# https://dev.azure.com/home-assistant

trigger:
  branches:
    include:
      - master
pr:
  - master

variables:
  versionHadolint: "v1.17.2"
  versionShellCheck: "v0.7.0"

jobs:
  - job: "Hadolint"
    pool:
      vmImage: "ubuntu-latest"
    steps:
      - script: sudo docker pull hadolint/hadolint:$(versionHadolint)
        displayName: "Install Hadolint"
      - script: |
          set -e
          shopt -s globstar
          for dockerfile in **/Dockerfile
          do
            echo "Linting: $dockerfile"
            sudo docker run --rm -i \
              -v $(pwd)/.hadolint.yaml:/.hadolint.yaml:ro \
              hadolint/hadolint:$(versionHadolint) < "$dockerfile"
          done
        displayName: "Run Hadolint"

  - job: "ShellCheck"
    pool:
      vmImage: "ubuntu-latest"
    steps:
      - script: sudo docker pull koalaman/shellcheck:$(versionShellCheck)
        displayName: "Install ShellCheck"
      - script: |
          shopt -s globstar
          sudo docker run --rm -i \
            -v $(pwd):/mnt:ro koalaman/shellcheck:$(versionShellCheck) -s bash **/{*.sh,run}
        displayName: "Run ShellCheck"

  - job: "JQ"
    pool:
      vmImage: "ubuntu-latest"
    steps:
      - script: sudo apt-get install -y jq
        displayName: "Install JQ"
      - bash: |
          shopt -s globstar
          cat **/*.json | jq '.'
        displayName: "Run JQ"
