Repository navigation
Add annotations #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Add annotations | |
| on: | |
| workflow_run: | |
| types: | |
| - completed | |
| workflows: | |
| - Lint | |
| jobs: | |
| annotate: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| name: | |
| - flake8-py3 | |
| - clang-tidy | |
| runs-on: ubuntu-18.04 | |
| steps: | |
| - name: Download artifact | |
| uses: actions/github-script@v3 | |
| env: | |
| RUN_ID: ${{ github.event.workflow_run.id }} | |
| LINT_NAME: ${{ matrix.name }} | |
| with: | |
| # https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | |
| script: | | |
| const artifacts = await github.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: process.env.RUN_ID, | |
| }); | |
| const filteredArtifacts = artifacts.data.artifacts.filter(artifact => { | |
| return artifact.name == process.env.LINT_NAME; | |
| }); | |
| if (filteredArtifacts.length > 0) { | |
| const matchArtifact = filteredArtifacts[0]; | |
| const download = await github.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| const fs = require('fs'); | |
| fs.writeFileSync( | |
| `${process.env.GITHUB_WORKSPACE}/linter-output.zip`, | |
| Buffer.from(download.data), | |
| ); | |
| } | |
| - name: Unzip artifact | |
| id: unzip | |
| run: | | |
| if unzip linter-output.zip annotations.json commit-sha.txt; then | |
| echo ::set-output \ | |
| name=sha::"$(grep -Em1 '^[[:xdigit:]]{40}$' commit-sha.txt)" | |
| fi | |
| - if: steps.unzip.outputs.sha | |
| name: Add annotations | |
| uses: pytorch/add-annotations-github-action@master | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| check_name: ${{ matrix.name }} | |
| linter_output_path: annotations.json | |
| commit_sha: ${{ steps.unzip.outputs.sha }} | |
| mode: json |