Skip to content

Commit

Permalink
chore: detect the channel a PR wants to merge into
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed May 25, 2023
1 parent ec8a8a0 commit a085f16
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 10 deletions.
79 changes: 69 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
# Determine which channel will be merged into.
channel:
runs-on: ubuntu-latest
outputs:
CHANNEL: ${{ steps.channel.outputs.CHANNEL }}
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all branches
- id: channel
run: ci/which-channel.sh

# Check Code style quickly by running `rustfmt` over all code
rustfmt:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -43,6 +57,8 @@ jobs:

test:
runs-on: ${{ matrix.os }}
needs:
- channel
env:
CARGO_PROFILE_DEV_DEBUG: 1
CARGO_PROFILE_TEST_DEBUG: 1
Expand All @@ -57,82 +73,106 @@ jobs:
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' }}
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: startsWith(matrix.os, 'windows')
if: matrix.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: startsWith(matrix.rust, 'nightly')
if: matrix.if && startsWith(matrix.rust, 'nightly')
- run: sudo apt update -y && sudo apt install gcc-multilib libsecret-1-0 libsecret-1-dev -y
if: matrix.os == 'ubuntu-latest'
if: matrix.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.os == 'ubuntu-latest'

if: matrix.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
run: |
# 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.os == 'ubuntu-latest'
if: matrix.if && matrix.os == 'ubuntu-latest'
- run: cargo build --manifest-path crates/credential/cargo-credential-macos-keychain/Cargo.toml
if: matrix.os == 'macos-latest'
if: matrix.if && matrix.os == 'macos-latest'
- run: cargo build --manifest-path crates/credential/cargo-credential-wincred/Cargo.toml
if: matrix.os == 'windows-latest'
if: matrix.if && matrix.os == 'windows-latest'
- name: Check benchmarks
env:
# Share the target dir to try to cache a few build-time deps.
Expand All @@ -142,12 +182,15 @@ 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
Expand All @@ -170,6 +213,9 @@ jobs:

build_std:
runs-on: ubuntu-latest
needs:
- channel
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
steps:
- uses: actions/checkout@v3
- run: rustup update nightly && rustup default nightly
Expand All @@ -180,8 +226,19 @@ jobs:
CARGO_RUN_BUILD_STD_TESTS: 1
docs:
runs-on: ubuntu-latest
needs:
- 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
Expand All @@ -196,10 +253,12 @@ jobs:
env:
RUSTDOCFLAGS: -D warnings
- run: cd src/doc && mdbook build --dest-dir ../../target/doc
- run: |
- name: Run linkchecker.sh
run: |
BRANCH=${{ steps.branch.outputs.BRANCH }}
cd src/doc
curl -sSLo linkcheck.sh \
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
"https://raw.githubusercontent.com/rust-lang/rust/$BRANCH/src/tools/linkchecker/linkcheck.sh"
sh linkcheck.sh --all cargo
success:
Expand Down
48 changes: 48 additions & 0 deletions ci/which-channel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# This script outputs the channel where a CI workflow wants to merge into.
#
# Inputs:
# BASE_SHA The commit SHA of the branch where the PR wants to merge into.
#
# GitHub Action Outputs:
# CHANNEL Target channel where the PR wants to merge into.

set -euo pipefail

# When `BASE_SHA` is missing, we assume it is from bors merge commit,
# 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)

# 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)"

if [[ "$beta" == "rustc ${version}"* ]]
then
CHANNEL="beta"
fi

if [[ "$stable" = "rustc ${version}"* ]]
then
CHANNEL="stable"
fi
fi

echo "Base sha: $base_sha"
echo "Possible ref: $ref"
echo "Channel: $CHANNEL"

echo "CHANNEL=$CHANNEL" >> "$GITHUB_OUTPUT"

0 comments on commit a085f16

Please sign in to comment.