---
name: ShellCheck check

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

permissions: {}

jobs:
  build:
    name: ShellCheck check
    runs-on: ubuntu-22.04
    permissions:
      contents: read
      pull-requests: read
      packages: read
      statuses: write
    steps:
      - name: ShellCheck installation
        run: apt-get update && apt-get install -y shellcheck=0.8.0-2
      - name: code checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
        with:
          fetch-depth: 0
      - name: ShellCheck check
        # https://www.shellcheck.net/wiki/Recursiveness
        run: |
          if find . -type f -name "*.sh" -print0 | grep -qz .; then
            find . -type f -name "*.sh" -print0 | xargs -0 shellcheck
            exit 0
          else
            echo "No shell scripts found. Skipping ShellCheck."
          fi
