From 4cd4acb5f6b5256f89f5a7f71cf7483387f0ce08 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Thu, 12 Nov 2026 06:45:45 +0800 Subject: [PATCH] CI: reusable workflows, CI images, hardening --- .github/workflows/build_test.yml | 59 ++++++++++++++++---------------- .github/workflows/lint.yml | 24 +++++++++++++ .github/workflows/reports.yml | 33 ++++++++++++------ renovate.json | 4 +++ rust-toolchain.toml | 2 ++ 5 files changed, 82 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 renovate.json create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index a27d76c..ea28ef1 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -4,44 +4,45 @@ on: push: pull_request: +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: - build_and_test: - name: Rust project - stable - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: rustup update stable && rustup default stable - - run: cargo build --verbose - - run: cargo test --verbose - - # The same build and test on the other platforms (core#9). The Linux x86_64 - # job above keeps its name; these are additional checks. - test: - 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 - - run: rustup update stable && rustup default stable - - uses: Swatinem/rust-cache@v2 - - run: cargo build --verbose - - run: cargo test --verbose + # The toolchain matrix (stable, beta, nightly), the same build and tests on + # the other platforms (core#9: paths and line endings 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 # `comline-codegen` takes core's IR only, with no parser, so it (and so a - # generator binary) builds for WASI and the browser. + # generator binary) builds for WASI and the browser. In the wasm CI image + # (stable 1.99.1, which `rust-toolchain.toml` pins, and both wasm targets). wasm: name: comline-codegen - wasm - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 20 + container: ghcr.io/comlineproject/ci-wasm@sha256:badd6af13cee6c459c9284de8ef0ef4a1667ed7e35582f87d1afb08f3c30fd8f + defaults: + run: + shell: bash steps: - - uses: actions/checkout@v4 - - run: rustup update stable && rustup default stable - - run: rustup target add wasm32-wasip1 wasm32-unknown-unknown + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - run: cargo build --verbose -p comline-codegen --target wasm32-wasip1 - run: cargo build --verbose -p comline-codegen --target wasm32-unknown-unknown # The Markdown renderer as a WASI module, which the CLI can run under diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..96917d5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +name: Lint + +on: + push: + branches: [master] + 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 c79a0d3..113fbab 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,15 +28,21 @@ env: jobs: coverage: name: coverage - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 + timeout-minutes: 45 steps: - - uses: actions/checkout@v7 - - uses: Swatinem/rust-cache@v2 - - uses: ComlineProject/observatory/.github/actions/report-rust-coverage@v1 + - 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: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + - uses: ComlineProject/observatory/.github/actions/report-rust-coverage@8d21b1fbe68f8b639676153ce1a308eaafdcc6a7 # v1 with: output: reports/generation.coverage.json args: --workspace - - uses: actions/upload-artifact@v7 + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: report-coverage path: reports/generation.coverage.json @@ -46,19 +52,24 @@ jobs: name: publish needs: [coverage] 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/generation.coverage.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"