printer-linter-pr-post.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. name: printer-linter-pr-post
  2. on:
  3. workflow_run:
  4. workflows: ["printer-linter-pr-diagnose"]
  5. types: [completed]
  6. jobs:
  7. printer-linter-result:
  8. # Trigger the job only if the previous (insecure) workflow completed successfully
  9. if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
  10. runs-on: ubuntu-latest
  11. permissions:
  12. pull-requests: write
  13. steps:
  14. - name: Download analysis results
  15. uses: actions/github-script@v7
  16. with:
  17. script: |
  18. const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
  19. owner: context.repo.owner,
  20. repo: context.repo.repo,
  21. run_id: ${{github.event.workflow_run.id }},
  22. });
  23. const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
  24. return artifact.name == "printer-linter-result"
  25. })[0];
  26. const download = await github.rest.actions.downloadArtifact({
  27. owner: context.repo.owner,
  28. repo: context.repo.repo,
  29. artifact_id: matchArtifact.id,
  30. archive_format: "zip",
  31. });
  32. const fs = require("fs");
  33. fs.writeFileSync("${{ github.workspace }}/printer-linter-result.zip", Buffer.from(download.data));
  34. - name: Extract analysis results
  35. run: |
  36. mkdir printer-linter-result
  37. unzip -j printer-linter-result.zip -d printer-linter-result
  38. - name: Set PR details environment variables
  39. uses: actions/github-script@v7
  40. with:
  41. script: |
  42. const assert = require("node:assert").strict;
  43. const fs = require("fs");
  44. function exportVar(varName, fileName, regEx) {
  45. const val = fs.readFileSync("${{ github.workspace }}/printer-linter-result/" + fileName, {
  46. encoding: "ascii"
  47. }).trimEnd();
  48. assert.ok(regEx.test(val), "Invalid value format for " + varName);
  49. core.exportVariable(varName, val);
  50. }
  51. exportVar("PR_ID", "pr-id.txt", /^[0-9]+$/);
  52. exportVar("PR_HEAD_REPO", "pr-head-repo.txt", /^[-./0-9A-Z_a-z]+$/);
  53. exportVar("PR_HEAD_SHA", "pr-head-sha.txt", /^[0-9A-Fa-f]+$/);
  54. fs.access("${{ github.workspace }}/printer-linter-result/comment.md", fs.constants.F_OK, (err) => {
  55. if (err) {
  56. core.exportVariable("commentFileExists", "false");
  57. } else {
  58. core.exportVariable("commentFileExists", "true");
  59. }
  60. });
  61. - uses: actions/checkout@v4
  62. with:
  63. repository: ${{ env.PR_HEAD_REPO }}
  64. ref: ${{ env.PR_HEAD_SHA }}
  65. persist-credentials: false
  66. - name: Redownload analysis results
  67. uses: actions/github-script@v7
  68. with:
  69. script: |
  70. const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
  71. owner: context.repo.owner,
  72. repo: context.repo.repo,
  73. run_id: ${{github.event.workflow_run.id }},
  74. });
  75. const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
  76. return artifact.name == "printer-linter-result"
  77. })[0];
  78. const download = await github.rest.actions.downloadArtifact({
  79. owner: context.repo.owner,
  80. repo: context.repo.repo,
  81. artifact_id: matchArtifact.id,
  82. archive_format: "zip",
  83. });
  84. const fs = require("fs");
  85. fs.writeFileSync("${{ github.workspace }}/printer-linter-result.zip", Buffer.from(download.data));
  86. - name: Extract analysis results
  87. run: |
  88. mkdir printer-linter-result
  89. unzip -j printer-linter-result.zip -d printer-linter-result
  90. - name: Run PR Comments
  91. if: env.commentFileExists == 'true'
  92. uses: peter-evans/create-or-update-comment@v4
  93. with:
  94. issue-number: ${{ env.PR_ID }}
  95. body-path: 'printer-linter-result/comment.md'
  96. - name: Run clang-tidy-pr-comments action
  97. uses: platisd/clang-tidy-pr-comments@v1
  98. with:
  99. github_token: ${{ secrets.GITHUB_TOKEN }}
  100. clang_tidy_fixes: printer-linter-result/fixes.yml
  101. pull_request_id: ${{ env.PR_ID }}
  102. request_changes: true