Skip to content

Commit 1eb0bea

Browse files
committed
[ci] Consolidate Verible linting workflow into one stage
Running the verible linter and adding review comments to the pull request previously had to be done in two stages: 1. Triggered on the pull request - prepare config and waiver files as artifacts. 2. Running on the repo's HEAD - run Verible and add review comments. This was required because Actions running in the context of the pull request did not have write permissions to add comments to pull requests. This is now possible with the `pull_request_target` event, which triggers when pull requests change, but runs in the context of the repo's HEAD and has the permissions to create comments. See #1427 and chipsalliance/verible-linter-action#31 for details. Signed-off-by: James Wainwright <[email protected]>
1 parent 06df664 commit 1eb0bea

File tree

2 files changed

+29
-58
lines changed

2 files changed

+29
-58
lines changed

.github/workflows/pr_lint_review.yml

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,45 @@
11
# Copyright lowRISC contributors.
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# 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+
49
name: pr-lint-review
510

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.
615
on:
7-
workflow_run:
8-
workflows: ["pr-trigger"]
9-
types:
10-
- completed
16+
pull_request_target:
1117

1218
jobs:
13-
review_triggered:
19+
verible-lint:
1420
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'
1529
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-
uses: actions/[email protected]
30+
- uses: actions/checkout@v3
2431
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::"
4440
- name: Run Verible linter action
4541
uses: chipsalliance/verible-linter-action@main
4642
with:
4743
github_token: ${{ secrets.GITHUB_TOKEN }}
4844
suggest_fixes: 'false'
49-
config_file: 'vendor/lowrisc_ip/lint/tools/veriblelint/lowrisc-styleguide.rules.verible_lint'
45+
config_file: ${{ env.verible_config }}

.github/workflows/pr_trigger.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)