{"id":70,"date":"2026-08-05T09:00:00","date_gmt":"2026-08-05T01:00:00","guid":{"rendered":"https:\/\/fsdata.site\/?p=70"},"modified":"2026-07-24T00:36:52","modified_gmt":"2026-07-23T16:36:52","slug":"github-actions-%e8%87%aa%e5%8a%a8%e5%8c%96-ci-cd-%e5%85%a8%e6%b5%81%e7%a8%8b%e6%8c%87%e5%8d%97%ef%bc%88%e5%90%ab%e9%83%a8%e7%bd%b2%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fsdata.site\/?p=70","title":{"rendered":"GitHub Actions \u81ea\u52a8\u5316 CI\/CD \u5168\u6d41\u7a0b\u6307\u5357\uff08\u542b\u90e8\u7f72\uff09"},"content":{"rendered":"<h2>\u4e00\u3001CI\/CD \u8ba9\u53d1\u5e03\u4e0d\u518d\u75db\u82e6<\/h2>\n<p>\u6bcf\u6b21\u624b\u52a8\u6253\u5305\u3001\u4e0a\u4f20\u3001\u91cd\u542f\uff0c\u65e2\u6162\u53c8\u5bb9\u6613\u51fa\u9519\u3002\u7528 GitHub Actions \u628a\u8fd9\u5957\u6d41\u7a0b\u81ea\u52a8\u5316\uff0cpush \u4ee3\u7801\u5373\u89e6\u53d1\u6784\u5efa\u90e8\u7f72\uff0c\u672c\u6587\u7ed9\u4e00\u5957\u53ef\u76f4\u63a5\u6284\u7684\u6a21\u677f\u3002<\/p>\n<h2>\u4e8c\u3001\u6838\u5fc3\u6982\u5ff5<\/h2>\n<ul>\n<li><strong>Workflow<\/strong>\uff1a\u4e00\u4e2a\u81ea\u52a8\u5316\u6d41\u7a0b\uff0c\u5b58\u653e\u5728 <code>.github\/workflows\/<\/code>\u3002<\/li>\n<li><strong>Job<\/strong>\uff1a\u4e00\u7ec4\u6b65\u9aa4\uff0c\u53ef\u5e76\u884c\u6216\u4f9d\u8d56\u3002<\/li>\n<li><strong>Step<\/strong>\uff1a\u5177\u4f53\u6267\u884c\u547d\u4ee4\u3002<\/li>\n<li><strong>Runner<\/strong>\uff1a\u6267\u884c\u73af\u5883\uff08GitHub \u6258\u7ba1\u6216\u81ea\u6258\u7ba1\uff09\u3002<\/li>\n<\/ul>\n<h2>\u4e09\u3001\u4e00\u4e2a Java \u9879\u76ee CI \u6a21\u677f<\/h2>\n<pre><code>name: CI\non: [push]\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\/checkout@v4\n      - uses: actions\/setup-java@v4\n        with: { java-version: '17', distribution: 'temurin' }\n      - run: mvn -B package\n      - uses: actions\/upload-artifact@v4\n        with: { name: app, path: target\/*.jar }\n<\/code><\/pre>\n<h2>\u56db\u3001\u52a0\u4e2a CD\uff1a\u81ea\u52a8\u90e8\u7f72\u5230\u670d\u52a1\u5668<\/h2>\n<pre><code>  deploy:\n    needs: build\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\/download-artifact@v4\n        with: { name: app }\n      - name: scp to server\n        uses: appleboy\/scp-action@v1\n        with:\n          host: ${{ secrets.HOST }}\n          username: ${{ secrets.USER }}\n          key: ${{ secrets.KEY }}\n          source: \"*.jar\"\n          target: \"\/opt\/app\/\"\n      - name: restart\n        uses: appleboy\/ssh-action@v1\n        with:\n          host: ${{ secrets.HOST }}\n          username: ${{ secrets.USER }}\n          key: ${{ secrets.KEY }}\n          script: systemctl restart myapp\n<\/code><\/pre>\n<h2>\u4e94\u3001\u5e38\u7528\u6280\u5de7<\/h2>\n<ul>\n<li><strong>\u7f13\u5b58\u4f9d\u8d56<\/strong>\uff1a<code>actions\/cache<\/code> \u7f13\u5b58 Maven\/<code>~\/.m2<\/code>\uff0c\u6784\u5efa\u63d0\u901f\u660e\u663e\u3002<\/li>\n<li><strong>\u77e9\u9635\u6784\u5efa<\/strong>\uff1a<code>matrix: { java: [17, 21] }<\/code> \u591a\u7248\u672c\u9a8c\u8bc1\u3002<\/li>\n<li><strong>\u6761\u4ef6\u89e6\u53d1<\/strong>\uff1a<code>on: { push: { branches: [main] } }<\/code> \u53ea\u8dd1\u4e3b\u5206\u652f\u3002<\/li>\n<\/ul>\n<h2>\u516d\u3001\u8e29\u5751\u63d0\u793a<\/h2>\n<ul>\n<li>\u5bc6\u94a5\u653e <strong>Settings \u2192 Secrets<\/strong>\uff0c\u522b\u786c\u7f16\u7801\u3002<\/li>\n<li>\u81ea\u6258\u7ba1 Runner \u6ce8\u610f\u5b89\u5168\uff0c\u522b\u8ba9\u516c\u5f00\u4ed3\u5e93\u8dd1\u7279\u6743\u811a\u672c\u3002<\/li>\n<li>\u8d85\u65f6\u9ed8\u8ba4 6 \u5c0f\u65f6\uff0c\u957f\u6784\u5efa\u8bbe <code>timeout-minutes<\/code>\u3002<\/li>\n<\/ul>\n<h2>\u7ed3\u8bed<\/h2>\n<p>CI\/CD \u7684\u4ef7\u503c\u4e0d\u5728\u9177\uff0c\u5728\u4e8e&#8221;\u7a33\u5b9a\u53ef\u91cd\u590d&#8221;\u3002\u5148\u628a\u6784\u5efa\u81ea\u52a8\u5316\uff0c\u518d\u9010\u6b65\u52a0\u90e8\u7f72\uff0c\u5faa\u5e8f\u6e10\u8fdb\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528 GitHub Actions \u5b9e\u73b0 push \u5373\u6784\u5efa\u90e8\u7f72\uff1aCI \u6a21\u677f\u3001scp \u90e8\u7f72\u3001\u7f13\u5b58\u4f9d\u8d56\u3001\u5bc6\u94a5\u7ba1\u7406\u4e0e\u8e29\u5751\u63d0\u793a\u3002<\/p>\n","protected":false},"author":2,"featured_media":164,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70"}],"version-history":[{"count":1,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions\/169"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/media\/164"}],"wp:attachment":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}