feat: add self-referential hashing and tighten GH workflows #41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # DO NOT EDIT - This file is generated by cigen | |
| # Source: .cigen/workflows/ | |
| # Regenerate with: cargo run -- generate --file .cigen | |
| # | |
| name: CI | |
| on: | |
| pull_request: {} | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build_cigen: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: rust:latest | |
| steps: | |
| - name: Prepare Node runtime for actions | |
| if: ${{ env.ACT == 'true' }} | |
| run: | | |
| set -e | |
| if ! command -v node >/dev/null 2>&1 || ! command -v protoc >/dev/null 2>&1; then | |
| apt-get update | |
| apt-get install -y nodejs npm protobuf-compiler | |
| fi | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Install build dependencies | |
| run: | | |
| set -e | |
| apt-get update | |
| apt-get install -y nodejs npm protobuf-compiler | |
| - uses: actions/cache@v4 | |
| with: | |
| path: | | |
| target/release | |
| key: target-release-${{ runner.os }}-${{ hashFiles('Cargo.lock') }} | |
| - name: Build cigen binary | |
| run: cargo build --release --bin cigen | |
| - name: Prepare artifact bundle | |
| run: | | |
| set -e | |
| mkdir -p .cigen/bin | |
| cp target/release/cigen .cigen/bin/cigen | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: cigen-bin | |
| path: .cigen/bin/cigen | |
| clippy: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: rust:latest | |
| needs: | |
| - build_cigen | |
| steps: | |
| - name: Prepare Node runtime for actions | |
| if: ${{ env.ACT == 'true' }} | |
| run: | | |
| set -e | |
| if ! command -v node >/dev/null 2>&1 || ! command -v protoc >/dev/null 2>&1; then | |
| apt-get update | |
| apt-get install -y nodejs npm protobuf-compiler | |
| fi | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download cigen binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: cigen-bin | |
| path: .cigen/bin | |
| - name: Prepare cigen binary | |
| run: | | |
| set -e | |
| mkdir -p .cigen/bin | |
| chmod +x .cigen/bin/cigen | |
| - name: Compute source hash | |
| id: compute_hash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p .cigen/skip-cache | |
| mkdir -p .cigen/cache | |
| ./.cigen/bin/cigen hash \ | |
| --job clippy \ | |
| --config .cigen \ | |
| --base-dir . \ | |
| --output job_hash \ | |
| --cache .cigen/cache/file-hashes.json | |
| - name: Restore skip cache | |
| id: job_skip_cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: .cigen/skip-cache/clippy | |
| key: job-skip-${ runner.os }-clippy-${ steps.compute_hash.outputs.job_hash } | |
| restore-keys: job-skip-${ runner.os }-clippy- | |
| if: ${{ env.ACT != 'true' }} | |
| - name: Skip job (cached) | |
| if: steps.job_skip_cache.outputs.cache-hit == 'true' | |
| run: echo 'Job cache hit; skipping remaining steps.' && exit 0 | |
| - name: Install clippy | |
| run: rustup component add clippy | |
| if: steps.job_skip_cache.outputs.cache-hit != 'true' | |
| - name: Clippy check | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| if: steps.job_skip_cache.outputs.cache-hit != 'true' | |
| - name: Record job completion | |
| if: success() && steps.job_skip_cache.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| HASH="${JOB_HASH}" | |
| if [ -z "$HASH" ]; then | |
| echo 'JOB_HASH missing' >&2 | |
| exit 1 | |
| fi | |
| MARKER=.cigen/skip-cache/clippy/$HASH | |
| mkdir -p "$(dirname "$MARKER")" | |
| date > "$MARKER" | |
| env: | |
| JOB_HASH: ${{ steps.compute_hash.outputs.job_hash }} | |
| fmt: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: rust:latest | |
| needs: | |
| - build_cigen | |
| steps: | |
| - name: Prepare Node runtime for actions | |
| if: ${{ env.ACT == 'true' }} | |
| run: | | |
| set -e | |
| if ! command -v node >/dev/null 2>&1 || ! command -v protoc >/dev/null 2>&1; then | |
| apt-get update | |
| apt-get install -y nodejs npm protobuf-compiler | |
| fi | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download cigen binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: cigen-bin | |
| path: .cigen/bin | |
| - name: Prepare cigen binary | |
| run: | | |
| set -e | |
| mkdir -p .cigen/bin | |
| chmod +x .cigen/bin/cigen | |
| - name: Compute source hash | |
| id: compute_hash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p .cigen/skip-cache | |
| mkdir -p .cigen/cache | |
| ./.cigen/bin/cigen hash \ | |
| --job fmt \ | |
| --config .cigen \ | |
| --base-dir . \ | |
| --output job_hash \ | |
| --cache .cigen/cache/file-hashes.json | |
| - name: Restore skip cache | |
| id: job_skip_cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: .cigen/skip-cache/fmt | |
| key: job-skip-${ runner.os }-fmt-${ steps.compute_hash.outputs.job_hash } | |
| restore-keys: job-skip-${ runner.os }-fmt- | |
| if: ${{ env.ACT != 'true' }} | |
| - name: Skip job (cached) | |
| if: steps.job_skip_cache.outputs.cache-hit == 'true' | |
| run: echo 'Job cache hit; skipping remaining steps.' && exit 0 | |
| - name: Install rustfmt | |
| run: rustup component add rustfmt | |
| if: steps.job_skip_cache.outputs.cache-hit != 'true' | |
| - name: Format check | |
| run: cargo fmt -- --check | |
| if: steps.job_skip_cache.outputs.cache-hit != 'true' | |
| - name: Record job completion | |
| if: success() && steps.job_skip_cache.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| HASH="${JOB_HASH}" | |
| if [ -z "$HASH" ]; then | |
| echo 'JOB_HASH missing' >&2 | |
| exit 1 | |
| fi | |
| MARKER=.cigen/skip-cache/fmt/$HASH | |
| mkdir -p "$(dirname "$MARKER")" | |
| date > "$MARKER" | |
| env: | |
| JOB_HASH: ${{ steps.compute_hash.outputs.job_hash }} | |
| test: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: rust:latest | |
| needs: | |
| - fmt | |
| - clippy | |
| - build_cigen | |
| steps: | |
| - name: Prepare Node runtime for actions | |
| if: ${{ env.ACT == 'true' }} | |
| run: | | |
| set -e | |
| if ! command -v node >/dev/null 2>&1 || ! command -v protoc >/dev/null 2>&1; then | |
| apt-get update | |
| apt-get install -y nodejs npm protobuf-compiler | |
| fi | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download cigen binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: cigen-bin | |
| path: .cigen/bin | |
| - name: Prepare cigen binary | |
| run: | | |
| set -e | |
| mkdir -p .cigen/bin | |
| chmod +x .cigen/bin/cigen | |
| - name: Compute source hash | |
| id: compute_hash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p .cigen/skip-cache | |
| mkdir -p .cigen/cache | |
| ./.cigen/bin/cigen hash \ | |
| --job test \ | |
| --config .cigen \ | |
| --base-dir . \ | |
| --output job_hash \ | |
| --cache .cigen/cache/file-hashes.json | |
| - name: Restore skip cache | |
| id: job_skip_cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: .cigen/skip-cache/test | |
| key: job-skip-${ runner.os }-test-${ steps.compute_hash.outputs.job_hash } | |
| restore-keys: job-skip-${ runner.os }-test- | |
| if: ${{ env.ACT != 'true' }} | |
| - name: Skip job (cached) | |
| if: steps.job_skip_cache.outputs.cache-hit == 'true' | |
| run: echo 'Job cache hit; skipping remaining steps.' && exit 0 | |
| - name: Run tests | |
| run: cargo test --all-features | |
| if: steps.job_skip_cache.outputs.cache-hit != 'true' | |
| - name: Record job completion | |
| if: success() && steps.job_skip_cache.outputs.cache-hit != 'true' | |
| run: | | |
| set -e | |
| HASH="${JOB_HASH}" | |
| if [ -z "$HASH" ]; then | |
| echo 'JOB_HASH missing' >&2 | |
| exit 1 | |
| fi | |
| MARKER=.cigen/skip-cache/test/$HASH | |
| mkdir -p "$(dirname "$MARKER")" | |
| date > "$MARKER" | |
| env: | |
| JOB_HASH: ${{ steps.compute_hash.outputs.job_hash }} |