From 9313c6f73088e86f1bc8208a961a6ccaa9bba977 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 25 May 2023 22:02:29 +0100 Subject: [PATCH] chore(ci): determine if it is a backport by listing branches --- .github/workflows/main.yml | 111 ++++++++++++------------------------- ci/matrix.json | 44 +++++++++++++++ ci/which-channel.sh | 47 ++++++++-------- 3 files changed, 101 insertions(+), 101 deletions(-) create mode 100644 ci/matrix.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9213705d85c1..40c33ed1ec83 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,10 +55,33 @@ jobs: # Only check cargo lib for now - run: cargo clippy -p cargo --lib -- -D warnings + # Generate strategy matrix for different platforms and channels + # (see ci/matrix.json) + matrix: + runs-on: ubuntu-latest + needs: + - channel + outputs: + matrix: ${{ steps.matrix.outputs.matrix }} + steps: + - uses: actions/checkout@v3 + - name: Generate strategy matrix + id: matrix + run: | + CHANNEL=${{ needs.channel.outputs.CHANNEL }} + MATRIX=$( + jq --arg C "$CHANNEL" 'map (. | + if ($C == "beta") then select(.rust | startswith("nightly") | not) + elif ($C == "stable") then select(.rust | startswith("stable")) + else . end)' ci/matrix.json + ) + echo "$MATRIX" + echo "MATRIX={\"include\":$(echo $MATRIX)}" >> "$GITHUB_OUTPUT" + test: runs-on: ${{ matrix.os }} needs: - - channel + - matrix env: CARGO_PROFILE_DEV_DEBUG: 1 CARGO_PROFILE_TEST_DEBUG: 1 @@ -67,82 +90,37 @@ jobs: # Deny warnings on CI to avoid warnings getting into the codebase. RUSTFLAGS: -D warnings strategy: - matrix: - include: - - name: Linux x86_64 stable - os: ubuntu-latest - rust: stable - other: i686-unknown-linux-gnu - if: always() - - name: Linux x86_64 beta - os: ubuntu-latest - rust: beta - other: i686-unknown-linux-gnu - if: ${{ needs.channel.outputs.CHANNEL == 'beta' || needs.channel.outputs.CHANNEL == 'nightly' }} - - name: Linux x86_64 nightly - os: ubuntu-latest - rust: nightly - other: i686-unknown-linux-gnu - if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }} - - name: macOS x86_64 stable - os: macos-latest - rust: stable - other: x86_64-apple-ios - if: always() - - name: macOS x86_64 nightly - os: macos-latest - rust: nightly - other: x86_64-apple-ios - if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }} - - name: Windows x86_64 MSVC stable - os: windows-latest - rust: stable-msvc - other: i686-pc-windows-msvc - if: always() - - name: Windows x86_64 gnu nightly # runs out of space while trying to link the test suite - os: windows-latest - rust: nightly-gnu - other: i686-pc-windows-gnu - if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }} + matrix: ${{ fromJSON(needs.matrix.outputs.MATRIX) }} name: Tests ${{ matrix.name }} steps: - uses: actions/checkout@v3 - if: matrix.if - name: Dump Environment run: ci/dump-environment.sh - if: matrix.if - name: Update Rustup (temporary workaround) run: rustup self update shell: bash - if: matrix.if && startsWith(matrix.os, 'windows') + if: startsWith(matrix.os, 'windows') - run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }} - if: matrix.if - run: rustup target add ${{ matrix.other }} - if: matrix.if - run: rustup component add rustc-dev llvm-tools-preview rust-docs - if: matrix.if && startsWith(matrix.rust, 'nightly') + if: startsWith(matrix.rust, 'nightly') - run: sudo apt update -y && sudo apt install gcc-multilib libsecret-1-0 libsecret-1-dev -y - if: matrix.if && matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-latest' - run: rustup component add rustfmt || echo "rustfmt not available" - if: matrix.if - name: Configure extra test environment run: echo CARGO_CONTAINER_TESTS=1 >> $GITHUB_ENV - if: matrix.if && matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-latest' - run: cargo test - if: matrix.if - name: Clear intermediate test output run: ci/clean-test-output.sh - if: matrix.if - name: gitoxide tests (all git-related tests) run: cargo test git env: __CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2: 1 - if: matrix.if # The testsuite generates a huge amount of data, and fetch-smoke-test was # running out of disk space. - name: Clear test output run: ci/clean-test-output.sh - if: matrix.if - name: Check operability of rustc invocation with argfile env: __CARGO_TEST_FORCE_ARGFILE: 1 @@ -150,29 +128,20 @@ jobs: # This only tests `cargo fix` because fix-proxy-mode is one of the most # complicated subprocess management in Cargo. cargo test --test testsuite -- fix:: - if: matrix.if - run: cargo test --manifest-path crates/cargo-test-support/Cargo.toml env: CARGO_TARGET_DIR: target - if: matrix.if - - run: cargo test -p cargo-test-support - if: matrix.if - run: cargo test -p cargo-platform - if: matrix.if - run: cargo test -p cargo-util - if: matrix.if - run: cargo test --manifest-path crates/home/Cargo.toml - if: matrix.if - run: cargo test --manifest-path crates/mdman/Cargo.toml - if: matrix.if - run: cargo build --manifest-path crates/credential/cargo-credential-1password/Cargo.toml - if: matrix.if - run: cargo build --manifest-path crates/credential/cargo-credential-gnome-secret/Cargo.toml - if: matrix.if && matrix.os == 'ubuntu-latest' + if: matrix.os == 'ubuntu-latest' - run: cargo build --manifest-path crates/credential/cargo-credential-macos-keychain/Cargo.toml - if: matrix.if && matrix.os == 'macos-latest' + if: matrix.os == 'macos-latest' - run: cargo build --manifest-path crates/credential/cargo-credential-wincred/Cargo.toml - if: matrix.if && matrix.os == 'windows-latest' + if: matrix.os == 'windows-latest' - name: Check benchmarks env: # Share the target dir to try to cache a few build-time deps. @@ -182,15 +151,12 @@ jobs: # download all workspaces. cargo test --manifest-path benches/benchsuite/Cargo.toml --all-targets -- cargo cargo check --manifest-path benches/capture/Cargo.toml - if: matrix.if # The testsuite generates a huge amount of data, and fetch-smoke-test was # running out of disk space. - name: Clear benchmark output run: ci/clean-test-output.sh - if: matrix.if - name: Fetch smoke test run: ci/fetch-smoke-test.sh - if: matrix.if resolver: runs-on: ubuntu-latest @@ -215,7 +181,7 @@ jobs: runs-on: ubuntu-latest needs: - channel - if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }} + if: ${{ needs.channel.outputs.CHANNEL == 'master' }} steps: - uses: actions/checkout@v3 - run: rustup update nightly && rustup default nightly @@ -230,15 +196,6 @@ jobs: - channel steps: - uses: actions/checkout@v3 - - name: Set branch for rustc linkchecker - id: branch - run: | - BRANCH=${{ needs.channel.outputs.CHANNEL }} - if [ "$BRANCH" = "nightly" ] - then - BRANCH=master - fi - echo "BRANCH=$BRANCH" >> "$GITHUB_OUTPUT" - run: rustup update nightly && rustup default nightly - run: rustup update stable - run: rustup component add rust-docs @@ -255,7 +212,7 @@ jobs: - run: cd src/doc && mdbook build --dest-dir ../../target/doc - name: Run linkchecker.sh run: | - BRANCH=${{ steps.branch.outputs.BRANCH }} + BRANCH=${{ needs.channel.outputs.CHANNEL }} cd src/doc curl -sSLo linkcheck.sh \ "https://github.com/raw/rust-lang/rust/$BRANCH/src/tools/linkchecker/linkcheck.sh" diff --git a/ci/matrix.json b/ci/matrix.json new file mode 100644 index 000000000000..f325caefd123 --- /dev/null +++ b/ci/matrix.json @@ -0,0 +1,44 @@ +[ + { + "name": "Linux x86_64 stable", + "os": "ubuntu-latest", + "rust": "stable", + "other": "i686-unknown-linux-gnu" + }, + { + "name": "Linux x86_64 beta", + "os": "ubuntu-latest", + "rust": "beta", + "other": "i686-unknown-linux-gnu" + }, + { + "name": "Linux x86_64 nightly", + "os": "ubuntu-latest", + "rust": "nightly", + "other": "i686-unknown-linux-gnu" + }, + { + "name": "macOS x86_64 stable", + "os": "macos-latest", + "rust": "stable", + "other": "x86_64-apple-ios" + }, + { + "name": "macOS x86_64 nightly", + "os": "macos-latest", + "rust": "nightly", + "other": "x86_64-apple-ios" + }, + { + "name": "Windows x86_64 MSVC stable", + "os": "windows-latest", + "rust": "stable-msvc", + "other": "i686-pc-windows-msvc" + }, + { + "name": "Windows x86_64 gnu nightly", + "os": "windows-latest", + "rust": "nightly-gnu", + "other": "i686-pc-windows-gnu" + } +] diff --git a/ci/which-channel.sh b/ci/which-channel.sh index d4376dacee4f..0a063e0abae0 100755 --- a/ci/which-channel.sh +++ b/ci/which-channel.sh @@ -13,36 +13,35 @@ set -euo pipefail # so hope `HEAD~` to find the previous commit on master branch. base_sha=$(git rev-parse "${BASE_SHA:-HEAD~1}") -# Default to nightly channel -CHANNEL="nightly" - # Get symbolic names for the base_sha. -# We only care about `rust-1.y.z` branches -ref=$(git name-rev --name-only --refs="origin/rust-1.*" $base_sha) +# Assumption: Cargo branches are always in the format of `rust-1.*.0`, +# otherwise `git name-rev` will return "undefined". +ref=$(git name-rev --name-only --refs='origin/rust-1.*.0' $base_sha) -# Remove the patch version `.0` and keep only `1.y`, -# so that rustup can install the correct patched toolchain -if [[ "$ref" =~ ^origin/rust-(.*).0$ ]] -then - rustup update - rustup toolchain install stable beta - version="${BASH_REMATCH[1]}" - beta="$(rustc +beta -V)" - stable="$(rustc +stable -V)" +# Get the latest `rust-1.*.0` branch from remote origin. +# Assumption: The latest branch is always beta branch. +beta=$(git branch --remotes --list 'origin/rust-1.*.0' | sort | tail -n1 | tr -d "[:space:]") - if [[ "$beta" == "rustc ${version}"* ]] - then - CHANNEL="beta" - fi +master=$(git rev-parse origin/master) - if [[ "$stable" = "rustc ${version}"* ]] +# Backport pull requests always target at a `rust-1.*.0` branch. +if [[ "$ref" = "undefined" ]] || [[ "$base_sha" = "$master" ]] +then + # Should be nightly but for convenience in CI let's call it master. + channel="master" +else + if [[ "$ref" = "$beta" ]] then - CHANNEL="stable" + channel="beta" + else + channel="stable" fi fi -echo "Base sha: $base_sha" -echo "Possible ref: $ref" -echo "Channel: $CHANNEL" +echo "Base sha: $base_sha" +echo "Git Ref: $ref" +echo "master: $master" +echo "beta: $beta" +echo "Channel: $channel" -echo "CHANNEL=$CHANNEL" >> "$GITHUB_OUTPUT" +echo "CHANNEL=$channel" >> "$GITHUB_OUTPUT"