Skip to content

Commit 9313c6f

Browse files
committed
chore(ci): determine if it is a backport by listing branches
1 parent a085f16 commit 9313c6f

File tree

3 files changed

+101
-101
lines changed

3 files changed

+101
-101
lines changed

.github/workflows/main.yml

Lines changed: 34 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,33 @@ jobs:
5555
# Only check cargo lib for now
5656
- run: cargo clippy -p cargo --lib -- -D warnings
5757

58+
# Generate strategy matrix for different platforms and channels
59+
# (see ci/matrix.json)
60+
matrix:
61+
runs-on: ubuntu-latest
62+
needs:
63+
- channel
64+
outputs:
65+
matrix: ${{ steps.matrix.outputs.matrix }}
66+
steps:
67+
- uses: actions/checkout@v3
68+
- name: Generate strategy matrix
69+
id: matrix
70+
run: |
71+
CHANNEL=${{ needs.channel.outputs.CHANNEL }}
72+
MATRIX=$(
73+
jq --arg C "$CHANNEL" 'map (. |
74+
if ($C == "beta") then select(.rust | startswith("nightly") | not)
75+
elif ($C == "stable") then select(.rust | startswith("stable"))
76+
else . end)' ci/matrix.json
77+
)
78+
echo "$MATRIX"
79+
echo "MATRIX={\"include\":$(echo $MATRIX)}" >> "$GITHUB_OUTPUT"
80+
5881
test:
5982
runs-on: ${{ matrix.os }}
6083
needs:
61-
- channel
84+
- matrix
6285
env:
6386
CARGO_PROFILE_DEV_DEBUG: 1
6487
CARGO_PROFILE_TEST_DEBUG: 1
@@ -67,112 +90,58 @@ jobs:
6790
# Deny warnings on CI to avoid warnings getting into the codebase.
6891
RUSTFLAGS: -D warnings
6992
strategy:
70-
matrix:
71-
include:
72-
- name: Linux x86_64 stable
73-
os: ubuntu-latest
74-
rust: stable
75-
other: i686-unknown-linux-gnu
76-
if: always()
77-
- name: Linux x86_64 beta
78-
os: ubuntu-latest
79-
rust: beta
80-
other: i686-unknown-linux-gnu
81-
if: ${{ needs.channel.outputs.CHANNEL == 'beta' || needs.channel.outputs.CHANNEL == 'nightly' }}
82-
- name: Linux x86_64 nightly
83-
os: ubuntu-latest
84-
rust: nightly
85-
other: i686-unknown-linux-gnu
86-
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
87-
- name: macOS x86_64 stable
88-
os: macos-latest
89-
rust: stable
90-
other: x86_64-apple-ios
91-
if: always()
92-
- name: macOS x86_64 nightly
93-
os: macos-latest
94-
rust: nightly
95-
other: x86_64-apple-ios
96-
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
97-
- name: Windows x86_64 MSVC stable
98-
os: windows-latest
99-
rust: stable-msvc
100-
other: i686-pc-windows-msvc
101-
if: always()
102-
- name: Windows x86_64 gnu nightly # runs out of space while trying to link the test suite
103-
os: windows-latest
104-
rust: nightly-gnu
105-
other: i686-pc-windows-gnu
106-
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
93+
matrix: ${{ fromJSON(needs.matrix.outputs.MATRIX) }}
10794
name: Tests ${{ matrix.name }}
10895
steps:
10996
- uses: actions/checkout@v3
110-
if: matrix.if
11197
- name: Dump Environment
11298
run: ci/dump-environment.sh
113-
if: matrix.if
11499
- name: Update Rustup (temporary workaround)
115100
run: rustup self update
116101
shell: bash
117-
if: matrix.if && startsWith(matrix.os, 'windows')
102+
if: startsWith(matrix.os, 'windows')
118103
- run: rustup update --no-self-update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
119-
if: matrix.if
120104
- run: rustup target add ${{ matrix.other }}
121-
if: matrix.if
122105
- run: rustup component add rustc-dev llvm-tools-preview rust-docs
123-
if: matrix.if && startsWith(matrix.rust, 'nightly')
106+
if: startsWith(matrix.rust, 'nightly')
124107
- run: sudo apt update -y && sudo apt install gcc-multilib libsecret-1-0 libsecret-1-dev -y
125-
if: matrix.if && matrix.os == 'ubuntu-latest'
108+
if: matrix.os == 'ubuntu-latest'
126109
- run: rustup component add rustfmt || echo "rustfmt not available"
127-
if: matrix.if
128110
- name: Configure extra test environment
129111
run: echo CARGO_CONTAINER_TESTS=1 >> $GITHUB_ENV
130-
if: matrix.if && matrix.os == 'ubuntu-latest'
112+
if: matrix.os == 'ubuntu-latest'
131113
- run: cargo test
132-
if: matrix.if
133114
- name: Clear intermediate test output
134115
run: ci/clean-test-output.sh
135-
if: matrix.if
136116
- name: gitoxide tests (all git-related tests)
137117
run: cargo test git
138118
env:
139119
__CARGO_USE_GITOXIDE_INSTEAD_OF_GIT2: 1
140-
if: matrix.if
141120
# The testsuite generates a huge amount of data, and fetch-smoke-test was
142121
# running out of disk space.
143122
- name: Clear test output
144123
run: ci/clean-test-output.sh
145-
if: matrix.if
146124
- name: Check operability of rustc invocation with argfile
147125
env:
148126
__CARGO_TEST_FORCE_ARGFILE: 1
149127
run: |
150128
# This only tests `cargo fix` because fix-proxy-mode is one of the most
151129
# complicated subprocess management in Cargo.
152130
cargo test --test testsuite -- fix::
153-
if: matrix.if
154131
- run: cargo test --manifest-path crates/cargo-test-support/Cargo.toml
155132
env:
156133
CARGO_TARGET_DIR: target
157-
if: matrix.if
158-
- run: cargo test -p cargo-test-support
159-
if: matrix.if
160134
- run: cargo test -p cargo-platform
161-
if: matrix.if
162135
- run: cargo test -p cargo-util
163-
if: matrix.if
164136
- run: cargo test --manifest-path crates/home/Cargo.toml
165-
if: matrix.if
166137
- run: cargo test --manifest-path crates/mdman/Cargo.toml
167-
if: matrix.if
168138
- run: cargo build --manifest-path crates/credential/cargo-credential-1password/Cargo.toml
169-
if: matrix.if
170139
- run: cargo build --manifest-path crates/credential/cargo-credential-gnome-secret/Cargo.toml
171-
if: matrix.if && matrix.os == 'ubuntu-latest'
140+
if: matrix.os == 'ubuntu-latest'
172141
- run: cargo build --manifest-path crates/credential/cargo-credential-macos-keychain/Cargo.toml
173-
if: matrix.if && matrix.os == 'macos-latest'
142+
if: matrix.os == 'macos-latest'
174143
- run: cargo build --manifest-path crates/credential/cargo-credential-wincred/Cargo.toml
175-
if: matrix.if && matrix.os == 'windows-latest'
144+
if: matrix.os == 'windows-latest'
176145
- name: Check benchmarks
177146
env:
178147
# Share the target dir to try to cache a few build-time deps.
@@ -182,15 +151,12 @@ jobs:
182151
# download all workspaces.
183152
cargo test --manifest-path benches/benchsuite/Cargo.toml --all-targets -- cargo
184153
cargo check --manifest-path benches/capture/Cargo.toml
185-
if: matrix.if
186154
# The testsuite generates a huge amount of data, and fetch-smoke-test was
187155
# running out of disk space.
188156
- name: Clear benchmark output
189157
run: ci/clean-test-output.sh
190-
if: matrix.if
191158
- name: Fetch smoke test
192159
run: ci/fetch-smoke-test.sh
193-
if: matrix.if
194160

195161
resolver:
196162
runs-on: ubuntu-latest
@@ -215,7 +181,7 @@ jobs:
215181
runs-on: ubuntu-latest
216182
needs:
217183
- channel
218-
if: ${{ needs.channel.outputs.CHANNEL == 'nightly' }}
184+
if: ${{ needs.channel.outputs.CHANNEL == 'master' }}
219185
steps:
220186
- uses: actions/checkout@v3
221187
- run: rustup update nightly && rustup default nightly
@@ -230,15 +196,6 @@ jobs:
230196
- channel
231197
steps:
232198
- 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"
242199
- run: rustup update nightly && rustup default nightly
243200
- run: rustup update stable
244201
- run: rustup component add rust-docs
@@ -255,7 +212,7 @@ jobs:
255212
- run: cd src/doc && mdbook build --dest-dir ../../target/doc
256213
- name: Run linkchecker.sh
257214
run: |
258-
BRANCH=${{ steps.branch.outputs.BRANCH }}
215+
BRANCH=${{ needs.channel.outputs.CHANNEL }}
259216
cd src/doc
260217
curl -sSLo linkcheck.sh \
261218
"https://raw.githubusercontent.com/rust-lang/rust/$BRANCH/src/tools/linkchecker/linkcheck.sh"

ci/matrix.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"name": "Linux x86_64 stable",
4+
"os": "ubuntu-latest",
5+
"rust": "stable",
6+
"other": "i686-unknown-linux-gnu"
7+
},
8+
{
9+
"name": "Linux x86_64 beta",
10+
"os": "ubuntu-latest",
11+
"rust": "beta",
12+
"other": "i686-unknown-linux-gnu"
13+
},
14+
{
15+
"name": "Linux x86_64 nightly",
16+
"os": "ubuntu-latest",
17+
"rust": "nightly",
18+
"other": "i686-unknown-linux-gnu"
19+
},
20+
{
21+
"name": "macOS x86_64 stable",
22+
"os": "macos-latest",
23+
"rust": "stable",
24+
"other": "x86_64-apple-ios"
25+
},
26+
{
27+
"name": "macOS x86_64 nightly",
28+
"os": "macos-latest",
29+
"rust": "nightly",
30+
"other": "x86_64-apple-ios"
31+
},
32+
{
33+
"name": "Windows x86_64 MSVC stable",
34+
"os": "windows-latest",
35+
"rust": "stable-msvc",
36+
"other": "i686-pc-windows-msvc"
37+
},
38+
{
39+
"name": "Windows x86_64 gnu nightly",
40+
"os": "windows-latest",
41+
"rust": "nightly-gnu",
42+
"other": "i686-pc-windows-gnu"
43+
}
44+
]

ci/which-channel.sh

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,35 @@ set -euo pipefail
1313
# so hope `HEAD~` to find the previous commit on master branch.
1414
base_sha=$(git rev-parse "${BASE_SHA:-HEAD~1}")
1515

16-
# Default to nightly channel
17-
CHANNEL="nightly"
18-
1916
# 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)
17+
# Assumption: Cargo branches are always in the format of `rust-1.*.0`,
18+
# otherwise `git name-rev` will return "undefined".
19+
ref=$(git name-rev --name-only --refs='origin/rust-1.*.0' $base_sha)
2220

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)"
21+
# Get the latest `rust-1.*.0` branch from remote origin.
22+
# Assumption: The latest branch is always beta branch.
23+
beta=$(git branch --remotes --list 'origin/rust-1.*.0' | sort | tail -n1 | tr -d "[:space:]")
3224

33-
if [[ "$beta" == "rustc ${version}"* ]]
34-
then
35-
CHANNEL="beta"
36-
fi
25+
master=$(git rev-parse origin/master)
3726

38-
if [[ "$stable" = "rustc ${version}"* ]]
27+
# Backport pull requests always target at a `rust-1.*.0` branch.
28+
if [[ "$ref" = "undefined" ]] || [[ "$base_sha" = "$master" ]]
29+
then
30+
# Should be nightly but for convenience in CI let's call it master.
31+
channel="master"
32+
else
33+
if [[ "$ref" = "$beta" ]]
3934
then
40-
CHANNEL="stable"
35+
channel="beta"
36+
else
37+
channel="stable"
4138
fi
4239
fi
4340

44-
echo "Base sha: $base_sha"
45-
echo "Possible ref: $ref"
46-
echo "Channel: $CHANNEL"
41+
echo "Base sha: $base_sha"
42+
echo "Git Ref: $ref"
43+
echo "master: $master"
44+
echo "beta: $beta"
45+
echo "Channel: $channel"
4746

48-
echo "CHANNEL=$CHANNEL" >> "$GITHUB_OUTPUT"
47+
echo "CHANNEL=$channel" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)