name: Lint GitHub Workflow YAML Files

on:
  push:
    branches:
      - main
  pull_request:
    paths:
      - '.github/workflows/*.yml'
      - '.github/workflows/*.yaml'
      - '.github/actionlint.yaml'

permissions:
  contents: read

jobs:
  lint:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Set up Go
        uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
        with:
          go-version: stable
          cache: false

      - name: Cache Go
        id: go-cache
        uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
        with:
          path: |
            ~/go/bin
            ~/go/pkg/mod
          key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }}

      - name: Run Actionlint
        run: |
          make actionlint

      - name: Reminder to Address Linting Errors
        if: failure()
        run: echo "⚠️ Please address all linting errors before merging this pull request."

      - name: All linting checks passed
        if: success()
        run: echo "✅ All linting checks passed."
