From b0bfe4573f6fc02531b7717e7ece4481777c9273 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Thu, 12 Nov 2026 06:46:10 +0800 Subject: [PATCH] CI: reusable workflows, hardening --- .github/workflows/ci.yml | 79 ++++++++++++++++------------------- .github/workflows/lint.yml | 24 +++++++++++ .github/workflows/reports.yml | 72 +++++++++++++++++++++---------- renovate.json | 4 ++ rust-toolchain.toml | 2 + 5 files changed, 116 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 renovate.json create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b34aaf3..bda73d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,59 +6,54 @@ on: pull_request: branches: ["main"] +permissions: + contents: read + +# A newer push to the same pull request supersedes this run; a branch's runs +# queue instead. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + env: CARGO_TERM_COLOR: always jobs: - test: - name: Test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - # The external-generator tests build their fixture generators for - # wasm32-wasip1 (tests/cli/external.rs). - targets: wasm32-wasip1 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose - - # The same build and tests on the other platforms (core#9): paths, line - # endings and executable lookup are where they're expected to differ. - test_cross_platform: - name: Test (${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - windows-latest - - macos-latest - - ubuntu-24.04-arm - steps: - - uses: actions/checkout@v7 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - targets: wasm32-wasip1 - - uses: Swatinem/rust-cache@v2 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + # The toolchain matrix (stable, beta, nightly), the same build and tests on + # the other platforms (core#9: paths, line endings and executable lookup are + # where they're expected to differ), and a stable canary on ubuntu-26.04 that + # may fail without failing the run. The reusable workflow's own jobs set the + # runner, the timeouts and the pinned actions. + rust: + name: rust + permissions: + contents: read + uses: ComlineProject/.github/.github/workflows/rust-ci.yml@797d473553d7f2fc50895bb2573acb83ac63c7cb # main, no release tag yet + with: + # The external-generator tests build their fixture generators for + # wasm32-wasip1 (tests/cli/external.rs). + targets: wasm32-wasip1 + # Stays a local job: the CI images have neither rustfmt nor clippy, which + # the reusable workflow doesn't run either. Pinned to the toolchain + # `rust-toolchain.toml` names. lint: name: Lint - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 30 steps: - - uses: actions/checkout@v4 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install Rust - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 with: + toolchain: 1.99.1 components: rustfmt, clippy + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - name: rustfmt run: cargo fmt --check - name: clippy diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..398fc15 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +# Not `lint-...`: the reusable workflow's own group is that, and groups are +# case-insensitive, so the same name would make the call wait on itself. +concurrency: + group: ci-lint-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + lint: + name: lint + permissions: + contents: read + uses: ComlineProject/.github/.github/workflows/lint.yml@797d473553d7f2fc50895bb2573acb83ac63c7cb # main, no release tag yet + with: + renovate-config: renovate.json diff --git a/.github/workflows/reports.yml b/.github/workflows/reports.yml index b77983a..8dee447 100644 --- a/.github/workflows/reports.yml +++ b/.github/workflows/reports.yml @@ -19,8 +19,8 @@ permissions: contents: read concurrency: - group: reports-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: CARGO_TERM_COLOR: always @@ -28,25 +28,32 @@ env: jobs: size: name: size - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 45 steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@stable + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: 1.99.1 targets: wasm32-wasip1 - - uses: Swatinem/rust-cache@v2 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 - id: rustc run: echo "version=$(rustc --version)" >> "$GITHUB_OUTPUT" - name: Build run: | cargo build --locked --release - - uses: ComlineProject/observatory/.github/actions/report-size@v1 + - uses: ComlineProject/observatory/.github/actions/report-size@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: output: reports/cli.size.json toolchain: ${{ steps.rustc.outputs.version }} artifacts: | cli/x86_64-linux-release=target/release/comline - - uses: actions/upload-artifact@v7 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: report-size path: reports/cli.size.json @@ -54,18 +61,25 @@ jobs: coverage: name: coverage - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 45 steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@stable + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 with: + toolchain: 1.99.1 targets: wasm32-wasip1 - - uses: Swatinem/rust-cache@v2 - - uses: ComlineProject/observatory/.github/actions/report-rust-coverage@v1 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - uses: ComlineProject/observatory/.github/actions/report-rust-coverage@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: output: reports/cli.coverage.json args: --workspace - - uses: actions/upload-artifact@v7 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: report-coverage path: reports/cli.coverage.json @@ -73,17 +87,24 @@ jobs: compile: name: compile time - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 45 steps: - - uses: actions/checkout@v7 - - uses: dtolnay/rust-toolchain@stable + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: + egress-policy: audit + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # v1 + with: + toolchain: 1.99.1 targets: wasm32-wasip1 - - uses: ComlineProject/observatory/.github/actions/report-rust-compile@v1 + - uses: ComlineProject/observatory/.github/actions/report-rust-compile@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: output: reports/cli.compile.json args: --workspace --release - - uses: actions/upload-artifact@v7 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: report-compile path: reports/cli.compile.json @@ -93,19 +114,24 @@ jobs: name: publish needs: [size, coverage, compile] if: github.event_name != 'pull_request' - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 15 permissions: contents: write steps: - - uses: actions/checkout@v7 + - uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + # The one checkout that keeps its credentials: publish-report pushes. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - - uses: actions/download-artifact@v8 + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: pattern: report-* path: reports merge-multiple: true - - uses: ComlineProject/observatory/.github/actions/publish-report@v1 + - uses: ComlineProject/observatory/.github/actions/publish-report@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: reports: reports/cli.size.json reports/cli.coverage.json reports/cli.compile.json readme: .github/reports-branch.md diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..f8b00a1 --- /dev/null +++ b/renovate.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["github>ComlineProject/.github:renovate-config"] +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..246cb22 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.99.1"