name: checks

on:
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  linter-check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/setup-go@v3
        with:
          go-version: '1.20.x'
      - uses: actions/checkout@v3

      - name: Install npm formatting/linting tools
        run: npm install --global --save-dev prettier prettier-plugin-solidity solhint

      # shellcheck should already be installed, but it doesn't hurt
      - name: Install apt formatting/linting tools
        run: sudo apt install -y shfmt shellcheck

      - name: Run formatters
        run: make format && diff -u <(echo -n) <(git status --short --untracked-files=no)

      - name: Run linters
        run: make lint

  mockgen-check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/setup-go@v3
        with:
          go-version: '1.20.x'
      - uses: actions/checkout@v3

      - name: Generate mocks and verify no changes
        run: make mock && diff -u <(echo -n) <(git status --short --untracked-files=no)

  vet-check:
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/setup-go@v3
        with:
          go-version: '1.20.x'
      - uses: actions/checkout@v3

      - name: Run go vet
        run: |
          go vet ./...
