From f9058106a81ffbb3ceb27ace87d2df7a6945801a Mon Sep 17 00:00:00 2001 From: lingbopro Date: Sun, 24 May 2026 19:27:07 +0800 Subject: [PATCH 1/5] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0PR=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 参见 #793 --- .github/workflows/pr-deploy.yaml | 78 ++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/pr-deploy.yaml diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml new file mode 100644 index 00000000..67420e17 --- /dev/null +++ b/.github/workflows/pr-deploy.yaml @@ -0,0 +1,78 @@ +name: Pull Request Deploy + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v6 + - name: Deploy + id: deploy + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: | + pages deploy --project-name=win12-online --branch=pr-preview/${{ github.event.pull_request.number }} --commit-hash=${{ github.event.pull_request.head.sha }} + - name: Post comment + if: ${{ steps.deploy.outputs.deploy_url != '' }} + uses: actions/github-script@v9 + with: + script: | + // Check if there is already a comment + let commentId = null; + await github.paginate( + 'GET /repos/{owner}/{repo}/issues/{issue_number}/comments', + { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ github.event.pull_request.number }}, + }, + (response) => { + for (const comment of response) { + if ( + comment.user.login === 'github-actions[bot]' && + comment.body.includes('')) { + commentId = comment.id; + return true; + } + } + return false; + } + ); + + console.log('commentId: ', commentId); + const comment = ` + + ## ⚡ 已自动部署到 Cloudflare Pages + + 预览地址: <${{ steps.deploy.outputs.deploy_url }}> + 提交hash: ${{ github.event.pull_request.head.sha }} + + PR 更新时会自动进行部署并更新此评论 + + ###### 本评论由 GitHub Actions 工作流自动生成~ + `; + console.log('comment: ', comment); + + if (!commentId) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ github.event.pull_request.number }}, + body: comment, + }); + } + else { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: commentId, + body: comment, + }); + } + From 9c92d656d4e195dc7bbc28180ff4cb95a6b61675 Mon Sep 17 00:00:00 2001 From: lingbopro Date: Sun, 24 May 2026 20:20:49 +0800 Subject: [PATCH 2/5] fix workflow --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 67420e17..27204307 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -17,7 +17,7 @@ jobs: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} command: | - pages deploy --project-name=win12-online --branch=pr-preview/${{ github.event.pull_request.number }} --commit-hash=${{ github.event.pull_request.head.sha }} + pages deploy . --project-name=win12-online --branch=pr-preview/${{ github.event.pull_request.number }} --commit-hash=${{ github.event.pull_request.head.sha }} - name: Post comment if: ${{ steps.deploy.outputs.deploy_url != '' }} uses: actions/github-script@v9 From fc81db8143d0736dd037fe5e8055ea9be01658d4 Mon Sep 17 00:00:00 2001 From: lingbopro Date: Sun, 7 Jun 2026 19:29:06 +0800 Subject: [PATCH 3/5] ci: update pr workflow to fix field name Co-authored-by: Paper Moon <47830915@qq.com> --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 27204307..744f1a61 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -19,7 +19,7 @@ jobs: command: | pages deploy . --project-name=win12-online --branch=pr-preview/${{ github.event.pull_request.number }} --commit-hash=${{ github.event.pull_request.head.sha }} - name: Post comment - if: ${{ steps.deploy.outputs.deploy_url != '' }} + if: ${{ steps.deploy.outputs.deployment-url != '' }} uses: actions/github-script@v9 with: script: | From 0d77f0780ace77f44e2858e77164f7d003ccf580 Mon Sep 17 00:00:00 2001 From: lingbopro Date: Sun, 7 Jun 2026 19:44:35 +0800 Subject: [PATCH 4/5] Update .github/workflows/pr-deploy.yaml Co-authored-by: Paper Moon <47830915@qq.com> --- .github/workflows/pr-deploy.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 744f1a61..c862ca85 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -3,7 +3,9 @@ name: Pull Request Deploy on: pull_request: types: [opened, synchronize, reopened] - +permissions: + contents: read + pull-requests: write jobs: deploy: runs-on: ubuntu-latest From a2f3e04e02d792d572592da78b15cf045591af25 Mon Sep 17 00:00:00 2001 From: lingbopro Date: Sun, 7 Jun 2026 19:49:11 +0800 Subject: [PATCH 5/5] Update pr-deploy.yaml --- .github/workflows/pr-deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index c862ca85..23acf71a 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -52,7 +52,7 @@ jobs: ## ⚡ 已自动部署到 Cloudflare Pages - 预览地址: <${{ steps.deploy.outputs.deploy_url }}> + 预览地址: <${{ steps.deploy.outputs.deployment-url }}> 提交hash: ${{ github.event.pull_request.head.sha }} PR 更新时会自动进行部署并更新此评论