Artifacts #22
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
| name: Artifacts | |
| on: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: | |
| - completed | |
| branches-ignore: | |
| - main | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| notify: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests.length > 0 }} | |
| steps: | |
| - uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id | |
| }); | |
| if (artifacts.data.total_count !== 1) { | |
| throw new Error('Expected one artifact') | |
| } | |
| const pullNumber = context.payload.workflow_run.pull_requests[0].number; | |
| const artifactId = artifacts.data.artifacts[0].id; | |
| const artifactUrl = `${context.payload.workflow_run.html_url}/artifacts/${artifactId}`; | |
| const commentBody = `<!-- build-artifact-comment -->\n📦 Docs artifacts are ready: ${artifactUrl}`; | |
| const comments = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pullNumber | |
| }); | |
| const botComment = comments.data.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('<!-- build-artifact-comment -->') | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: commentBody | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pullNumber, | |
| body: commentBody | |
| }); | |
| } |