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@v3
      with:
        ref: ${{ inputs.branch }}

    - name: Shellcheck
      run: bin/check/shellcheck.sh

    - name: Check ad hoc
      run: bin/check/ad_hoc.sh

    - name: Git leaks
      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
      run: bin/check/hadolint.sh ./contrib/docker/Dockerfile

    - name: Install prerequisites
      run: bin/check/install_prerequisites.sh

    - name: Rustfmt
      run: bin/check/rustfmt.sh

    - name: Clippy
      run: bin/check/clippy.sh

    - name: Black
      run: bin/check/black.sh

    - name: Check XML/HTML files
      run: bin/check/xmllint.sh

    - name: Run crates update
      run: bin/check/crates.sh 

    - name: Check crates licence
      run: python3 bin/check/license.py

    - name: Check hurl crate API changes
      run: bin/check/compatibility.sh

