1+ name : Mergin Maps delivery
2+ on :
3+ workflow_run :
4+ types :
5+ - " completed"
6+ workflows :
7+ - " macOS Build"
8+ - " linux Build"
9+ - " win64 Build"
10+ - " Android Build"
11+ - " iOS Build"
12+
13+ permissions :
14+ actions : read
15+ pull-requests : write
16+
17+ jobs :
18+ comment_on_pr :
19+ if : github.event.workflow_run.conclusion == 'success'
20+ runs-on : ubuntu-latest
21+ steps :
22+ - name : Find Artifacts and Format Comment
23+ id : artifact_finder
24+ uses : actions/github-script@v7
25+ with :
26+ # This script finds the artifacts from the required dependency workflows
27+ # that ran on the same commit (head_sha) as this PR.
28+ script : |
29+ const buildWorkflowNames = ['macOS Build', 'linux Build', 'win64 Build', 'Android Build', 'iOS Build'];
30+ const headSha = context.payload.pull_request.head.sha;
31+ let commentBody = '## 📦 Build Artifacts Ready\n\n';
32+ let artifactsFound = false;
33+
34+ for (const workflowName of buildWorkflowNames) {
35+ // 1. Find the latest successful run for the specific workflow and commit SHA
36+ const runsResponse = await github.rest.actions.listWorkflowRunsForRepo({
37+ owner: context.repo.owner,
38+ repo: context.repo.repo,
39+ head_sha: headSha,
40+ status: 'success',
41+ per_page: 10
42+ });
43+
44+ // Filter to find the run matching the exact workflow name
45+ const latestRun = runsResponse.data.workflow_runs.find(run =>
46+ run.name === workflowName && run.conclusion === 'success'
47+ );
48+
49+ if (!latestRun) {
50+ console.log(`Could not find a successful run for workflow: ${workflowName}`);
51+ commentBody += `- :x: **${workflowName}**: Build not yet complete or failed.\n`;
52+ continue;
53+ }
54+
55+ // 2. List artifacts for that specific run
56+ const artifactsResponse = await github.rest.actions.listWorkflowRunArtifacts({
57+ owner: context.repo.owner,
58+ repo: context.repo.repo,
59+ run_id: latestRun.id,
60+ });
61+
62+ const artifacts = artifactsResponse.data.artifacts;
63+
64+ if (artifacts.length > 0) {
65+ commentBody += `### ${workflowName} (Run #${latestRun.id})\n`;
66+
67+ for (const artifact of artifacts) {
68+ const apiDownloadUrl = `https://api.github.com/repos/${context.repo.owner}/${context.repo.repo}/actions/artifacts/${artifact.id}/zip`;
69+
70+ commentBody += `- [📥 **${artifact.name}**](${apiDownloadUrl}) (Expires: ${new Date(artifact.expires_at).toLocaleDateString()})\n`;
71+ artifactsFound = true;
72+ }
73+ }
74+ }
75+
76+ if (artifactsFound) {
77+ // Set the output for the next step
78+ core.setOutput('comment_body', commentBody);
79+ } else {
80+ core.setOutput('comment_body', 'No artifacts found for this PR commit.');
81+ }
82+
83+ - name : Update Comment
84+ if : steps.artifact_finder.outputs.comment_body != 'No artifacts found for this PR commit.'
85+ uses : peter-evans/create-or-update-comment@v5
86+ with :
87+ issue-number : ${{ github.event.pull_request.number }}
88+ body : ${{ steps.artifact_finder.outputs.comment_body }}
0 commit comments