name: Post Build Artifacts Comment on: workflow_run: workflows: ["Build Test Package on PR"] types: [completed] permissions: contents: read actions: read issues: write pull-requests: write concurrency: group: build-artifacts-comment-${{ github.repository }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }} cancel-in-progress: true jobs: comment: if: github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: - name: Create or update PR comment uses: actions/github-script@v7 with: script: | const { owner, repo } = context.repo; const runId = context.payload.workflow_run.id; const headSha = context.payload.workflow_run.head_sha; const headBranch = context.payload.workflow_run.head_branch; const headRepoOwner = context.payload.workflow_run.head_repository?.owner?.login; // Resolve PR number (payload -> fallback by head owner:branch). const prs = context.payload.workflow_run.pull_requests || []; let prNumber = prs[0]?.number; if (!prNumber) { const head = `${headRepoOwner || owner}:${headBranch}`; const byHead = await github.rest.pulls.list({ owner, repo, state: 'open', head, per_page: 1, }); prNumber = byHead.data?.[0]?.number; } if (!prNumber) { core.setFailed(`Could not resolve a pull request for workflow_run ${runId} (head_sha=${headSha}, head_branch=${headBranch}).`); return; } // Find artifact id. const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, { owner, repo, run_id: runId, per_page: 100, }); const artifact = artifacts.find(a => a.name === 'patchright-packages' && !a.expired); if (!artifact) { core.setFailed(`Artifact 'patchright-packages' not found (or expired) for run ${runId}`); return; } const marker = ''; const body = [ marker, '**Patchright Package Build**', '__Do not download or use these artifacts in production! They are only for testing purposes on this Pull Request.__', '', '**Download**', `- Download the PR's npm package builds via \`patchright-packages\`:\n [Download Package Build Artifacts](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/artifacts/${artifact.id})`, '', '**Debug info**', `- Artifact ID: \`${artifact.id}\``, `- Head SHA: \`${headSha}\``, '', ].join('\n'); // Find existing bot comment with marker. const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number: Number(prNumber), per_page: 100, }); const existing = comments.find(c => c.user?.login === 'github-actions[bot]' && typeof c.body === 'string' && c.body.includes(marker) ); if (existing) { await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body, }); } else { await github.rest.issues.createComment({ owner, repo, issue_number: Number(prNumber), body, }); }