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