Automatic SystemVerilog linting in github actions with the help of Verible

Overview

Verible Lint Action

Usage

See action.yml

This is a GitHub Action used to lint Verilog and SystemVerilog source files and comment erroneous lines of code in Pull Requests automatically. The GitHub Token input is used to provide reviewdog access to the PR. If you don't wish to use the automatic PR review, you can omit the github_token input. If you'd like to use a reporter of reviewdog other than github-pr-review, you can pass its name in the input reviewdog_reporter.

Here's a basic example to lint all *.v and *.sv files:

name: Verible linter example
on:
  pull_request:
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
    - uses: chipsalliance/[email protected]
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}

You can provide optional arguments to specify paths, exclude paths, a config file and extra arguments for verible-verilog-lint.

- uses: chipsalliance/[email protected]
  with:
    config_file: 'config.rules'
    paths: |
      ./rtl
      ./shared
    exclude_paths: |
      ./rtl/some_file
    extra_args: "--check_syntax=true"
    github_token: ${{ secrets.GITHUB_TOKEN }}

Automatic review on PRs from external repositories

In GitHub Actions, workflows triggered by external repositories may only have read access to the main repository. In order to have automatic reviews on external PRs, you need to create two workflows. One will be triggered on pull_request and upload the data needed by reviewdog as an artifact. The artifact shall store the file pointed by $GITHUB_EVENT_PATH as event.json. The other workflow will download the artifact and use the Verible action.

For example:

name: upload-event-file
on:
  pull_request:

...
      - run: cp "$GITHUB_EVENT_PATH" ./event.json
      - name: Upload event file as artifact
        uses: actions/[email protected]
        with:
          name: event.json
          path: event.json
{ 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 action with Reviewdog uses: chipsalliance/[email protected] with: github_token: ${{ secrets.GITHUB_TOKEN }} ">
name: review-triggered
on:
  workflow_run:
    workflows: ["upload-event-file"]
    types:
      - completed

jobs:
  review_triggered:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: 'Download artifact'
        id: get-artifacts
        uses: actions/[email protected]
        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 action with Reviewdog
        uses: chipsalliance/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
Comments
  • Convert to Container Action

    Convert to Container Action

    Close #3

    Unfortunately, when the image is built automatically as part of a Container Action, it seems that global environment variables are not inherited. Therefore, enabling BuildKit globally through DOCKER_BUILDKIT does not work. That would be desirable in order to use https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#build-mounts-run---mount in the dockerfile. For now, I worked around it by using a COPY statement (a layer) instead. Nonetheless, I kept the commit isolated, because it might be reverted when building the image is decoupled from the execution.

    I added a very simple CI workflow for testing the execution of the Action. Yet, since there is no "demo" project here, execution is rather useless. It would be interesting if someone familiar with Verible would contribute an example project in a follow-up PR.

    NOTE: Since GitHub Actions is not enabled in this repository yet, results are not shown below. See https://github.com/umarcor/verible-linter-action/actions

    opened by umarcor 4
  • Always use latest verible

    Always use latest verible

    Similar to the verible-formatter-action, fetch the most recent version of verible and perform the linting.

    Should the same arguments be used as before or should it be done the same way as the formatting action?

    • -f fail fast without html error document
    • -S shows an error message on fail
    • -L follows a redirect
    opened by mole99 3
  • Optimise execution by using a Container Action

    Optimise execution by using a Container Action

    The current implementation of this Action is of type Composite. In the first five steps, the dependencies are downloaded and installed: https://github.com/chipsalliance/verible-linter-action/blob/main/action.yml#L31-L51. In the last step, which is a single bash script, the actual functionality is implemented: https://github.com/chipsalliance/verible-linter-action/blob/main/action.yml#L52-L87.

    I recommend to convert this Action into a Container Action, since having it be a Composite does not provide any meaningful advantage in this use case.

    The advantage of spliting dependency installation into a Dockerfile is that it can be later decoupled. That means, building and deploying the container image on one side, and using it in the action on the other side. As a result, the Action will be executed faster.

    For reference, that approach is used in mithro/actions-includes:

    • https://github.com/mithro/actions-includes/blob/main/action.yml#L27-L29
    • https://github.com/mithro/actions-includes/blob/main/docker/Dockerfile
    • https://github.com/mithro/actions-includes/blob/main/.github/workflows/publish-docker-image.yml

    Similar strategy, without decoupling, in dbhi/qus:

    • https://github.com/dbhi/qus/blob/main/action/action.yml
    • https://github.com/dbhi/qus/blob/main/action/Dockerfile

    and eine/tip:

    • https://github.com/eine/tip/blob/master/action.yml
    • https://github.com/eine/tip/blob/master/Dockerfile
    opened by umarcor 2
  • Push container image to GHCR and use it in the Action

    Push container image to GHCR and use it in the Action

    This is a folloy-up of #4.

    As commented in #3, building the container image separatedly and the using it at runtime can reduce the execution time for users of this Action. In this PR, a workflow is added, which builds image ghcr.io/chipsalliance/verible-linter-action and pushes it to the GitHub Container Registry, using the default token. Then, in the Action, that image is used instead of the Dockerfile.

    • Current execution time (92s): https://github.com/chipsalliance/verible-linter-action/actions/runs/1192256099
    • Image build and push time (131s): https://github.com/umarcor/verible-linter-action/actions/runs/1194493666
    • Execution time using the image (22s): https://github.com/umarcor/verible-linter-action/actions/runs/1194493667

    The workflows are scheduled weekly. Feel free to adjust that to your needs.

    NOTE: CI will fail below because this PR does not have permission for pushing to ghcr.io/chipsalliance. That will work after this is merged to main. Precisely, workflow Container will work as soon as it is merged, and Test will need to be rerun afte the image is pushed for the first time. The references to my fork above did work because I temporarily used ghcr.io/umarcor instead.

    opened by umarcor 1
  • Always use latest verible

    Always use latest verible

    Re-opening of #19 due to an error on my end.

    Similar to the verible-formatter-action, fetch the most recent version of verible and perform the linting.

    opened by mole99 0
  • Colon is missing from error messages produced by reviewdog

    Colon is missing from error messages produced by reviewdog

    Reviewdog reports (e.g. here)

    Unpacked dimension range must be declared in big-endian ([0N-1]) order. Declare zero-based big-endian unpacked dimensions sized as [N]. [Style unpacked-ordering] [unpacked-dimensions-range-ordering]

    Look at the "[0N-1]" string, which should be "[0:N-1]" (the Verible source code agrees with me).

    We somewhere loose the colon in the path between Verible and the GH action reporting.

    opened by imphil 0
  • add GitHub token to test

    add GitHub token to test

    The test would fail because the default reporter is "github-pr-review" and there wasn't a token provided. The reason I change the test, and not the code of the action, is because I assume that the correct usage of the action is to either:

    1. Use a reporter that requires the token ("github-pr-review") AND provide the token.
    2. Use a reporter that doesn't require the token (for example "local").

    The workflow was successful here: https://github.com/antmicro/verible-linter-action/actions/runs/1266083502

    opened by wsipak 0
  • Add action input fail_on_error

    Add action input fail_on_error

    This allows to choose whether the action should fail or not, depending on the result of running Verible. Use fail_on_error: 'true' to fail the action if a rule violation that is relevant to a PR exists.

    For testing purposes, this PRs have been created:

    1. Failing disabled, errors were posted as code review, but the workflow was successful anyway: https://github.com/antmicro/gha-playground/pull/95
    2. Failing enabled, errors were posted as code review and the workflow failed: https://github.com/antmicro/gha-playground/pull/96
    3. Failing enabled, but no rule violations were found, thus the workflow succeeded: https://github.com/antmicro/gha-playground/pull/97
    opened by wsipak 0
  • exit the action without error

    exit the action without error

    Previously, the action would exit with non-zero code whenever rule violations were found, even if the violations did not belong to the changes in PR. We could either change it to return non-zero when violations are relevant, or always return zero. I'm changing this to always exit successfully and my reasoning here is that, if there are relevant violations, we'll see them in code review (so we don't really need the negative flag), and we can use non-zero exit codes for internal errors in the action, not related to output from Verible.

    opened by wsipak 0
  • Fix missing output from action.py

    Fix missing output from action.py

    The newer version of Verible:

    1. Prints rule violations to stderr, not stdout (This caused problems in Ibex repository).
    2. Uses different values for autofix argument (I thought I had added this change already, and I'm adding it now).

    A test PR was recreated here: https://github.com/antmicro/gha-playground/pull/93

    opened by wsipak 0
  • Fix remote url handling when a PR from a fork is created

    Fix remote url handling when a PR from a fork is created

    The action needs to handle two remotes. One for the main repo, and the other for the source of the PR. This wasn't handled properly and is fixed here. The problem appeared here: https://github.com/lowRISC/ibex/pull/1434

    Right now the script retrieves the URL of the remote from event.json and fetches the right branch from it. Additionally, hash of the HEAD is printed so that it's easy to confirm correctness of operation.

    I've checked these scenarios:

    1. The branch used in a PR doesn't exist in the main repo, and it works.
    2. The branch used in a PR does exist in the main repo, and it's actually fetched from the fork. (Previously the script tried to fetch it from mainline)
    opened by wsipak 0
  • List of repos where the action could be used

    List of repos where the action could be used

    We need to compile a list of repositories that contain SystemVerilog or Verilog (even simple test cases) where we could enable the Verible actions.

    Let me start with

    Please comment with suggestions of other repositories CC @hzeller @mkurc-ant @kgugala

    opened by tgorochowik 0
Releases(v1.4)
Owner
CHIPS Alliance
Common Hardware for Interfaces, Processors and Systems
CHIPS Alliance
This is a simple bot that can be used to upload images to a third-party cloud (image hosting). Currently, only the imgbb.com website supports the bot. I Will do future updates

TGImageHosting This is a simple bot that can be used to upload images to a third party cloud (image hosting). Currently, only the imgbb.com website su

Abhijith N T 0 Dec 26, 2021
AminoLab Library For AminoApps using aminoapps.com/api

AminoLab AminoLab Api For AminoApps using aminoapps.com/api Installing pip install AminoLab Example #Login import AminoLab client = AminoLab.Client()

10 Sep 26, 2022
A community Billy vs SNAKEMAN bot

BvS Bot A discord bot built for the Billy vs SNAKEMAN community! Dependencies An installation of Python 3.9.x with ssl compiled. The following pip pac

Neopolitan 2 May 10, 2022
A Python API wrapper for the Twitter API!

PyTweet PyTweet is an api wrapper made for twitter using twitter's api version 2! Installation Windows py3 -m pip install PyTweet Linux python -m pip

TheFarGG 1 Nov 19, 2022
A simpler way to make forms, surveys, and reaction input using discord.py.

discord-ext-forms An easier way to make forms and surveys in discord.py. This module is a very simple way to ask questions and create complete forms i

thrizzle 16 Nov 06, 2022
AnyAPI is a library that helps you to write any API wrapper with ease and in pythonic way.

AnyAPI AnyAPI is a library that helps you to write any API wrappers with ease and in pythonic way. Features Have better looking code using dynamic met

Fatih Kilic 129 Sep 20, 2022
A bot framework for Reddit to manage threads, wiki pages, widgets, menus and more.

Sub Manager Sub Manager is a bot framework for Reddit to automate a variety of tasks on one or more subreddits, and can be configured and run without

r/SpaceX 3 Aug 26, 2022
The text based version of my App Blocker that I planning on converting to GUI soon.

App-Blocker The text based version of my App Blocker that I planning on converting to GUI soon. Currently I am just uploading the appblocker.py file,

Harsh Raj 0 Sep 13, 2022
This is a bot which you can use in telegram to spam without flooding and enjoy being in the leaderboard

Telegram-Count-spamming-Bot This is a bot which you can use in telegram to spam without flooding and enjoy being in the leaderboard You can avoid the

Lalan Kumar 1 Oct 23, 2021
Python Capfire API wrapper

General CampfireAPI based on Campfire web. Install pip install Campfire-API Quickstart Use it without login: from campfire_api import CampfireAPI cf

Ghost 0 Jan 03, 2022
A simple fun discord bot using discord.py that can post memes

A simple fun discord bot using discord.py * * Commands $commands - to see all commands $meme - for a random meme from the internet $cry - to make the

Dice Flip 2 Dec 20, 2021
Asynchronous python aria2 mirror bot Telegram.

aioaria2-mirror-bot A Bot for Telegram made with Python using Pyrogram library. It needs Python 3.9 or newer to run. THIS BOT IS INTENDED TO BE USED O

Adek 85 Jan 03, 2023
A powerful bot to copy your google drive data to your team drive

⚛️ Clonebot - Heroku version ⚡ CloneBot is a telegram bot that allows you to copy folder/team drive to team drives. One of the main advantage of this

MsGsuite 269 Dec 23, 2022
Discord bot that shows valorant your daily store by using the Ingame API

Valorant store checker - Discord Bot Discord bot that shows valorant your daily store by using the Ingame API. written using Python and the Pycord lib

STACIA 226 Jan 02, 2023
Discord Selfbot, 90+ commands

Setting the bot up. STEP 1: copy the directory yook.club selfbot was downloaded and extracted into, open cmd and type "cd " then paste. STEP 2: python

yook 1 Dec 12, 2021
Exports saved posts and comments on Reddit to a csv file.

reddit-saved-to-csv Exports saved posts and comments on Reddit to a csv file. Columns: ID, Name, Subreddit, Type, URL, NoSFW ID: Starts from 1 and inc

70 Jan 02, 2023
A python script that changes our background based on current weather and time of the day.

Desktop background on Windows 10, based on current weather and time A python script that changes our background based on current weather and time of t

Maj Gaberšček 1 Nov 16, 2021
Awslogs - AWS CloudWatch logs for Humans™

awslogs awslogs is a simple command line tool for querying groups, streams and events from Amazon CloudWatch logs. One of the most powerful features i

Jorge Bastida 4.5k Dec 30, 2022
Cookiecutter templates for Serverless applications using AWS SAM and the Rust programming language.

Cookiecutter SAM template for Lambda functions in Rust This is a Cookiecutter template to create a serverless application based on the Serverless Appl

AWS Samples 24 Nov 11, 2022