Preview Home Page — Deploy #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Preview Home Page — Deploy | |
| on: | |
| workflow_run: | |
| workflows: ["Preview Home Page — Build"] | |
| types: [completed] | |
| # Only one deploy at a time; do not cancel in-progress deploys. | |
| concurrency: | |
| group: 'preview-deploy' | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| deployments: write | |
| pull-requests: write | |
| actions: read | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-24.04 | |
| # Only deploy when the build succeeded. | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: preview-build | |
| path: ./out | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Read PR number | |
| id: pr | |
| run: | | |
| number="$(cat ./out/pr-number.txt)" | |
| echo "number=$number" >> "$GITHUB_OUTPUT" | |
| echo "branch=pr-$number" >> "$GITHUB_OUTPUT" | |
| - name: Deploy to Cloudflare Pages | |
| id: deploy | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ vars.CLOUDFLARE_ACCOUNT_ID }} | |
| command: pages deploy ./out --project-name=fastgpt-home --branch=${{ steps.pr.outputs.branch }} | |
| quiet: false | |
| - name: Comment Preview URL on PR | |
| uses: actions/github-script@v7 | |
| if: success() && steps.pr.outputs.number != '' | |
| with: | |
| script: | | |
| const prNumber = parseInt('${{ steps.pr.outputs.number }}'); | |
| const deployUrl = '${{ steps.deploy.outputs.deployment-url }}'; | |
| const marker = '<!-- fastgpt-home-preview -->'; | |
| const body = `${marker} | |
| 🚀 **FastGPT Homepage Preview Ready!** | |
| 📱 **Preview URL:** ${deployUrl} | |
| 🔗 [👀 Click here to visit preview](${deployUrl}) | |
| --- | |
| 💡 This preview will be automatically updated when you push new commits to this PR.`; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| const existing = comments.find(c => c.body.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body, | |
| }); | |
| } |