name: Lint
on:
  workflow_dispatch:
  push:
    branches:
      - master
  pull_request:

permissions:
  contents: read

jobs:
  markdownlint:
    name: Lint Markdown
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
    - name: Run Markdown linter
      uses: DavidAnson/markdownlint-cli2-action@ded1f9488f68a970bc66ea5619e13e9b52e601cd # v23.2.0
      with:
        globs: # set to null to override default of *.{md,markdown}

  spellcheck:
    name: Check spelling
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
    - name: Check spelling with cspell
      uses: streetsidesoftware/cspell-action@de2a73e963e7443969755b648a1008f77033c5b2 # v8.4.0
      with:
        incremental_files_only: true
        strict: true
        # cspell uses the .cspell.json configuration file
    - name: Check spelling with codespell
      uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2
      with:
        check_filenames: true
        check_hidden: true
        # codespell uses the .codespellrc file

  template-formatting:
    name: Check template formatting
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
    - name: Install Go
      uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
      with:
        go-version: "1.26"
        check-latest: true
        cache: true
        cache-dependency-path: |
          **/go.sum
          **/go.mod
    - name: Install gotmplfmt
      run: go install github.com/gohugoio/gotmplfmt@623175f49b3d07a11da381ff85228d0d03101880 # v0.4.1
    - name: Check template formatting
      run: "diff <(gotmplfmt -d layouts) <(printf '')"
