---
# inspiration:
# - [Tips for Faster Rust CI Builds | corrode Rust Consulting](https://corrode.dev/blog/tips-for-faster-ci-builds/)
name: ci

on:
  push:
    branches-ignore:
      - "release-plz-*"
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  ci:
    # "ubuntu-22.04-arm" vs "ubuntu-latest"
    # - faster? (not sure 10min for both with cold cache, and 4min (+1min) for arm on 90% cache'hit)
    # - fewer available => longer "queued times"
    runs-on: "ubuntu-latest"
    env:
      CARGO_TERM_COLOR: always
      # to help debug on failure (maybe conflict with disable of test debug)
      RUST_BACKTRACE: full
      # reduce size of target (good for caching)
      CARGO_PROFILE_TEST_DEBUG: 0
      # disable incremental compilation faster from-scratch builds & sccache
      CARGO_INCREMENTAL: 0
      # configure sccache to cache the build artifacts (on github caches)
      SCCACHE_GHA_ENABLED: "true"
      RUSTC_WRAPPER: "sccache"
    steps:
      - uses: actions/checkout@v7
      - uses: mozilla-actions/sccache-action@v0.0.9
      - uses: jdx/mise-action@v4
        with:
          # version 2025.5.11, a symlink is created for rust setup
          # without cache, missing components are installed
          # with cache, nothing is installed, but as rust tool is symlinked, it is not cached => missing components failure
          cache: false
          cache_save: false
          experimental: true
      - name: install cdviz-collector
        run: |
          curl --proto '=https' --tlsv1.2 -LsSf \
            https://github.com/cdviz-dev/cdviz-collector/releases/latest/download/cdviz-collector-installer.sh \
            | sh
        shell: bash
      - name: run CI and report test results
        run: |
          cdviz-collector send --run testsuiterun_junit \
            --data "target/nextest/default/junit.xml" \
            --metadata "suite_name=/cdviz-collector/ci" \
            --metadata "tested_artifact_id=pkg:oci/cdviz-collector" \
            --url "${CDVIZ_COLLECTOR_URL}" \
            -- mise run --jobs 1 ci
          # --log-full-response-on-error \
        shell: bash
        env:
          CDVIZ_COLLECTOR_URL: ${{ secrets.CDVIZ_COLLECTOR_URL }}
          CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X-SIGNATURE__TYPE: "signature"
          CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X-SIGNATURE__TOKEN: ${{ secrets.CDVIZ_COLLECTOR_TOKEN }}
          CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X-SIGNATURE__SIGNATURE_PREFIX: "sha256="
          CDVIZ_COLLECTOR__SINKS__HTTP__HEADERS__X-SIGNATURE__SIGNATURE_ENCODING: "hex"
