-
Notifications
You must be signed in to change notification settings - Fork 907
ci: 添加PR部署工作流 #829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ci: 添加PR部署工作流 #829
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR似乎无法访问secrets捏,最好改用pull_request_target
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好像确实) 不过, 而且
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 问了 GitHub Docs 内置的Copilot,它是这么说的: |
||
| 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.deployment-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('<!-- Deploy Bot Comment -->')) { | ||
| commentId = comment.id; | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| ); | ||
|
|
||
| console.log('commentId: ', commentId); | ||
| const comment = ` | ||
| <!-- Deploy Bot Comment --> | ||
| ## ⚡ 已自动部署到 Cloudflare Pages | ||
|
|
||
| 预览地址: <${{ steps.deploy.outputs.deploy_url }}> | ||
|
lingbopro marked this conversation as resolved.
Outdated
|
||
| 提交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, | ||
| }); | ||
| } | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.