|
| 1 | +name: Artifacts |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["CI"] |
| 5 | + types: |
| 6 | + - completed |
| 7 | + |
| 8 | +permissions: |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + notify: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: ${{ github.event.workflow_run.event == 'pull_request' }} |
| 15 | + steps: |
| 16 | + - uses: actions/github-script@v7 |
| 17 | + with: |
| 18 | + script: | |
| 19 | + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 20 | + owner: context.repo.owner, |
| 21 | + repo: context.repo.repo, |
| 22 | + run_id: context.payload.workflow_run.id |
| 23 | + }); |
| 24 | +
|
| 25 | + const artifactUrl = artifacts[0].archive_download_url; |
| 26 | + const commentBody = `<!-- build-artifact-comment -->\n📦 Docs artifacts are ready: ${artifactUrl}`; |
| 27 | +
|
| 28 | + const comments = await github.rest.issues.listComments({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + issue_number: context.issue.number, |
| 32 | + }); |
| 33 | +
|
| 34 | + const botComment = comments.data.find(comment => |
| 35 | + comment.user.type === 'Bot' && |
| 36 | + comment.body.includes('<!-- build-artifact-comment -->') |
| 37 | + ); |
| 38 | +
|
| 39 | + if (botComment) { |
| 40 | + await github.rest.issues.updateComment({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + comment_id: botComment.id, |
| 44 | + body: commentBody |
| 45 | + }); |
| 46 | + } else { |
| 47 | + await github.rest.issues.createComment({ |
| 48 | + owner: context.repo.owner, |
| 49 | + repo: context.repo.repo, |
| 50 | + issue_number: context.issue.number, |
| 51 | + body: commentBody |
| 52 | + }); |
| 53 | + } |
0 commit comments