name: Lint / Syntax checks

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  hadolint:
    runs-on: ubuntu-latest
    container: ghcr.io/hadolint/hadolint:latest-alpine
    steps:
      - name: ↩️ Checkout
        uses: actions/checkout@v2
        
      - name: Get changed files
        id: changed_files
        uses: jitterbit/get-changed-files@v1

      - name: 🔎 Run hadolint
        run: |
          for files in ${{ steps.changed_files.outputs.all }}; do
            if [[ "$(basename ${files})" == "Dockerfile" ]]; then
              echo "Hadolint ${{ steps.changed_files.outputs.all }}"
              hadolint "${{ steps.changed_files.outputs.all }}"
            fi
          done

  shellcheck:
    runs-on: ubuntu-latest
    steps:
      - name: ↩️ Checkout
        uses: actions/checkout@v2

      - name: 📂 Detect chanced files
        id: filter
        uses: dorny/paths-filter@v2.9.0
        with:
          list-files: 'shell'
          filters: |
            shell:
              - '**/*.sh'
              - '**/cont-init.d/*'
              - '**/services.d/*'
      - name: 🔎 Run ShellCheck
        if: steps.filter.outputs.shell == 'true'
        uses: ludeeus/action-shellcheck@1.1.0
        with:
          additional_files: ${{ steps.filter.outputs.shell_files }}

  markdownlint:
    runs-on: ubuntu-latest
    steps:
      - name: ↩️ Checkout
        uses: actions/checkout@v2
        with:
          # Full git history is needed to get a proper list of changed files within `super-linter`
          fetch-depth: 0

      - name: 🔎 Run markdownlint
        uses: nosborn/github-action-markdown-cli@v1.1.1
        with:
          config_file: .markdownlint.yaml
