name: Lint

concurrency:
  # for PR's cancel the running task, if another commit is pushed
  group: ${{ github.workflow }} ${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

on:
  # build on PR and push-to-main. This works for short-lived branches, and saves
  # CPU cycles on duplicated tests.
  # For long-lived branches that diverge, you'll want to run on all pushes, not
  # just on push-to-main.
  pull_request: {}
  push:
    branches:
    - master


jobs:
  lint:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - uses: leafo/gh-actions-lua@v10
        with:
          luaVersion: "5.4"

      - uses: leafo/gh-actions-luarocks@v4

      - name: dependencies
        run: |
          luarocks install luacheck

      - name: lint
        run: |
          for spec in $(find . -type f -name "*.rockspec"); do
            (luarocks lint $spec && echo "$spec [OK]") || (echo "$spec [NOK]"; exit 1);
          done
          luacheck .
