Skip to content

Artifacts

Artifacts #18

Workflow file for this run

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' }}
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.artifacts_url}/${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
});
}