name: Linters
permissions: read-all

on:
  pull_request:
    branches:
    - main
  workflow_dispatch:

jobs:
  jshint:
    name: Javascript Linter
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
    - name: Install linters
      run: |
        sudo npm install -g jshint@2.13.6 eslint@8.57.0
    - name: Run jshint
      run: jshint internal/ui/static/js/*.js
    - name: Run ESLint
      run: eslint internal/ui/static/js/*.js

  golangci:
    name: Golang Linters
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
      - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
        with:
          go-version: stable
      - uses: golangci/golangci-lint-action@82606bf257cbaff209d206a39f5134f0cfbfd2ee # v9.2.1
      - name: Run gofmt linter
        run: gofmt -d -e .

  commitlint:
    if: github.event_name == 'pull_request'
    name: Commit Linter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          fetch-depth: 0
      - name: Set up Python
        uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: '3.13'
      - name: Validate PR commits
        run: python3 .github/workflows/scripts/commit-checker.py --base ${{ github.event.pull_request.base.sha }} --head ${{ github.event.pull_request.head.sha }}
