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

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  lint-ruby:
    name: Ruby
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ruby # Latest stable CRuby version
          bundler-cache: true
      - name: internal_investigation
        run: bundle exec rake internal_investigation

  lint-ruby-without-bundler:
    name: Ruby without Bundler
    runs-on: ubuntu-latest
    steps:
      # Install Ruby first so bundler installs no gems
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ruby # Latest stable CRuby version
      - uses: actions/checkout@v7
      - name: Package and install RuboCop locally
        run: |
          gem build
          gem install ./rubocop-*.gem --no-document
          gem install rubocop-performance rubocop-rake rubocop-rspec --no-document
      - name: internal_investigation
        run: rubocop
      # Regression test for https://github.com/rubocop/rubocop/issues/13867
      - name: internal_investigation with require
        run: |
          echo "require: rubocop-rspec" > .rubocop.yml
          # This should never give any offense, just testing it doesn't error
          rubocop Gemfile --only RSpec/AnyInstance

  lint-yaml:
    permissions:
      contents: read  # for actions/checkout to fetch code
      pull-requests: write  # for karancode/yamllint-github-action to post comments on PRs
    name: Yaml
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Yamllint
        uses: karancode/yamllint-github-action@v3.0.0
        with:
          yamllint_strict: true
          yamllint_format: parsable
          yamllint_comment: true
        env:
          GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
