From e058690b00dda3a20c315ed105a796d4e85b4647 Mon Sep 17 00:00:00 2001 From: Wojciech Sipak Date: Wed, 25 Aug 2021 17:54:47 +0200 Subject: [PATCH] [ci] Add GHA workflows to review PRs using Verible Any activity regarding a Pull Request will trigger workflows that create automatic code review using outputs from Verible linter --- .github/workflows/pr_lint_review.yml | 49 ++++++++++++++++++++++++++++ .github/workflows/pr_trigger.yml | 25 ++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/pr_lint_review.yml create mode 100644 .github/workflows/pr_trigger.yml diff --git a/.github/workflows/pr_lint_review.yml b/.github/workflows/pr_lint_review.yml new file mode 100644 index 0000000000..ec42384ea4 --- /dev/null +++ b/.github/workflows/pr_lint_review.yml @@ -0,0 +1,49 @@ +# Copyright lowRISC contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +name: pr-lint-review + +on: + workflow_run: + workflows: ["pr-trigger"] + types: + - completed + +jobs: + review_triggered: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + # this workflow does not run in a PR context + # download 'event.json' file from a PR-tiggered workflow + # to mock the PR context and make a review + - name: 'Download artifact' + id: get-artifacts + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "event.json" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/event.json.zip', Buffer.from(download.data)); + - run: | + unzip event.json.zip + - name: Run Verible linter action + uses: chipsalliance/verible-linter-action@v1.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + suggest_fixes: 'false' + config_file: 'vendor/lowrisc_ip/lint/tools/veriblelint/rules.vbl' diff --git a/.github/workflows/pr_trigger.yml b/.github/workflows/pr_trigger.yml new file mode 100644 index 0000000000..b969698b2c --- /dev/null +++ b/.github/workflows/pr_trigger.yml @@ -0,0 +1,25 @@ +# Copyright lowRISC contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +name: pr-trigger + +on: + pull_request: + +jobs: + upload: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Copy event file + run: cp "$GITHUB_EVENT_PATH" ./event.json + + # If this workflow is triggered by a PR from a fork + # it won't have sufficient access rights to make a review + # so we just save the file needed to do the review + # in a context with proper access rights + - name: Upload event file as artifact + uses: actions/upload-artifact@v2 + with: + name: event.json + path: event.json