PR 评论发布 #23
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
| # 预览构建完成后:Surge 部署 + 预览/文档 diff 两条 PR 评论(二进制评论见 build-multi-platform.yml) | |
| name: PR 评论发布 | |
| on: | |
| workflow_run: | |
| workflows: ["PR 文档预览构建"] | |
| types: | |
| - completed | |
| env: | |
| PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} | |
| BUILD_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }} | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| deploy-preview: | |
| name: 部署预览并评论 | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: 下载 Surge 预览站产物 | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: tdesign-flutter-web | |
| path: tdesign-flutter-web | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 部署到 Surge | |
| id: deploy | |
| run: | | |
| DEPLOY_DOMAIN=https://preview-pr-${{ env.PR_NUMBER }}-${{ github.event.repository.name }}.surge.sh | |
| npx surge --project ./tdesign-flutter-web --domain $DEPLOY_DOMAIN --token ${{ secrets.TDESIGN_SURGE_TOKEN }} | |
| echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT | |
| - name: 组装 PR 预览评论 | |
| id: preview-comment | |
| env: | |
| PREVIEW_URL: ${{ steps.deploy.outputs.url }} | |
| run: | | |
| { | |
| echo 'body<<EOF' | |
| printf '%s\n' \ | |
| "<a href=\"${PREVIEW_URL}\"><img height=\"96\" alt=\"完成\" src=\"https://user-images.githubusercontent.com/15634204/150816437-9f5bb788-cd67-4cbc-9897-b82d74e9aa65.png\" /></a>" \ | |
| '' \ | |
| "**预览地址**: [${PREVIEW_URL}](${PREVIEW_URL})" \ | |
| '' \ | |
| '<!-- AUTO_PREVIEW_HOOK -->' | |
| echo 'EOF' | |
| } >> "$GITHUB_OUTPUT" | |
| - name: 更新 PR 预览评论 | |
| uses: TDesignOteam/workflows/actions/maintain-one-comment@main | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: ${{ steps.preview-comment.outputs.body }} | |
| number: ${{ env.PR_NUMBER }} | |
| body-include: "<!-- AUTO_PREVIEW_HOOK -->" | |
| - name: 部署失败时更新预览评论 | |
| if: failure() | |
| uses: TDesignOteam/workflows/actions/maintain-one-comment@main | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| [<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
| <!-- AUTO_PREVIEW_HOOK --> | |
| number: ${{ env.PR_NUMBER }} | |
| body-include: "<!-- AUTO_PREVIEW_HOOK -->" | |
| publish-doc-diff: | |
| name: 发布文档 diff 评论 | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: 下载文档 diff | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: doc-diff-comment | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 组装文档 diff 评论 | |
| id: doc-diff-comment | |
| run: | | |
| { | |
| echo 'body<<EOF' | |
| if [ -f doc-diff-comment.md ]; then | |
| cat doc-diff-comment.md | |
| else | |
| echo '_文档 diff 内容缺失。_' | |
| fi | |
| echo '' | |
| echo '<!-- AUTO_DOC_DIFF_HOOK -->' | |
| echo 'EOF' | |
| } >> "$GITHUB_OUTPUT" | |
| - name: 更新 PR 文档 diff 评论 | |
| uses: TDesignOteam/workflows/actions/maintain-one-comment@main | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: ${{ steps.doc-diff-comment.outputs.body }} | |
| number: ${{ env.PR_NUMBER }} | |
| body-include: "<!-- AUTO_DOC_DIFF_HOOK -->" | |
| notify-preview-failure: | |
| name: 预览构建失败 | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'failure' | |
| steps: | |
| - uses: TDesignOteam/workflows/actions/maintain-one-comment@main | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| [<img height="96" alt="失败" src="https://user-images.githubusercontent.com/5378891/75333447-1e63a280-58c1-11ea-975d-235367fd1522.png">](${{ env.BUILD_RUN_URL }}) | |
| <!-- AUTO_PREVIEW_HOOK --> | |
| number: ${{ env.PR_NUMBER }} | |
| body-include: "<!-- AUTO_PREVIEW_HOOK -->" | |
| notify-doc-diff-failure: | |
| name: 文档 diff 构建失败 | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'failure' | |
| steps: | |
| - uses: TDesignOteam/workflows/actions/maintain-one-comment@main | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| body: | | |
| _文档 diff 未生成:预览构建失败。_ | |
| <!-- AUTO_DOC_DIFF_HOOK --> | |
| number: ${{ env.PR_NUMBER }} | |
| body-include: "<!-- AUTO_DOC_DIFF_HOOK -->" |