From 0b9aae421fe44af1ababe19b90e093e33d2dbefb Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Mon, 27 Jul 2026 13:13:53 +0200 Subject: [PATCH] CI: Run Rust tests on GhA We start with a decision taks right from the get go: We will run specific tasks only when the corresponding files have changed. That will speed up CI significantly. E.g. typo fixes in docs or Python-only files won't trigger a full Kotlin run, nor does it trigger a Rust rebuild. With this first change however we only migrate the Rust tests, those only happen when *.rs files or Cargo files change --- .github/rust.json | 44 ++++++++++++++++ .github/workflows/crate-ci.sh | 13 ++++- .github/workflows/test.yml | 96 +++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 .github/rust.json create mode 100644 .github/workflows/test.yml diff --git a/.github/rust.json b/.github/rust.json new file mode 100644 index 0000000000..4793344dbe --- /dev/null +++ b/.github/rust.json @@ -0,0 +1,44 @@ +{ + "problemMatcher": [ + { + "owner": "cargo-common", + "pattern": [ + { + "regexp": "^(warning|warn|error)(\\[(\\S*)\\])?: (.*)$", + "severity": 1, + "message": 4, + "code": 3 + }, + { + "regexp": "^\\s+-->\\s(\\S+):(\\d+):(\\d+)$", + "file": 1, + "line": 2, + "column": 3 + } + ] + }, + { + "owner": "cargo-test", + "pattern": [ + { + "regexp": "^\\s+thread\\s+'(.*?)'.+panicked\\s+at\\s+([^:]+):(\\d+):(\\d+):$", + "message": 1, + "file": 2, + "line": 3, + "column": 4 + } + ] + }, + { + "owner": "cargo-fmt", + "pattern": [ + { + "regexp": "^(Diff in ([^:]+):(\\d+)):$", + "message": 1, + "file": 1, + "line": 2 + } + ] + } + ] +} diff --git a/.github/workflows/crate-ci.sh b/.github/workflows/crate-ci.sh index 72125da0b8..cd64a6d3e2 100755 --- a/.github/workflows/crate-ci.sh +++ b/.github/workflows/crate-ci.sh @@ -21,6 +21,7 @@ Options: -f, --force Force overwriting an existing binary --crate NAME Name of the crate to install (default ) --tag TAG Tag (version) of the crate to install (default ) + --filename Filename (instead of $crate-$tag-$target.tar.gz). --target TARGET Install the release compiled for $TARGET (default <`rustc` host>) --to LOCATION Where to install the binary (default ~/.cargo/bin) EOF @@ -71,6 +72,10 @@ while test $# -gt 0; do tag=$2 shift ;; + --filename) + filename=$2 + shift + ;; --target) target=$2 shift @@ -148,7 +153,13 @@ fi say_err "Installing to: $dest" -url="$url/download/$tag/$crate-$tag-$target.tar.gz" +if [ -z "$filename" ]; then + filename="$crate-$tag-$target.tar.gz" +fi + +url="$url/download/$tag/$filename" + +say_err "URL: $url" td=$(mktemp -d || mktemp -d -t tmp) curl -sL "$url" | tar xz -f - -C "$td" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..021ecec9d3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,96 @@ +name: Test + +on: + push: + branches: + - main + pull_request: + types: + - opened + - synchronize + +# Drop all default GITHUB_TOKEN permissions; each job declares its own least-privilege set. +permissions: {} + +env: + MSRV: '1.90' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + decide-runs: + name: Decision task + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + rust-changed: ${{ steps.set-flags.outputs.rust-changed }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + filter: blob:none + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha || github.sha }} + - id: changed-files-rust + uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6 + with: + files: | + **/Cargo.toml + **/Cargo.lock + **/*.rs + base_sha: ${{ github.event.pull_request.base.sha || github.event.before }} + - name: Decide which jobs to run + id: set-flags + env: + RUST_CHANGED: ${{ steps.changed-files-rust.outputs.any_changed }} + run: | + echo "rust-changed=$RUST_CHANGED" >> $GITHUB_OUTPUT + + test-rust: + runs-on: ubuntu-latest + needs: [decide-runs] + if: needs.decide-runs.outputs.rust-changed == 'true' + strategy: + fail-fast: false + matrix: + rust-version: ["stable", "1.90"] + steps: + - &checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + filter: blob:none + ref: ${{ github.event.pull_request.head.sha || github.sha }} + + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.rust-version }} + + - name: Install nextest + run: | + .github/workflows/crate-ci.sh \ + --git nextest-rs/nextest \ + --crate nextest \ + --tag "cargo-nextest-0.9.143" \ + --filename "cargo-nextest-0.9.143-x86_64-unknown-linux-gnu.tar.gz" + + - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1 + + - name: Install deps + run: | + sudo apt update + sudo apt install --yes --no-install-recommends \ + faketime + + - name: Test + run: | + export RUST_BACKTRACE=1 + export RUST_LOG=glean_core=debug + export CARGO_INCREMENTAL=0 + + echo "::add-matcher::.github/rust.json" + make test-rust