{"id":10020777,"date":"2025-04-27T00:45:57","date_gmt":"2025-04-26T16:45:57","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020777"},"modified":"2025-04-27T00:45:57","modified_gmt":"2025-04-26T16:45:57","slug":"%e5%9f%ba%e4%ba%8e-github-actions-%e7%9a%84%e6%b5%81%e7%a8%8b%e8%87%aa%e5%8a%a8%e5%8c%96%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020777","title":{"rendered":"\u57fa\u4e8e GitHub Actions \u7684\u6d41\u7a0b\u81ea\u52a8\u5316\u5b9e\u8df5"},"content":{"rendered":"<h2>\u6458\u8981<\/h2>\n<p>\u5f00\u6e90\u9879\u76ee\u534f\u4f5c\u6d41\u7a0b\u4e2d\u7684\u91cd\u590d\u6027\u4efb\u52a1\uff08\u5982 Issue \u7ba1\u7406\u3001Pull Request \u68c0\u67e5\u3001\u4ee3\u7801\u5408\u5e76\uff09\u5e38\u5e38\u8017\u8d39\u5927\u91cf\u65f6\u95f4\uff0c\u5bfc\u81f4\u6548\u7387\u4f4e\u4e0b\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u5982\u4f55\u8bbe\u8ba1\u57fa\u4e8e GitHub Actions \u548c Bot \u7cfb\u7edf\u7684\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u4ee5\u4f18\u5316\u5f00\u6e90\u9879\u76ee\u7684\u534f\u4f5c\u6d41\u7a0b\u3002\u901a\u8fc7\u8be6\u7ec6\u7684\u4ee3\u7801\u793a\u4f8b\u548c\u914d\u56fe\uff0c\u5c55\u793a\u5982\u4f55\u5b9e\u73b0 Issue \u81ea\u52a8\u6807\u8bb0\u3001Pull Request \u6a21\u677f\u81ea\u52a8\u68c0\u67e5\u3001\u5408\u5e76\u51b2\u7a81\u63d0\u9192\u7b49\u529f\u80fd\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u4e13\u6ce8\u4e8e\u6838\u5fc3\u5f00\u53d1\u4efb\u52a1\u3002<\/p>\n<h2>\u5f15\u8a00<\/h2>\n<p>\u5f00\u6e90\u9879\u76ee\u7684\u9ad8\u6548\u534f\u4f5c\u79bb\u4e0d\u5f00\u826f\u597d\u7684\u6d41\u7a0b\u7ba1\u7406\u3002\u7136\u800c\uff0c\u624b\u52a8\u5904\u7406\u91cd\u590d\u6027\u4efb\u52a1\u4e0d\u4ec5\u5bb9\u6613\u51fa\u9519\uff0c\u8fd8\u53ef\u80fd\u5f71\u54cd\u5f00\u53d1\u8282\u594f\u3002\u5728\u73b0\u4ee3\u5f00\u6e90\u73af\u5883\u4e2d\uff0c\u81ea\u52a8\u5316\u5de5\u5177\u6210\u4e3a\u534f\u4f5c\u4f18\u5316\u7684\u5173\u952e\u3002\u672c\u7bc7\u6587\u7ae0\u4ee5 GitHub Actions \u548c\u5b9a\u5236 Bot \u7cfb\u7edf\u4e3a\u4f8b\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u81ea\u52a8\u5316\u8bbe\u8ba1\u63d0\u9ad8\u56e2\u961f\u534f\u4f5c\u6548\u7387\u3002<\/p>\n<h2>\u81ea\u52a8\u5316\u534f\u4f5c\u6d41\u7a0b\u7684\u6838\u5fc3\u529f\u80fd<\/h2>\n<h3>\u534f\u4f5c\u6d41\u7a0b\u4e2d\u7684\u5e38\u89c1\u95ee\u9898<\/h3>\n<ol>\n<li><strong>\u624b\u52a8\u7ba1\u7406 Issue \u548c Pull Request<\/strong>\uff1a\u5f53\u9879\u76ee\u89c4\u6a21\u6269\u5927\uff0c\u624b\u52a8\u8ddf\u8e2a\u4efb\u52a1\u4f18\u5148\u7ea7\u548c\u72b6\u6001\u53d8\u5f97\u4e0d\u73b0\u5b9e\u3002<\/li>\n<li><strong>\u5408\u5e76\u51b2\u7a81\u9891\u53d1<\/strong>\uff1a\u5f00\u53d1\u8005\u5e38\u56e0\u5408\u5e76\u51b2\u7a81\u672a\u53ca\u65f6\u53d1\u73b0\u800c\u6d6a\u8d39\u65f6\u95f4\u3002<\/li>\n<li><strong>\u4ee3\u7801\u8d28\u91cf\u68c0\u67e5\u4e0d\u8db3<\/strong>\uff1a\u624b\u52a8\u8fd0\u884c\u9759\u6001\u4ee3\u7801\u68c0\u67e5\u5de5\u5177\u5bb9\u6613\u9057\u6f0f\u95ee\u9898\u3002<\/li>\n<li><strong>\u7f3a\u4e4f\u900f\u660e\u6027<\/strong>\uff1a\u534f\u4f5c\u8fdb\u5c55\u7684\u66f4\u65b0\u4e0e\u901a\u77e5\u4e0d\u8db3\uff0c\u5f71\u54cd\u56e2\u961f\u6210\u5458\u95f4\u7684\u540c\u6b65\u3002<\/li>\n<\/ol>\n<h3>GitHub Actions \u548c Bot \u7684\u81ea\u52a8\u5316\u80fd\u529b<\/h3>\n<ol>\n<li><strong>\u4efb\u52a1\u81ea\u52a8\u5316<\/strong>\uff1a\u5b9e\u73b0\u4ece Issue \u6807\u8bb0\u5230 Pull Request \u5408\u5e76\u7684\u4e00\u7ad9\u5f0f\u81ea\u52a8\u5316\u3002<\/li>\n<li><strong>\u5b9e\u65f6\u901a\u77e5<\/strong>\uff1a\u5728\u56e2\u961f\u534f\u4f5c\u5e73\u53f0\uff08\u5982 Slack\u3001Teams\uff09\u63a8\u9001\u5b9e\u65f6\u66f4\u65b0\u3002<\/li>\n<li><strong>\u589e\u5f3a\u534f\u4f5c\u900f\u660e\u6027<\/strong>\uff1a\u901a\u8fc7\u62a5\u544a\u751f\u6210\u5de5\u5177\u8ba9\u534f\u4f5c\u72b6\u6001\u53ef\u89c6\u5316\u3002<\/li>\n<\/ol>\n<h2>\u57fa\u4e8e GitHub Actions \u7684\u534f\u4f5c\u6d41\u7a0b\u81ea\u52a8\u5316<\/h2>\n<h3>\u81ea\u52a8\u6807\u8bb0 Issue<\/h3>\n<p><strong>\u529f\u80fd\u63cf\u8ff0<\/strong>\uff1a\u901a\u8fc7\u5173\u952e\u8bcd\u8bc6\u522b\u81ea\u52a8\u7ed9 Issue \u6dfb\u52a0\u6807\u7b7e\u3002<\/p>\n<pre><code class=\".sh\">name: Auto-Label Issues\non:\n  issues:\n    types: [opened]\njobs:\n  add-label:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout repository\n        uses: actions\/checkout@v3\n      - name: Auto-label Issue\n        uses: actions-ecosystem\/action-add-labels@v1\n        with:\n          github_token: ${{ secrets.GITHUB_TOKEN }}\n          labels: |\n            bug\n            enhancement\n<\/code><\/pre>\n<h3>Pull Request \u68c0\u67e5\u548c\u6a21\u677f\u9a8c\u8bc1<\/h3>\n<p><strong>\u529f\u80fd\u63cf\u8ff0<\/strong>\uff1a\u68c0\u67e5 PR \u662f\u5426\u7b26\u5408\u6a21\u677f\u8981\u6c42\u3002<\/p>\n<pre><code class=\".sh\">name: Pull Request Validator\non:\n  pull_request:\n    types: [opened, edited]\njobs:\n  validate-pr:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Check PR Title\n        run: |\n          if [[ ! &quot;${{ github.event.pull_request.title }}&quot; =~ ^(fix|feat|docs|refactor): ]]; then\n            echo &quot;PR title does not match the required format.&quot;\n            exit 1\n          fi\n      - name: Check PR Description\n        run: |\n          if [[ -z &quot;${{ github.event.pull_request.body }}&quot; ]]; then\n            echo &quot;PR description is missing.&quot;\n            exit 1\n          fi\n<\/code><\/pre>\n<h3>\u5408\u5e76\u51b2\u7a81\u63d0\u9192<\/h3>\n<p><strong>\u529f\u80fd\u63cf\u8ff0<\/strong>\uff1a\u68c0\u67e5\u5f53\u524d PR \u662f\u5426\u6709\u672a\u89e3\u51b3\u7684\u5408\u5e76\u51b2\u7a81\u3002<\/p>\n<pre><code class=\".sh\">name: Conflict Checker\non:\n  pull_request:\n    types: [synchronize]\njobs:\n  check-conflicts:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Fetch Repository\n        uses: actions\/checkout@v3\n      - name: Check for Conflicts\n        run: |\n          if git diff --check | grep -q '^'; then\n            echo &quot;Merge conflicts detected.&quot;\n            exit 1\n          fi\n<\/code><\/pre>\n<h2>\u793a\u4f8b\u4ee3\u7801\u8be6\u89e3<\/h2>\n<ol>\n<li>\n<p><strong>Issue \u81ea\u52a8\u6807\u8bb0<\/strong><\/p>\n<ul>\n<li>\u5229\u7528\u00a0<code>issues.opened<\/code>\u00a0\u4e8b\u4ef6\u89e6\u53d1\u3002<\/li>\n<li>\u4f7f\u7528\u00a0<code>actions-ecosystem\/action-add-labels<\/code>\u00a0\u81ea\u52a8\u6807\u8bb0\u5173\u952e\u8bcd\u5bf9\u5e94\u7684\u6807\u7b7e\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>PR \u6a21\u677f\u9a8c\u8bc1<\/strong><\/p>\n<ul>\n<li>\u6821\u9a8c PR \u6807\u9898\u662f\u5426\u7b26\u5408\u683c\u5f0f\uff0c\u5e2e\u52a9\u56e2\u961f\u7ef4\u62a4\u89c4\u8303\u3002<\/li>\n<li>\u68c0\u67e5 PR \u63cf\u8ff0\u662f\u5426\u4e3a\u7a7a\uff0c\u786e\u4fdd\u5f00\u53d1\u8005\u63d0\u4f9b\u8db3\u591f\u7684\u80cc\u666f\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5408\u5e76\u51b2\u7a81\u68c0\u67e5<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u00a0<code>git diff --check<\/code>\u00a0\u68c0\u6d4b\u4ee3\u7801\u51b2\u7a81\u3002<\/li>\n<li>\u63d0\u524d\u63d0\u9192\u51b2\u7a81\u95ee\u9898\uff0c\u907f\u514d\u540e\u7eed\u5408\u5e76\u5931\u8d25\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2>QA \u73af\u8282<\/h2>\n<h3>Q1: \u662f\u5426\u53ef\u4ee5\u7ed3\u5408\u5916\u90e8\u5e73\u53f0\uff08\u5982 Slack\uff09\u63a8\u9001\u901a\u77e5\uff1f<\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7\u00a0<code>slackapi\/slack-github-action<\/code>\u00a0\u6216\u81ea\u5b9a\u4e49 Webhook\uff0c\u5c06\u4efb\u52a1\u8fdb\u5c55\u5b9e\u65f6\u63a8\u9001\u81f3\u534f\u4f5c\u5e73\u53f0\u3002<\/p>\n<h3>Q2: \u662f\u5426\u652f\u6301\u5b9a\u5236\u5316\u7684\u590d\u6742\u89c4\u5219\uff1f<\/h3>\n<p>GitHub Actions \u652f\u6301\u81ea\u5b9a\u4e49\u811a\u672c\u903b\u8f91\uff0c\u7ed3\u5408 Bot \u7cfb\u7edf\uff0c\u590d\u6742\u89c4\u5219\u7ba1\u7406\u4e5f\u80fd\u81ea\u52a8\u5316\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u57fa\u4e8e GitHub Actions \u7684\u81ea\u52a8\u5316\u534f\u4f5c\u6d41\u7a0b\u8bbe\u8ba1\uff0c\u9488\u5bf9 Issue \u7ba1\u7406\u3001Pull Request \u68c0\u67e5\u548c\u5408\u5e76\u51b2\u7a81\u63d0\u9192\u8fdb\u884c\u4e86\u793a\u4f8b\u5b9e\u73b0\u3002\u81ea\u52a8\u5316\u5de5\u5177\u53ef\u4ee5\u6709\u6548\u63d0\u5347\u5f00\u6e90\u9879\u76ee\u7684\u7ba1\u7406\u6548\u7387\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u4e13\u6ce8\u4e8e\u9ad8\u4ef7\u503c\u5de5\u4f5c\u3002<\/p>\n<p>\u672a\u6765\u53ef\u8fdb\u4e00\u6b65\u7ed3\u5408 AI \u6280\u672f\uff08\u5982 ChatGPT\uff09\u8bbe\u8ba1\u66f4\u667a\u80fd\u7684\u534f\u4f5c Bot\uff0c\u4f8b\u5982\u4ee3\u7801\u5ba1\u67e5\u52a9\u624b\u6216\u77e5\u8bc6\u5e93\u751f\u6210\u5de5\u5177\uff0c\u8fdb\u4e00\u6b65\u63d0\u5347\u5f00\u6e90\u9879\u76ee\u7684\u7ba1\u7406\u6c34\u5e73\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<ol>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=1BxBJtqC4uCHU16FiQ33WQ%3D%3D.dGv9P3rJOyBNGJWX1%2F2MMyHxNUJWHA%2FRDulXkYoDqbxPQRZfTDwECFs5RSjJnb%2FJ\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">GitHub Actions \u5b98\u65b9\u6587\u6863<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=u86OMISnrnx%2FBnL1MmIDrw%3D%3D.AihM1tsfVNS7ARMGznpW1smD8Q5qUvIGTNBgA%2Bg04ZkVvO6eUC4fHw59mhjJQCj3\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">GitHub Bot \u5f00\u53d1\u6307\u5357<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=TNKtjVDmg%2BXkFa1lM%2FrJGg%3D%3D.EMrigyP9s6g%2BU2ghtyoSUb7vBSElM6bG73FLtIM95svk74f4TLJ6fBAbufu6Kkey\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Slack GitHub Actions \u96c6\u6210<\/a><\/li>\n<\/ol>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046484178\">https:\/\/segmentfault.com\/a\/1190000046484178<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981 \u5f00\u6e90\u9879\u76ee\u534f\u4f5c\u6d41\u7a0b\u4e2d\u7684\u91cd\u590d\u6027\u4efb\u52a1\uff08\u5982 Issue \u7ba1\u7406\u3001Pull Request \u68c0\u67e5\u3001\u4ee3\u7801\u5408\u5e76\uff09\u5e38\u5e38\u8017\u8d39 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020777","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020777"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020777\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}