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
Python API Client for Twitter API v2

๐Ÿ Python Client For Twitter API v2 ๐Ÿš€ Why Twitter Stream ? Twitter-Stream.py a python API client for Twitter API v2 now supports FilteredStream, Samp

Twitivity 31 Nov 19, 2022
An script where it logs in your instagram account and follows people and likes their posts

InstaFollower An script where it logs in your instagram account and follows people and likes their posts (uses the tags to fetch people) Requirements:

Bless 3 Nov 29, 2022
Uploader-Bot - A Modified Telegram Url Uploader Bot With Mongodb, Zee5, Sonyliv Support and Many Other Yt-dlp Sites

๐š๐šŽ๐šš๐šž๐š’๐š›๐šŽ๐š ๐š…๐šŠ๐š›๐š’๐šŠ๐š‹๐š•๐šŽ๐šœ ๐Ÿ”Š APP_ID API_HASH TG_BOT_TOKEN DATABASE_URL

11 Sep 10, 2022
A simple API wrapper for Discord written in Python.

AIOCord This project is work in progress not for production use A simple asynchronous API wrapper around Discord API written in Python. Inspiration Th

Izhar Ahmad 3 Dec 07, 2021
A slack bot that notifies you when a restaurant is available for orders

Slack Wolt Notifier A Slack bot that notifies you when a Wolt restaurant or venue is available for orders. How does it work? Slack supports bots that

Gil Matok 8 Oct 24, 2022
Materials for the AMS 2022 Student Conference Python Workshop.

AMS 2022 Student Conference Python Workshop Let's talk MetPy! Here you will find a collection of notebooks we will be demonstrating and working throug

Unidata 4 Dec 13, 2022
A VCVideoPlayer Bot for Telegram made with ๐Ÿ’ž By @TeamDeeCoDe

VC Video Player How To Host โœจ Heroku Deploy โœจ The easiest way to deploy this Bot is via Heroku. Credit ๐Ÿ”ฅ |๐Ÿ‡ฎ๐Ÿ‡ณ Louis |๐Ÿ‡ฎ๐Ÿ‡ณ Sammy |๐Ÿ‡ฎ๐Ÿ‡ณ Blaze |๐Ÿ‡ฎ๐Ÿ‡ณ S

TeamDeeCode 6 Feb 28, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

1 Jan 15, 2022
An NFTGenerator to generate NFTs and send them to nft.storage

NFTGenerator Table of Contents Overview Installation Introduction Features Reflection Issues & bug reports Show your support Credits Overview The NFTG

3 Mar 14, 2022
A simple Python library to integrate with the Heron Data API

Heron Python This library provides easy access to the Heron Data API from applications written in Python. Documentation No language-specific docs are

Heron Data 11 Nov 11, 2022
A Discord Self-Bot in Python

๐Ÿ‘จโ€๐Ÿ’ป Discord Self Bot ๐Ÿ‘จโ€๐Ÿ’ป A Discord Self-Bot in Python by natrix Installation Run: selfbot.bat Python: version : 3.8 Modules

natrix_dev 3 Oct 02, 2022
Compares and analyzes GCP IAM roles.

gcp-iam-analyzer I wrote this to help in my day to day working in GCP. A lot of the time I am doing role comparisons to see which role has more permis

Jason Dyke 37 Dec 28, 2022
A Python wrapper for the QQ Channel API

A Python wrapper for the QQ Channel API

Fox_white 55 Dec 07, 2022
Apple iTunes In-app purchase verification tool

itunes-iap v2 Python 2 & 3 compatible! Even with :mod:`asyncio` support! Source code: https://github.com/youknowone/itunes-iap Documentation: http://i

Jeong YunWon 129 Dec 10, 2022
Tamil Voicechat UserBot. Powerd By TamilBots. Https://T.me/TamilSupport

Tamil Voicechat UserBot A Telegram UserBot to Play music ๐ŸŽถ in Voice Chats. It's recommended to use an USA number.(if your real number is suspended I'

Tamil Bots 78 Nov 01, 2022
Hazard-Nuker - Hazard Nuker With Python

๐ŸŒŸ Since hazard is free, donations are really appriciate and keeps the developme

โ€ โ€  9 Oct 26, 2022
A Telegram Bot That Can Find Lyrics Of Song

Lyrics-Search-Bot A Telegram Bot That Can Find Lyrics Of Song A Simple Telegram Bot That Can Extract Lyrics Of Any Songs Deploy Commands start - To St

Muhammed Fazin 11 Oct 21, 2022
Best badge generator API to count visitors of your Repository / Account ๐Ÿฅ‡

github visitors badge A badge generator service to count visitors of your markdown file. Hello every one! In this post, I will tell you the story of m

Sแด‡ษดแดœ Gแด€แดแด‡ส€ Bแดส ใ€ฝ 3 Dec 11, 2021
A basic template for Creating Odoo Module

Odoo ERP Boilerplate A basic template for Creating Odoo Module. Folders inside this repository consist of snippet code and a module example. Folders w

Altela Eleviansyah Pramardhika 1 Feb 06, 2022
Marketplace for self published books

Nile API API for the imaginary Nile marketplace for self published books. This is a project created to try out FastAPI as the post promising ASGI serv

Matt de Young 1 Jan 31, 2022