name: coverage

on:
  push:
    branches:
      - master
  workflow_dispatch:

permissions: {}

env:
  RUSTFLAGS: "-C instrument-coverage"

jobs:
  coverage:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust: [stable]
    steps:
    - name: Checkout repository
      uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
      with:
        persist-credentials: false

    - name: Install Prerequisites
      run: bin/install_prerequisites_ubuntu.sh

    - name: Install Python 3.11
      uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 #v6.2.0
      with:
        python-version: '3.11'

    - name: Tests prerequisites
      run: bin/test/test_prerequisites.sh

    - name: Install Rust
      run: bin/install_rust.sh

    - name: Install Grcov
      run: bin/install_grcov.sh

    - name: Environment
      run: bin/environment.sh

    - name: Build
      run: cargo build

    - name: Run Coverage
      run: bin/coverage_run.sh

    - name: Init git bot context
      uses: crazy-max/ghaction-import-gpg@2dc316deee8e90f13e1a351ab510b4d5bc0c82cd #v7.0.0
      with:
        gpg_private_key: ${{ secrets.HURL_BOT_GPG_PRIVATE_KEY }}
        passphrase: ${{ secrets.HURL_BOT_GPG_PRIVATE_KEY_PASSPHRASE }}
        git_committer_name: ${{ secrets.HURL_BOT_USER }}
        git_committer_email: ${{ secrets.HURL_BOT_EMAIL }}
        git_user_signingkey: true
        git_commit_gpgsign: true

    - name: Deploy GitHub Pages
      uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e #v4.0.0
      with:
        personal_token: ${{ secrets.HURL_BOT_TOKEN }}
        user_name: 'hurl-bot'
        user_email: 'bot@hurl.dev'
        publish_branch: github-pages
        publish_dir: target/coverage
        destination_dir: coverage

    - name: Archive Artifacts
      uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a #v7.0.1
      if: ${{ always() }}
      with:
        name: coverage
        path: |
          target/coverage
          *.profraw
