|
1 | 1 | # Copyright lowRISC contributors.
|
2 | 2 | # Licensed under the Apache License, Version 2.0, see LICENSE for details.
|
3 | 3 | # SPDX-License-Identifier: Apache-2.0
|
| 4 | + |
| 5 | +# GitHub Action to run Verible linting on pull requests and add review comments. |
| 6 | +# |
| 7 | +# See https://github.com/chipsalliance/verible-linter-action. |
| 8 | + |
4 | 9 | name: pr-lint-review
|
5 | 10 |
|
| 11 | +# Triggers when there is any activity on a pull request, e.g. opened, updated. |
| 12 | +# |
| 13 | +# The action runs in the context of the _base_ of the pull request, but later we |
| 14 | +# checkout the repository at the pull request's HEAD to run linting. |
6 | 15 | on:
|
7 |
| - workflow_run: |
8 |
| - workflows: ["pr-trigger"] |
9 |
| - types: |
10 |
| - - completed |
| 16 | + pull_request_target: |
11 | 17 |
|
12 | 18 | jobs:
|
13 |
| - review_triggered: |
| 19 | + verible-lint: |
14 | 20 | runs-on: ubuntu-latest
|
| 21 | + # Grant write permissions only for setting checks and adding review comments |
| 22 | + # to pull requests. |
| 23 | + permissions: |
| 24 | + checks: write |
| 25 | + contents: read |
| 26 | + pull-requests: write |
| 27 | + env: |
| 28 | + verible_config: 'vendor/lowrisc_ip/lint/tools/veriblelint/lowrisc-styleguide.rules.verible_lint' |
15 | 29 | steps:
|
16 |
| - - uses: actions/checkout@v2 |
17 |
| - |
18 |
| - # this workflow does not run in a PR context |
19 |
| - # download 'event.json' file from a PR-tiggered workflow |
20 |
| - # to mock the PR context and make a review |
21 |
| - - name: 'Download artifact' |
22 |
| - id: get-artifacts |
23 |
| - |
| 30 | + - uses: actions/checkout@v3 |
24 | 31 | with:
|
25 |
| - script: | |
26 |
| - var artifacts = await github.actions.listWorkflowRunArtifacts({ |
27 |
| - owner: context.repo.owner, |
28 |
| - repo: context.repo.repo, |
29 |
| - run_id: ${{github.event.workflow_run.id }}, |
30 |
| - }); |
31 |
| - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
32 |
| - return artifact.name == "event.json" |
33 |
| - })[0]; |
34 |
| - var download = await github.actions.downloadArtifact({ |
35 |
| - owner: context.repo.owner, |
36 |
| - repo: context.repo.repo, |
37 |
| - artifact_id: matchArtifact.id, |
38 |
| - archive_format: 'zip', |
39 |
| - }); |
40 |
| - var fs = require('fs'); |
41 |
| - fs.writeFileSync('${{github.workspace}}/event.json.zip', Buffer.from(download.data)); |
42 |
| - - run: | |
43 |
| - unzip event.json.zip |
| 32 | + # Because `pull_request_target` runs at the PR's base, we need to |
| 33 | + # checkout the head of the PR before running the lint. |
| 34 | + ref: ${{ github.event.pull_request.head.sha }} |
| 35 | + - name: Display Verible config |
| 36 | + run: | |
| 37 | + echo "::group::Verible config" |
| 38 | + cat "$verible_config" |
| 39 | + echo "::endgroup::" |
44 | 40 | - name: Run Verible linter action
|
45 | 41 | uses: chipsalliance/verible-linter-action@main
|
46 | 42 | with:
|
47 | 43 | github_token: ${{ secrets.GITHUB_TOKEN }}
|
48 | 44 | suggest_fixes: 'false'
|
49 |
| - config_file: 'vendor/lowrisc_ip/lint/tools/veriblelint/lowrisc-styleguide.rules.verible_lint' |
| 45 | + config_file: ${{ env.verible_config }} |
0 commit comments