1
0
mirror of https://github.com/one-among-us/data.git synced 2025-02-23 06:38:45 +08:00
one-among-us-data/.github/workflows/preview.yml
2025-02-10 05:20:51 +08:00

76 lines
2.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: PR Preview
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
deployments: write
pull-requests: write
steps:
- 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
cache: 'yarn'
- name: Build
run: |
yarn install --production --frozen-lockfile
yarn build-preview
rm -rf dist/web.tgz
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
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:
script: |
const prNumber = context.payload.pull_request.number;
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)`;
// 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,
pull_number: prNumber,
});
const existingReview = reviews.find(review => review.body.includes('部署了预览'));
if (existingReview) {
// Update the existing review comment.
await github.rest.pulls.updateReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
review_id: existingReview.id,
body: reviewBody,
});
} else {
// Create a new review comment.
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: reviewBody,
event: "COMMENT",
});
}