Implement Rust version of log-lazy #2
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
| name: Rust | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| types: [opened, synchronize, reopened] | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: ${{ github.ref == 'refs/heads/main' }} | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUSTFLAGS: -Dwarnings | |
| RUST_ROOT: rust | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN || secrets.CARGO_TOKEN }} | |
| CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }} | |
| jobs: | |
| detect-changes: | |
| name: Detect Changes | |
| runs-on: ubuntu-latest | |
| outputs: | |
| rs-changed: ${{ steps.changes.outputs.rs-changed }} | |
| toml-changed: ${{ steps.changes.outputs.toml-changed }} | |
| docs-changed: ${{ steps.changes.outputs.docs-changed }} | |
| workflow-changed: ${{ steps.changes.outputs.workflow-changed }} | |
| any-code-changed: ${{ steps.changes.outputs.any-code-changed }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install rust-script | |
| run: cargo install rust-script | |
| - name: Detect Rust changes | |
| id: changes | |
| env: | |
| GITHUB_EVENT_NAME: ${{ github.event_name }} | |
| GITHUB_BASE_SHA: ${{ github.event.pull_request.base.sha || '' }} | |
| GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha || '' }} | |
| run: rust-script scripts/detect-rust-changes.rs | |
| version-check: | |
| name: Check Crate Version | |
| runs-on: ubuntu-latest | |
| needs: [detect-changes] | |
| if: | | |
| github.event_name == 'push' || | |
| github.event_name == 'workflow_dispatch' || | |
| needs.detect-changes.outputs.rs-changed == 'true' || | |
| needs.detect-changes.outputs.toml-changed == 'true' || | |
| needs.detect-changes.outputs.workflow-changed == 'true' | |
| outputs: | |
| should-publish: ${{ steps.check.outputs.should-publish }} | |
| version: ${{ steps.check.outputs.version }} | |
| crate-name: ${{ steps.check.outputs.crate-name }} | |
| crates-io-version: ${{ steps.check.outputs.crates-io-version }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install rust-script | |
| run: cargo install rust-script | |
| - name: Check crate version | |
| id: check | |
| env: | |
| GITHUB_EVENT_NAME: ${{ github.event_name }} | |
| GITHUB_REF: ${{ github.ref }} | |
| run: rust-script scripts/check-crate-version.rs | |
| check-file-size: | |
| name: Check File Line Limits | |
| runs-on: ubuntu-latest | |
| needs: [detect-changes] | |
| if: | | |
| github.event_name == 'push' || | |
| github.event_name == 'workflow_dispatch' || | |
| needs.detect-changes.outputs.rs-changed == 'true' || | |
| needs.detect-changes.outputs.toml-changed == 'true' || | |
| needs.detect-changes.outputs.docs-changed == 'true' || | |
| needs.detect-changes.outputs.workflow-changed == 'true' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Simulate fresh merge with base branch | |
| if: github.event_name == 'pull_request' | |
| env: | |
| BASE_REF: ${{ github.base_ref }} | |
| run: bash scripts/simulate-fresh-merge.sh | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install rust-script | |
| run: cargo install rust-script | |
| - name: Check file size limit | |
| run: rust-script scripts/check-file-size.rs | |
| lint: | |
| name: Lint and Format Check | |
| runs-on: ubuntu-latest | |
| needs: [detect-changes, check-file-size] | |
| if: | | |
| !cancelled() && | |
| (github.event_name == 'push' || | |
| github.event_name == 'workflow_dispatch' || | |
| needs.detect-changes.outputs.rs-changed == 'true' || | |
| needs.detect-changes.outputs.toml-changed == 'true' || | |
| needs.detect-changes.outputs.docs-changed == 'true' || | |
| needs.detect-changes.outputs.workflow-changed == 'true') && | |
| (needs.check-file-size.result == 'success' || needs.check-file-size.result == 'skipped') | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Simulate fresh merge with base branch | |
| if: github.event_name == 'pull_request' | |
| env: | |
| BASE_REF: ${{ github.base_ref }} | |
| run: bash scripts/simulate-fresh-merge.sh | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - name: Cache cargo registry | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| rust/target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock', 'Cargo.toml', 'rust/Cargo.toml') }} | |
| restore-keys: ${{ runner.os }}-cargo- | |
| - name: Check formatting | |
| working-directory: rust | |
| run: cargo fmt --all -- --check | |
| - name: Run Clippy | |
| working-directory: rust | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| test: | |
| name: Test (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| needs: [detect-changes, lint, check-file-size] | |
| if: | | |
| !cancelled() && | |
| (github.event_name == 'push' || | |
| github.event_name == 'workflow_dispatch' || | |
| needs.detect-changes.outputs.rs-changed == 'true' || | |
| needs.detect-changes.outputs.toml-changed == 'true' || | |
| needs.detect-changes.outputs.workflow-changed == 'true') && | |
| needs.lint.result == 'success' && | |
| (needs.check-file-size.result == 'success' || needs.check-file-size.result == 'skipped') | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Simulate fresh merge with base branch | |
| if: github.event_name == 'pull_request' | |
| env: | |
| BASE_REF: ${{ github.base_ref }} | |
| shell: bash | |
| run: bash scripts/simulate-fresh-merge.sh | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo registry | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| rust/target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock', 'Cargo.toml', 'rust/Cargo.toml') }} | |
| restore-keys: ${{ runner.os }}-cargo- | |
| - name: Run tests | |
| working-directory: rust | |
| run: cargo test --all-features --verbose | |
| - name: Run doc tests | |
| working-directory: rust | |
| run: cargo test --doc --verbose | |
| coverage: | |
| name: Code Coverage | |
| runs-on: ubuntu-latest | |
| needs: [detect-changes, lint] | |
| if: | | |
| !cancelled() && | |
| (github.event_name == 'push' || | |
| github.event_name == 'workflow_dispatch' || | |
| needs.detect-changes.outputs.rs-changed == 'true' || | |
| needs.detect-changes.outputs.toml-changed == 'true') && | |
| needs.lint.result == 'success' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: llvm-tools-preview | |
| - name: Cache cargo registry | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| rust/target | |
| key: ${{ runner.os }}-cargo-coverage-${{ hashFiles('Cargo.lock', 'Cargo.toml', 'rust/Cargo.toml') }} | |
| restore-keys: ${{ runner.os }}-cargo-coverage- | |
| - name: Install cargo-llvm-cov | |
| uses: taiki-e/install-action@cargo-llvm-cov | |
| - name: Generate code coverage | |
| working-directory: rust | |
| run: cargo llvm-cov --all-features --lcov --output-path lcov.info | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| files: rust/lcov.info | |
| fail_ci_if_error: false | |
| build: | |
| name: Build Package | |
| runs-on: ubuntu-latest | |
| needs: [lint, test] | |
| if: | | |
| !cancelled() && | |
| needs.lint.result == 'success' && | |
| needs.test.result == 'success' | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo registry | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| rust/target | |
| key: ${{ runner.os }}-cargo-build-${{ hashFiles('Cargo.lock', 'Cargo.toml', 'rust/Cargo.toml') }} | |
| restore-keys: ${{ runner.os }}-cargo-build- | |
| - name: Build release | |
| working-directory: rust | |
| run: cargo build --release --verbose | |
| - name: Check package contents | |
| working-directory: rust | |
| run: cargo package --list --allow-dirty | |
| publish: | |
| name: Publish Crate | |
| runs-on: ubuntu-latest | |
| needs: [version-check, lint, test, build] | |
| if: | | |
| !cancelled() && | |
| github.event_name == 'push' && | |
| github.ref == 'refs/heads/main' && | |
| needs.version-check.outputs.should-publish == 'true' && | |
| needs.lint.result == 'success' && | |
| needs.test.result == 'success' && | |
| needs.build.result == 'success' | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install rust-script | |
| run: cargo install rust-script | |
| - name: Publish to Crates.io | |
| id: publish | |
| run: rust-script scripts/publish-crate.rs | |
| - name: Create GitHub release | |
| if: steps.publish.outputs.publish_result == 'success' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| rust-script scripts/create-rust-github-release.rs \ | |
| --release-version "${{ needs.version-check.outputs.version }}" \ | |
| --crate-name "${{ needs.version-check.outputs.crate-name }}" \ | |
| --repository "${{ github.repository }}" | |
| summary: | |
| name: Summary | |
| runs-on: ubuntu-latest | |
| needs: | |
| [ | |
| detect-changes, | |
| version-check, | |
| check-file-size, | |
| lint, | |
| test, | |
| coverage, | |
| build, | |
| publish, | |
| ] | |
| if: always() | |
| steps: | |
| - name: Workflow summary | |
| run: | | |
| echo "## Rust Workflow Summary" | |
| echo "- Event: ${{ github.event_name }}" | |
| echo "- Ref: ${{ github.ref_name }}" | |
| echo "- Rust sources changed: ${{ needs.detect-changes.outputs.rs-changed }}" | |
| echo "- Cargo files changed: ${{ needs.detect-changes.outputs.toml-changed }}" | |
| echo "- Docs changed: ${{ needs.detect-changes.outputs.docs-changed }}" | |
| echo "- Workflow changed: ${{ needs.detect-changes.outputs.workflow-changed }}" | |
| echo "- Version check: ${{ needs.version-check.result }}" | |
| echo "- File limits: ${{ needs.check-file-size.result }}" | |
| echo "- Lint: ${{ needs.lint.result }}" | |
| echo "- Test: ${{ needs.test.result }}" | |
| echo "- Coverage: ${{ needs.coverage.result }}" | |
| echo "- Build: ${{ needs.build.result }}" | |
| echo "- Publish: ${{ needs.publish.result }}" |