---
name: hadolint check

on: # yamllint disable-line rule:truthy
  pull_request:
    types: [opened, edited, reopened, synchronize]

permissions: {}

jobs:
  build:
    name: hadolint check
    runs-on: ubuntu-22.04
    permissions:
      contents: read
      pull-requests: read
      packages: read
      statuses: write
    steps:
      - name: hadolint installation
        working-directory: /bin
        run: |
          set -e

          VERSION="v2.12.0"
          CHECKSUM="5798551bf19f33951881f15eb238f90aef023f11e7ec7e9f4c37961cb87c5df6 hadolint"

          wget -O hadolint "https://github.com/hadolint/hadolint/releases/download/$VERSION/hadolint-Linux-arm64"
          echo "$CHECKSUM" | sha256sum --check

          chmod +x hadolint
      - name: code checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
        with:
          fetch-depth: 0
      - name: hadolint check
        run: |
          STATUS=0
          while read -r file; do
            echo "Linting $file..."
            hadolint "$file" || STATUS=1
          done < <(find . -name "Dockerfile")
          exit $STATUS
