name: check
on:
  pull_request:
  workflow_dispatch:
  workflow_call:
    inputs:
      branch:
        description: "ref branch for this workflow"
        default: "master"
        required: true
        type: string

env:
  CARGO_TERM_COLOR: always

jobs:

  checks:
    runs-on: ubuntu-latest
    steps:

    - name: Checkout repository
      uses: actions/checkout@v4.1.7
      with:
        ref: ${{ inputs.branch }}

    - name: Shellcheck
      if: always()
      run: bin/check/shellcheck.sh

    - name: Check ad hoc
      if: always()
      run: bin/check/ad_hoc.sh

    - name: Git leaks
      if: always()
      uses: addnab/docker-run-action@v3
      with:
        image: ghcr.io/zricethezav/gitleaks:latest
        options: --volume ${{ github.workspace }}:/work:rw --workdir /work --privileged --env CARGO_TERM_COLOR=always
        run: gitleaks detect --verbose --config .github/workflows/config/gitleaks.toml

    - name: Hadolint
      if: always()
      run: bin/check/hadolint.sh ./contrib/docker/Dockerfile

    - name: Install prerequisites
      if: always()
      run: |
        bin/check/install_prerequisites.sh
        bin/install_python3_venv.sh
        export PATH="/tmp/hurl-python3-venv/bin:$PATH"
        echo "PATH=$PATH" >> $GITHUB_ENV
        which python3
        python3 --version
        pip --version

    - name: Check Rust version
      if: always()
      run: |
        python3 -m pip install requests --quiet
        bin/check/rust_version.py 7

    - name: Generated
      if: always()
      run: bin/check/generated.sh

    - name: Rustfmt
      if: always()
      run: bin/check/rustfmt.sh

    - name: Clippy
      if: always()
      run: bin/check/clippy.sh

    - name: Black
      if: always()
      run: bin/check/black.sh

    - name: Check XML/HTML files
      if: always()
      run: bin/check/xmllint.sh

    - name: Hurlfmt
      if: always()
      run: |
        bin/release/release.sh
        export PATH=target/release:$PATH
        bin/check/hurlfmt.sh

    - name: Check crates licence
      if: always()
      run: python3 bin/check/license.py

    - name: Check hurl crate API changes
      if: always()
      run: bin/check/compatibility.sh

    - name: Check doc generation
      if: always()
      run: bin/check/doc.sh

    - name: Check completion files
      if: always()
      run: |
        sudo apt-get install -y zsh fish powershell
        bin/check/completion.sh
