部署 (预览环境) 后处理 #109
This file contains 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: 部署 (预览环境) 后处理 | |
on: | |
workflow_run: | |
workflows: | |
- 部署 (预览环境) | |
types: | |
- completed | |
env: | |
PR_NUM: 0 | |
jobs: | |
on-success: | |
name: 推送到 Netlify | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: 下载工作流信息 | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow_conclusion: success | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr-num | |
path: pr-num | |
allow_forks: true | |
- name: 获取 PR 编号 | |
id: pr-num | |
run: | | |
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV | |
- name: 下载构建内容 | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow_conclusion: success | |
run_id: ${{ github.event.workflow_run.id }} | |
name: build-result | |
allow_forks: true | |
- name: 解压构建文件 | |
run: | | |
tar -xvf dist.tar .vitepress/dist | |
# ls -R -a | |
- name: 推送到 Netlify | |
id: netlify | |
uses: nwtgck/actions-netlify@v3.0 | |
with: | |
publish-dir: ".vitepress/dist" | |
deploy-message: "Deploy from GitHub Actions" | |
production-deploy: false | |
alias: deploy-preview-wiki-${{ env.PR_NUM }} | |
enable-commit-comment: false | |
enable-pull-request-comment: false | |
enable-commit-status: false | |
enable-github-deployment: false | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
timeout-minutes: 1 | |
- name: 查找评论 ID | |
uses: peter-evans/find-comment@v3 | |
id: fc | |
with: | |
issue-number: ${{ env.PR_NUM }} | |
comment-author: "github-actions[bot]" | |
body-includes: <!-- auto message --> | |
- name: 创建或更新评论 | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ env.PR_NUM }} | |
body: | | |
## ✅ 成功部署预览! | |
| 类型 | 链接 | | |
|:-----------:|:----------------------------------------------------------------------------------------------------:| | |
| 预览地址 | ${{ steps.netlify.outputs.deploy-url }} | | |
| 最新提交 | ${{ github.sha }} | | |
| 部署日志 | [${{ github.event.workflow_run.name }} #${{ github.event.workflow_run.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) | | |
<!-- auto message --> | |
edit-mode: replace | |
on-failure: | |
name: 提示构建预览失败 | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
steps: | |
- name: 下载构建内容 (工作流信息) | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
workflow_conclusion: success | |
run_id: ${{ github.event.workflow_run.id }} | |
name: pr-num | |
path: pr-num | |
allow_forks: true | |
- name: 获取 PR 编号 | |
id: pr-num | |
run: | | |
echo "PR_NUM=$(cat pr-num/pr_num)" >> $GITHUB_ENV | |
- name: 查找评论 ID | |
uses: peter-evans/find-comment@v3 | |
id: fc | |
with: | |
issue-number: ${{ env.PR_NUM }} | |
comment-author: "github-actions[bot]" | |
body-includes: <!-- auto message --> | |
- name: 创建或更新评论:失败 | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ env.PR_NUM }} | |
body: | | |
## ❌ 部署预览失败 | |
| 类型 | 链接 | | |
|:-----------:|:----------------------------------------------------------------------------------------------------:| | |
| 预览地址 | 部署失败,请查看工作流运行日志。 | | |
| 最新提交 | ${{ github.sha }} | | |
| 部署日志 | [${{ github.event.workflow_run.name }} #${{ github.event.workflow_run.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) | | |
<!-- auto message --> | |
edit-mode: replace |