nightly_pr_comment.yml 2.9 KB

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