Skip to content

Commit 32bae81

Browse files
committed
chore: detect the channel a PR wants to merge into
1 parent ec8a8a0 commit 32bae81

File tree

2 files changed

+118
-12
lines changed

2 files changed

+118
-12
lines changed

.github/workflows/main.yml

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ env:
1616
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
1717

1818
jobs:
19+
# Determine which channel will be merged into.
20+
channel:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
CHANNEL: ${{ steps.channel.outputs.CHANNEL }}
24+
env:
25+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
26+
steps:
27+
- uses: actions/checkout@v3
28+
with:
29+
fetch-depth: 0 # fetch all branches
30+
- id: channel
31+
run: ci/which-channel.sh
32+
1933
# Check Code style quickly by running `rustfmt` over all code
2034
rustfmt:
2135
runs-on: ubuntu-latest
@@ -43,6 +57,8 @@ jobs:
4357

4458
test:
4559
runs-on: ${{ matrix.os }}
60+
needs:
61+
- channel
4662
env:
4763
CARGO_PROFILE_DEV_DEBUG: 1
4864
CARGO_PROFILE_TEST_DEBUG: 1
@@ -57,82 +73,106 @@ jobs:
5773
os: ubuntu-latest
5874
rust: stable
5975
other: i686-unknown-linux-gnu
76+
if: always()
6077
- name: Linux x86_64 beta
6178
os: ubuntu-latest
6279
rust: beta
6380
other: i686-unknown-linux-gnu
81+
if: ${{ needs.channel.outputs.CHANNEL == 'beta' || needs.channel.outputs.CHANNEL == 'nightly' }}
6482
- name: Linux x86_64 nightly
6583
os: ubuntu-latest
6684
rust: nightly
6785
other: i686-unknown-linux-gnu
86+
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
6887
- name: macOS x86_64 stable
6988
os: macos-latest
7089
rust: stable
7190
other: x86_64-apple-ios
91+
if: always()
7292
- name: macOS x86_64 nightly
7393
os: macos-latest
7494
rust: nightly
7595
other: x86_64-apple-ios
96+
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
7697
- name: Windows x86_64 MSVC stable
7798
os: windows-latest
7899
rust: stable-msvc
79100
other: i686-pc-windows-msvc
101+
if: always()
80102
- name: Windows x86_64 gnu nightly # runs out of space while trying to link the test suite
81103
os: windows-latest
82104
rust: nightly-gnu
83105
other: i686-pc-windows-gnu
106+
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
84107
name: Tests ${{ matrix.name }}
85108
steps:
86109
- uses: actions/checkout@v3
110+
if: matrix.if
87111
- name: Dump Environment
88112
run: ci/dump-environment.sh
113+
if: matrix.if
89114
- name: Update Rustup (temporary workaround)
90115
run: rustup self update
91116
shell: bash
92-
if: startsWith(matrix.os, 'windows')
117+
if: matrix.if && startsWith(matrix.os, 'windows')
93118
- run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
119+
if: matrix.if
94120
- run: rustup target add ${{ matrix.other }}
121+
if: matrix.if
95122
- run: rustup component add rustc-dev llvm-tools-preview rust-docs
96-
if: startsWith(matrix.rust, 'nightly')
123+
if: matrix.if && startsWith(matrix.rust, 'nightly')
97124
- run: sudo apt update -y && sudo apt install gcc-multilib libsecret-1-0 libsecret-1-dev -y
98-
if: matrix.os == 'ubuntu-latest'
125+
if: matrix.if && matrix.os == 'ubuntu-latest'
99126
- run: rustup component add rustfmt || echo "rustfmt not available"
127+
if: matrix.if
100128
- name: Configure extra test environment
101129
run: echo CARGO_CONTAINER_TESTS=1 >> $GITHUB_ENV
102-
if: matrix.os == 'ubuntu-latest'
103-
130+
if: matrix.if && matrix.os == 'ubuntu-latest'
104131
- run: cargo test
132+
if: matrix.if
105133
- name: Clear intermediate test output
106134
run: ci/clean-test-output.sh
135+
if: matrix.if
107136
- name: gitoxide tests (all git-related tests)
108137
run: cargo test git
109138
env:
110139
__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2: 1
140+
if: matrix.if
111141
# The testsuite generates a huge amount of data, and fetch-smoke-test was
112142
# running out of disk space.
113143
- name: Clear test output
114144
run: ci/clean-test-output.sh
145+
if: matrix.if
115146
- name: Check operability of rustc invocation with argfile
116147
env:
117148
__CARGO_TEST_FORCE_ARGFILE: 1
118149
run: |
119150
# This only tests `cargo fix` because fix-proxy-mode is one of the most
120151
# complicated subprocess management in Cargo.
121152
cargo test --test testsuite -- fix::
153+
if: matrix.if
122154
- run: cargo test --manifest-path crates/cargo-test-support/Cargo.toml
123155
env:
124156
CARGO_TARGET_DIR: target
157+
if: matrix.if
158+
- run: cargo test -p cargo-test-support
159+
if: matrix.if
125160
- run: cargo test -p cargo-platform
161+
if: matrix.if
126162
- run: cargo test -p cargo-util
163+
if: matrix.if
127164
- run: cargo test --manifest-path crates/home/Cargo.toml
165+
if: matrix.if
128166
- run: cargo test --manifest-path crates/mdman/Cargo.toml
167+
if: matrix.if
129168
- run: cargo build --manifest-path crates/credential/cargo-credential-1password/Cargo.toml
169+
if: matrix.if
130170
- run: cargo build --manifest-path crates/credential/cargo-credential-gnome-secret/Cargo.toml
131-
if: matrix.os == 'ubuntu-latest'
171+
if: matrix.if && matrix.os == 'ubuntu-latest'
132172
- run: cargo build --manifest-path crates/credential/cargo-credential-macos-keychain/Cargo.toml
133-
if: matrix.os == 'macos-latest'
173+
if: matrix.if && matrix.os == 'macos-latest'
134174
- run: cargo build --manifest-path crates/credential/cargo-credential-wincred/Cargo.toml
135-
if: matrix.os == 'windows-latest'
175+
if: matrix.if && matrix.os == 'windows-latest'
136176
- name: Check benchmarks
137177
env:
138178
# Share the target dir to try to cache a few build-time deps.
@@ -142,12 +182,15 @@ jobs:
142182
# download all workspaces.
143183
cargo test --manifest-path benches/benchsuite/Cargo.toml --all-targets -- cargo
144184
cargo check --manifest-path benches/capture/Cargo.toml
185+
if: matrix.if
145186
# The testsuite generates a huge amount of data, and fetch-smoke-test was
146187
# running out of disk space.
147188
- name: Clear benchmark output
148189
run: ci/clean-test-output.sh
190+
if: matrix.if
149191
- name: Fetch smoke test
150192
run: ci/fetch-smoke-test.sh
193+
if: matrix.if
151194

152195
resolver:
153196
runs-on: ubuntu-latest
@@ -170,6 +213,9 @@ jobs:
170213

171214
build_std:
172215
runs-on: ubuntu-latest
216+
needs:
217+
- channel
218+
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
173219
steps:
174220
- uses: actions/checkout@v3
175221
- run: rustup update nightly && rustup default nightly
@@ -180,8 +226,19 @@ jobs:
180226
CARGO_RUN_BUILD_STD_TESTS: 1
181227
docs:
182228
runs-on: ubuntu-latest
229+
needs:
230+
- channel
183231
steps:
184232
- uses: actions/checkout@v3
233+
- name: Set branch for rustc linkchecker
234+
id: branch
235+
run: |
236+
BRANCH=${{ needs.channel.outputs.CHANNEL }}
237+
if [ "$BRANCH" = "nightly" ]
238+
then
239+
BRANCH=master
240+
fi
241+
echo "BRANCH=$BRANCH" >> "$GITHUB_OUTPUT"
185242
- run: rustup update nightly && rustup default nightly
186243
- run: rustup update stable
187244
- run: rustup component add rust-docs
@@ -196,10 +253,11 @@ jobs:
196253
env:
197254
RUSTDOCFLAGS: -D warnings
198255
- run: cd src/doc && mdbook build --dest-dir ../../target/doc
199-
- run: |
200-
cd src/doc
201-
curl -sSLo linkcheck.sh \
202-
https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
256+
- name: Run linkchecker.sh
257+
run: |
258+
BRANCH=${{ steps.branch.outputs.BRANCH }}
259+
cd target
260+
curl -sSLO "https://raw.githubusercontent.com/rust-lang/rust/$BRANCH/src/tools/linkchecker/linkcheck.sh"
203261
sh linkcheck.sh --all cargo
204262
205263
success:

ci/which-channel.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# This script outputs the channel where a CI workflow wants to merge into.
3+
#
4+
# Inputs:
5+
# BASE_SHA The commit SHA of the branch where the PR wants to merge into.
6+
#
7+
# GitHub Action Outputs:
8+
# CHANNEL Target channel where the PR wants to merge into.
9+
10+
set -euo pipefail
11+
12+
# When `BASE_SHA` is missing, we assume it is from bors merge commit,
13+
# so hope `HEAD~` to find the previous commit on master branch.
14+
base_sha=$(git rev-parse "${BASE_SHA:-HEAD~1}")
15+
16+
# Default to nightly channel
17+
CHANNEL="nightly"
18+
19+
# Get symbolic names for the base_sha.
20+
# We only care about `rust-1.y.z` branches
21+
ref=$(git name-rev --name-only --refs="origin/rust-1.*" $base_sha)
22+
23+
# Remove the patch version `.0` and keep only `1.y`,
24+
# so that rustup can install the correct patched toolchain
25+
if [[ "$ref" =~ ^origin/rust-(.*).0$ ]]
26+
then
27+
rustup update
28+
rustup toolchain install stable beta
29+
version="${BASH_REMATCH[1]}"
30+
beta="$(rustc +beta -V)"
31+
stable="$(rustc +stable -V)"
32+
33+
if [[ "$beta" == "rustc ${version}"* ]]
34+
then
35+
CHANNEL="beta"
36+
fi
37+
38+
if [[ "$stable" = "rustc ${version}"* ]]
39+
then
40+
CHANNEL="stable"
41+
fi
42+
fi
43+
44+
echo "Base sha: $base_sha"
45+
echo "Possible ref: $ref"
46+
echo "Channel: $CHANNEL"
47+
48+
echo "CHANNEL=$CHANNEL" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)