nightly_pr_comment.yml
1 name: Comment PR artifacts links 2 3 on: 4 workflow_run: 5 workflows: ['Perform checks'] 6 types: [completed] 7 8 jobs: 9 pr_comment: 10 if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' 11 runs-on: ubuntu-latest 12 timeout-minutes: ${{ fromJSON(vars.JOB_TIMEOUT) }} 13 steps: 14 - uses: actions/github-script@v6 15 with: 16 script: | 17 const {owner, repo} = context.repo; 18 const run_id = ${{github.event.workflow_run.id}}; 19 const pull_head_sha = '${{github.event.workflow_run.head_sha}}'; 20 21 const issue_number = await (async () => { 22 const pulls = await github.rest.pulls.list({owner, repo}); 23 for await (const {data} of github.paginate.iterator(pulls)) { 24 for (const pull of data) { 25 if (pull.head.sha === pull_head_sha) { 26 return pull.number; 27 } 28 } 29 } 30 })(); 31 if (issue_number) { 32 core.info(`Using pull request ${issue_number}`); 33 } else { 34 return core.error(`No matching pull request found`); 35 } 36 37 const {data: {artifacts}} = await github.rest.actions.listWorkflowRunArtifacts({owner, repo, run_id}); 38 if (!artifacts.length) { 39 return core.error(`No artifacts found`); 40 } 41 let body = `Download the artifacts for this pull request:\n`; 42 let hidden_gtk_artifacts = `\n\n <details><summary>Old GUI (GTK3)</summary>\n`; 43 let hidden_headless_artifacts = `\n\n <details><summary>GUI-less (SDL2)</summary>\n`; 44 let hidden_debug_artifacts = `\n\n <details><summary>Only for Developers</summary>\n`; 45 for (const art of artifacts) { 46 if(art.name.includes('Debug')) { 47 hidden_debug_artifacts += `\n* [${art.name}](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`; 48 } else if(art.name.includes('gtk-ryujinx')) { 49 hidden_gtk_artifacts += `\n* [${art.name}](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`; 50 } else if(art.name.includes('sdl2-ryujinx-headless')) { 51 hidden_headless_artifacts += `\n* [${art.name}](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`; 52 } else { 53 body += `\n* [${art.name}](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`; 54 } 55 } 56 hidden_gtk_artifacts += `\n</details>`; 57 hidden_headless_artifacts += `\n</details>`; 58 hidden_debug_artifacts += `\n</details>`; 59 body += hidden_gtk_artifacts; 60 body += hidden_headless_artifacts; 61 body += hidden_debug_artifacts; 62 63 const {data: comments} = await github.rest.issues.listComments({repo, owner, issue_number}); 64 const existing_comment = comments.find((c) => c.user.login === 'github-actions[bot]'); 65 if (existing_comment) { 66 core.info(`Updating comment ${existing_comment.id}`); 67 await github.rest.issues.updateComment({repo, owner, comment_id: existing_comment.id, body}); 68 } else { 69 core.info(`Creating a comment`); 70 await github.rest.issues.createComment({repo, owner, issue_number, body}); 71 }