From e15618681421831a32b609342cdd68568f9abd47 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Mon, 10 Feb 2025 05:20:51 +0800 Subject: [PATCH] [F] Fix preview action? --- .github/workflows/preview.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 2cb9e32f..19354fa0 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,11 +1,9 @@ name: PR Preview on: - pull_request: - # Trigger the workflow on these PR events: + pull_request_target: types: [opened, synchronize, reopened] - # Limit to specific branches: - branches: [ main, develop ] + branches: [main] jobs: build: @@ -17,7 +15,11 @@ jobs: pull-requests: write steps: - - uses: actions/checkout@v4 + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + - uses: actions/setup-node@v4 with: node-version: 20 @@ -36,7 +38,7 @@ jobs: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} gitHubToken: ${{ secrets.GITHUB_TOKEN }} command: pages deploy dist --project-name=data-preview --branch=pr-${{ github.event.pull_request.number }} - + - name: Pull request comment uses: actions/github-script@v6 with: @@ -45,7 +47,7 @@ jobs: const now = new Date().toISOString().substring(0, 19).replace('T', ' '); const reviewBody = `🐱 感谢贡献!\n\n部署了预览,在这里哦: https://pr-${prNumber}.data-preview.pages.dev\n\n🕒 最后更新: ${now} (UTC)`; - // 获取现有 review + // Look for an existing review comment containing the preview message. const { data: reviews } = await github.rest.pulls.listReviews({ owner: context.repo.owner, repo: context.repo.repo, @@ -53,7 +55,7 @@ jobs: }); const existingReview = reviews.find(review => review.body.includes('部署了预览')); if (existingReview) { - // 如果已经有 review,更新它 + // Update the existing review comment. await github.rest.pulls.updateReview({ owner: context.repo.owner, repo: context.repo.repo, @@ -62,7 +64,7 @@ jobs: body: reviewBody, }); } else { - // 如果没有 review,创建新的 review + // Create a new review comment. await github.rest.pulls.createReview({ owner: context.repo.owner, repo: context.repo.repo,