Skip to content

Commit 9ffa6c3

Browse files
committed
Auto merge of #13317 - Urgau:improve-ci, r=<try>
Improve GitHub Actions CI config This pull request improves Cargo CI by: 1. Explicitly listing the branches the main CI should be run on (to avoid running on unwanted branches, particularly in forks) 2. By adding a [concurrency](https://docs.github.com/en/actions/using-jobs/using-concurrency) config so that only one "CI" runs for each "group" (one by PR), very inspired by rust-lang/rust [one](https://github.com/rust-lang/rust/blob/c485ee71477a29041895c47cc441b364670f3772/.github/workflows/ci.yml#L35) 3. By making all the jobs run only if triggered from this repository (to avoid having forks unnecessarily run CI jobs) 4. By making all the checkouts take `fetch-depth: 2` like done in [rust-lang/rust](https://github.com/rust-lang/rust/blob/c485ee71477a29041895c47cc441b364670f3772/.github/workflows/ci.yml#L452-L455) (to avoid unnecessary work, saves bandwidth and maybe a bit of time) The main motivation for this PR was (at first) to make the CI jobs not run on forks since it's a waste of CI resources as well as always failing (like [this](https://github.com/Urgau/cargo/actions/runs/7567435677/job/20606586124)); but after looking at the `main.yml` config I took the opportunity to improve the situation by using rust-lang/rust [ci.yml](https://github.com/rust-lang/rust/blob/master/.github/workflows/ci.yml) as reference.
2 parents c9d5cb3 + 355e88a commit 9ffa6c3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
name: CI
22
on:
33
push:
4-
branches-ignore: [master]
4+
branches:
5+
- auto-cargo
6+
- try
7+
- automation/bors/try
8+
- "rust-**"
59
pull_request:
6-
branches: ['*']
10+
branches:
11+
- "**"
712

813
defaults:
914
run:
@@ -12,6 +17,10 @@ defaults:
1217
permissions:
1318
contents: read
1419

20+
concurrency:
21+
group: "${{ github.workflow }}-${{ (github.ref == 'refs/heads/try' && github.sha) || github.ref }}"
22+
cancel-in-progress: true
23+
1524
jobs:
1625
success:
1726
permissions:
@@ -53,6 +62,7 @@ jobs:
5362
# Check Code style quickly by running `rustfmt` over all code
5463
rustfmt:
5564
runs-on: ubuntu-latest
65+
if: "github.repository == 'rust-lang/cargo'"
5666
steps:
5767
- uses: actions/checkout@v4
5868
- run: rustup update stable && rustup default stable
@@ -62,6 +72,7 @@ jobs:
6272
# Ensure there are no clippy warnings
6373
clippy:
6474
runs-on: ubuntu-latest
75+
if: "github.repository == 'rust-lang/cargo'"
6576
steps:
6677
- uses: actions/checkout@v4
6778
- run: rustup update stable && rustup default stable
@@ -78,13 +89,15 @@ jobs:
7889
# Ensure Cargo.lock is up-to-date
7990
lockfile:
8091
runs-on: ubuntu-latest
92+
if: "github.repository == 'rust-lang/cargo'"
8193
steps:
8294
- uses: actions/checkout@v4
8395
- run: rustup update stable && rustup default stable
8496
- run: cargo update -p cargo --locked
8597

8698
check-version-bump:
8799
runs-on: ubuntu-latest
100+
if: "github.repository == 'rust-lang/cargo'"
88101
env:
89102
BASE_SHA: ${{ github.event.pull_request.base.sha }}
90103
HEAD_SHA: ${{ github.event.pull_request.head.sha != '' && github.event.pull_request.head.sha || github.sha }}
@@ -108,6 +121,7 @@ jobs:
108121
CARGO_PROFILE_TEST_DEBUG: 1
109122
CARGO_INCREMENTAL: 0
110123
CARGO_PUBLIC_NETWORK_TESTS: 1
124+
if: "github.repository == 'rust-lang/cargo'"
111125
strategy:
112126
matrix:
113127
include:
@@ -191,13 +205,15 @@ jobs:
191205

192206
resolver:
193207
runs-on: ubuntu-latest
208+
if: "github.repository == 'rust-lang/cargo'"
194209
steps:
195210
- uses: actions/checkout@v4
196211
- run: rustup update stable && rustup default stable
197212
- run: cargo test -p resolver-tests
198213

199214
test_gitoxide:
200215
runs-on: ubuntu-latest
216+
if: "github.repository == 'rust-lang/cargo'"
201217
steps:
202218
- uses: actions/checkout@v4
203219
- run: rustup update --no-self-update stable && rustup default stable
@@ -210,6 +226,7 @@ jobs:
210226

211227
build_std:
212228
runs-on: ubuntu-latest
229+
if: "github.repository == 'rust-lang/cargo'"
213230
steps:
214231
- uses: actions/checkout@v4
215232
- run: rustup update nightly && rustup default nightly
@@ -220,6 +237,7 @@ jobs:
220237
CARGO_RUN_BUILD_STD_TESTS: 1
221238
docs:
222239
runs-on: ubuntu-latest
240+
if: "github.repository == 'rust-lang/cargo'"
223241
steps:
224242
- uses: actions/checkout@v4
225243
- run: rustup update nightly && rustup default nightly
@@ -247,6 +265,7 @@ jobs:
247265
248266
msrv:
249267
runs-on: ubuntu-latest
268+
if: "github.repository == 'rust-lang/cargo'"
250269
steps:
251270
- uses: actions/checkout@v4
252271
- uses: taiki-e/install-action@cargo-hack

0 commit comments

Comments
 (0)