From 3c5d5773ae95d156991865ec828390c7b7511dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B6=9B?= Date: Thu, 22 May 2025 21:21:00 +0800 Subject: [PATCH 1/4] chore: fix pr preview actions --- .github/workflows/pr-preview.yml | 52 +++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 3bdf9cce..748f9bba 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -55,21 +55,43 @@ jobs: run: | surge ./merged_output ${{ env.ARCO_SITE_DOMAIN }} --token $SURGE_TOKEN - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: fc - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: 'github-actions[bot]' - body-includes: PR Preview Link - - - name: Comment PR with Preview Link - uses: peter-evans/create-or-update-comment@v2 + - name: Create PR Comment + uses: actions/github-script@v6 env: ARCO_SITE_DOMAIN: ${{ env.ARCO_SITE_DOMAIN }} with: - issue-number: ${{ github.event.pull_request.number }} - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body: | - ✨ **PR Preview Link**: [https://${{ env.ARCO_SITE_DOMAIN }}](https://${{ env.ARCO_SITE_DOMAIN }}) + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const previewUrl = `https://${process.env.ARCO_SITE_DOMAIN}`; + const commentBody = `✨ **PR Preview Link**: [${previewUrl}](${previewUrl})`; + + // 获取已有的评论 + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + // 查找是否有我们之前创建的评论 + const botComment = comments.find(comment => { + return comment.user.type === 'Bot' && + comment.body.includes('PR Preview Link'); + }); + + if (botComment) { + // 更新已有评论 + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: commentBody + }); + } else { + // 创建新评论 + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: commentBody + }); + } From 33b585c5ececee06ba987a65363de827f52db902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B6=9B?= Date: Thu, 22 May 2025 21:29:29 +0800 Subject: [PATCH 2/4] chore: add permissions for PR comments in workflow --- .github/workflows/pr-preview.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 748f9bba..0a703cdd 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -3,6 +3,10 @@ name: PR Preview on: pull_request: +permissions: + contents: read + pull-requests: write # 允许写入PR评论的权限 + jobs: build-and-deploy: runs-on: ubuntu-latest From 251c068205c5fe3d2bdcfc87d8b7569425e229b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B6=9B?= Date: Fri, 30 May 2025 18:01:23 +0800 Subject: [PATCH 3/4] chore: update PR preview workflow permissions and comments --- .github/workflows/pr-preview.yml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 0a703cdd..56881226 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -4,8 +4,9 @@ on: pull_request: permissions: - contents: read - pull-requests: write # 允许写入PR评论的权限 + contents: read # Read repository content for checkout 读取仓库内容用于检出代码 + pull-requests: write # Write PR comments and status 写入PR评论和状态 + issues: write # Create and update issue comments 创建和更新issue评论 jobs: build-and-deploy: @@ -37,16 +38,16 @@ jobs: - name: Merge output directories run: | - # 合并文件 + # Merge files 合并文件 cp -R output_resource/* output/page/ - # 创建目标目录 + # Create target directories 创建目标目录 mkdir -p merged_output/mobile/react/arco-design/pc mkdir -p merged_output/mobile/react/arco-design/mobile - # 移动目录内容 + # Move directory contents 移动目录内容 mv output/page/home/* merged_output/mobile/react/ mv output/page/pc/* merged_output/mobile/react/arco-design/pc/ mv output/page/mobile/* merged_output/mobile/react/arco-design/mobile/ - # 创建重定向 HTML 文件 + # Create redirect HTML file 创建重定向 HTML 文件 echo '' > merged_output/index.html - name: Install Surge @@ -69,21 +70,21 @@ jobs: const previewUrl = `https://${process.env.ARCO_SITE_DOMAIN}`; const commentBody = `✨ **PR Preview Link**: [${previewUrl}](${previewUrl})`; - // 获取已有的评论 + // Retrieve existing comments 获取已有的评论 const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number }); - // 查找是否有我们之前创建的评论 + // Find if there's a comment created by us before 查找是否有我们之前创建的评论 const botComment = comments.find(comment => { return comment.user.type === 'Bot' && comment.body.includes('PR Preview Link'); }); if (botComment) { - // 更新已有评论 + // Update existing comment 更新已有评论 await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, @@ -91,7 +92,7 @@ jobs: body: commentBody }); } else { - // 创建新评论 + // Create new comment 创建新评论 await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, From 56f425d25ec8edd7467df2095bd953a49be51d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B6=9B?= Date: Fri, 30 May 2025 19:07:08 +0800 Subject: [PATCH 4/4] chore: update step name for creating/updating PR comments in workflow --- .github/workflows/pr-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index 56881226..56500256 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -60,7 +60,7 @@ jobs: run: | surge ./merged_output ${{ env.ARCO_SITE_DOMAIN }} --token $SURGE_TOKEN - - name: Create PR Comment + - name: Create/Update PR Comment uses: actions/github-script@v6 env: ARCO_SITE_DOMAIN: ${{ env.ARCO_SITE_DOMAIN }}