|
| 1 | +name: Comment Preview URLs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Generate Preview URLs"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + |
| 9 | +jobs: |
| 10 | + comment: |
| 11 | + name: Post Preview URLs Comment |
| 12 | + runs-on: ubuntu-latest |
| 13 | + if: > |
| 14 | + github.event.workflow_run.event == 'pull_request' && |
| 15 | + github.event.workflow_run.conclusion == 'success' |
| 16 | + permissions: |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Download artifacts |
| 21 | + uses: actions/download-artifact@v4 |
| 22 | + with: |
| 23 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + run-id: ${{ github.event.workflow_run.id }} |
| 25 | + |
| 26 | + - name: Read PR metadata |
| 27 | + id: pr-metadata |
| 28 | + run: | |
| 29 | + PR_NUMBER=$(find . -name "pr_number.txt" -exec cat {} \;) |
| 30 | + PR_SHA=$(find . -name "pr_sha.txt" -exec cat {} \;) |
| 31 | + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 32 | + echo "pr_sha=$PR_SHA" >> $GITHUB_OUTPUT |
| 33 | +
|
| 34 | + - name: Read preview URLs |
| 35 | + id: preview-urls |
| 36 | + run: | |
| 37 | + PREVIEW_CONTENT=$(find . -name "preview_urls.txt" -exec cat {} \;) |
| 38 | + { |
| 39 | + echo 'content<<EOF' |
| 40 | + echo "$PREVIEW_CONTENT" |
| 41 | + echo EOF |
| 42 | + } >> $GITHUB_OUTPUT |
| 43 | +
|
| 44 | + - name: Find existing comment |
| 45 | + uses: peter-evans/find-comment@v4 |
| 46 | + id: fc |
| 47 | + with: |
| 48 | + issue-number: ${{ steps.pr-metadata.outputs.pr_number }} |
| 49 | + comment-author: 'github-actions[bot]' |
| 50 | + body-includes: '本次 PR 文档预览链接' |
| 51 | + |
| 52 | + - name: Create or update comment |
| 53 | + uses: peter-evans/create-or-update-comment@v4 |
| 54 | + with: |
| 55 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 56 | + issue-number: ${{ steps.pr-metadata.outputs.pr_number }} |
| 57 | + body: ${{ steps.preview-urls.outputs.content }} |
| 58 | + edit-mode: replace |
0 commit comments