Skip to content

Commit b5a3df8

Browse files
committed
#116 refactor: deduplicate MSRV reading with setup job
1 parent b3f46ee commit b5a3df8

File tree

1 file changed

+44
-83
lines changed

1 file changed

+44
-83
lines changed

.github/workflows/reusable-ci.yml

Lines changed: 44 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@ on:
88
default: true
99

1010
jobs:
11+
# 🔧 Setup
12+
setup:
13+
name: Setup
14+
runs-on: ubuntu-latest
15+
outputs:
16+
msrv: ${{ steps.msrv.outputs.msrv }}
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- name: Read MSRV from Cargo.toml
21+
id: msrv
22+
shell: bash
23+
run: |
24+
set -euo pipefail
25+
if ! command -v jq >/dev/null 2>&1; then
26+
sudo apt-get update -y && sudo apt-get install -y jq
27+
fi
28+
RV=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].rust_version // empty')
29+
if [ -z "$RV" ]; then
30+
echo "rust-version is not set in Cargo.toml"
31+
exit 1
32+
fi
33+
[[ "$RV" =~ ^[0-9]+\.[0-9]+$ ]] && RV="${RV}.0"
34+
echo "msrv=${RV}" >> "$GITHUB_OUTPUT"
35+
echo "Using MSRV: $RV"
36+
1137
# 📋 Code Quality Checks
1238
code-quality:
1339
name: Code Quality
@@ -35,33 +61,17 @@ jobs:
3561
clippy:
3662
name: Clippy (MSRV)
3763
runs-on: ubuntu-latest
64+
needs: setup
3865
env:
3966
CARGO_LOCKED: "true"
4067
CARGO_TERM_COLOR: always
4168
steps:
4269
- uses: actions/checkout@v5
4370

44-
- name: Read MSRV from Cargo.toml
45-
id: msrv
46-
shell: bash
47-
run: |
48-
set -euo pipefail
49-
if ! command -v jq >/dev/null 2>&1; then
50-
sudo apt-get update -y && sudo apt-get install -y jq
51-
fi
52-
RV=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].rust_version // empty')
53-
if [ -z "$RV" ]; then
54-
echo "rust-version is not set in Cargo.toml"
55-
exit 1
56-
fi
57-
[[ "$RV" =~ ^[0-9]+\.[0-9]+$ ]] && RV="${RV}.0"
58-
echo "msrv=${RV}" >> "$GITHUB_OUTPUT"
59-
echo "Using MSRV: $RV"
60-
61-
- name: Install Rust (${{ steps.msrv.outputs.msrv }})
71+
- name: Install Rust (${{ needs.setup.outputs.msrv }})
6272
uses: dtolnay/rust-toolchain@v1
6373
with:
64-
toolchain: ${{ steps.msrv.outputs.msrv }}
74+
toolchain: ${{ needs.setup.outputs.msrv }}
6575
components: clippy
6676

6777
- name: Cache cargo
@@ -75,42 +85,26 @@ jobs:
7585
run: |
7686
set -euo pipefail
7787
if [ "${{ inputs.all-features }}" = "true" ]; then
78-
cargo +${{ steps.msrv.outputs.msrv }} clippy --workspace --all-targets --all-features -- -D warnings
88+
cargo +${{ needs.setup.outputs.msrv }} clippy --workspace --all-targets --all-features -- -D warnings
7989
else
80-
cargo +${{ steps.msrv.outputs.msrv }} clippy --workspace --all-targets -- -D warnings
90+
cargo +${{ needs.setup.outputs.msrv }} clippy --workspace --all-targets -- -D warnings
8191
fi
8292
8393
# 🧪 Tests
8494
test:
8595
name: Tests (MSRV)
8696
runs-on: ubuntu-latest
97+
needs: setup
8798
env:
8899
CARGO_LOCKED: "true"
89100
CARGO_TERM_COLOR: always
90101
steps:
91102
- uses: actions/checkout@v5
92103

93-
- name: Read MSRV from Cargo.toml
94-
id: msrv
95-
shell: bash
96-
run: |
97-
set -euo pipefail
98-
if ! command -v jq >/dev/null 2>&1; then
99-
sudo apt-get update -y && sudo apt-get install -y jq
100-
fi
101-
RV=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].rust_version // empty')
102-
if [ -z "$RV" ]; then
103-
echo "rust-version is not set in Cargo.toml"
104-
exit 1
105-
fi
106-
[[ "$RV" =~ ^[0-9]+\.[0-9]+$ ]] && RV="${RV}.0"
107-
echo "msrv=${RV}" >> "$GITHUB_OUTPUT"
108-
echo "Using MSRV: $RV"
109-
110-
- name: Install Rust (${{ steps.msrv.outputs.msrv }})
104+
- name: Install Rust (${{ needs.setup.outputs.msrv }})
111105
uses: dtolnay/rust-toolchain@v1
112106
with:
113-
toolchain: ${{ steps.msrv.outputs.msrv }}
107+
toolchain: ${{ needs.setup.outputs.msrv }}
114108

115109
- name: Cache cargo
116110
uses: Swatinem/rust-cache@v2
@@ -137,9 +131,9 @@ jobs:
137131
run: |
138132
set -euo pipefail
139133
if [ "${{ inputs.all-features }}" = "true" ]; then
140-
cargo +${{ steps.msrv.outputs.msrv }} nextest run --workspace --all-features --no-fail-fast --profile ci
134+
cargo +${{ needs.setup.outputs.msrv }} nextest run --workspace --all-features --no-fail-fast --profile ci
141135
else
142-
cargo +${{ steps.msrv.outputs.msrv }} nextest run --workspace --no-fail-fast --profile ci
136+
cargo +${{ needs.setup.outputs.msrv }} nextest run --workspace --no-fail-fast --profile ci
143137
fi
144138
145139
- name: Upload test results to Codecov
@@ -152,34 +146,17 @@ jobs:
152146
build:
153147
name: Build & Package
154148
runs-on: ubuntu-latest
155-
needs: [code-quality, clippy, test]
149+
needs: [setup, code-quality, clippy, test]
156150
env:
157151
CARGO_LOCKED: "true"
158152
CARGO_TERM_COLOR: always
159153
steps:
160154
- uses: actions/checkout@v5
161155

162-
- name: Read MSRV from Cargo.toml
163-
id: msrv
164-
shell: bash
165-
run: |
166-
set -euo pipefail
167-
if ! command -v jq >/dev/null 2>&1; then
168-
sudo apt-get update -y && sudo apt-get install -y jq
169-
fi
170-
RV=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].rust_version // empty')
171-
if [ -z "$RV" ]; then
172-
echo "rust-version is not set in Cargo.toml"
173-
exit 1
174-
fi
175-
[[ "$RV" =~ ^[0-9]+\.[0-9]+$ ]] && RV="${RV}.0"
176-
echo "msrv=${RV}" >> "$GITHUB_OUTPUT"
177-
echo "Using MSRV: $RV"
178-
179-
- name: Install Rust (${{ steps.msrv.outputs.msrv }})
156+
- name: Install Rust (${{ needs.setup.outputs.msrv }})
180157
uses: dtolnay/rust-toolchain@v1
181158
with:
182-
toolchain: ${{ steps.msrv.outputs.msrv }}
159+
toolchain: ${{ needs.setup.outputs.msrv }}
183160

184161
- name: Cache cargo
185162
uses: Swatinem/rust-cache@v2
@@ -207,36 +184,20 @@ jobs:
207184
fi
208185
209186
- name: Package (dry-run)
210-
run: cargo +${{ steps.msrv.outputs.msrv }} package --locked
187+
run: cargo +${{ needs.setup.outputs.msrv }} package --locked
211188

212189
# 📊 Coverage
213190
coverage:
214191
name: Coverage
215192
runs-on: ubuntu-latest
193+
needs: setup
216194
steps:
217195
- uses: actions/checkout@v5
218196

219-
- name: Read MSRV from Cargo.toml
220-
id: msrv
221-
shell: bash
222-
run: |
223-
set -euo pipefail
224-
if ! command -v jq >/dev/null 2>&1; then
225-
sudo apt-get update -y && sudo apt-get install -y jq
226-
fi
227-
RV=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].rust_version // empty')
228-
if [ -z "$RV" ]; then
229-
echo "rust-version is not set in Cargo.toml"
230-
exit 1
231-
fi
232-
[[ "$RV" =~ ^[0-9]+\.[0-9]+$ ]] && RV="${RV}.0"
233-
echo "msrv=${RV}" >> "$GITHUB_OUTPUT"
234-
echo "Using MSRV: $RV"
235-
236-
- name: Install Rust (${{ steps.msrv.outputs.msrv }})
197+
- name: Install Rust (${{ needs.setup.outputs.msrv }})
237198
uses: dtolnay/rust-toolchain@v1
238199
with:
239-
toolchain: ${{ steps.msrv.outputs.msrv }}
200+
toolchain: ${{ needs.setup.outputs.msrv }}
240201
components: llvm-tools-preview
241202

242203
- name: Cache cargo
@@ -254,7 +215,7 @@ jobs:
254215
shell: bash
255216
run: |
256217
set -euo pipefail
257-
cargo +${{ steps.msrv.outputs.msrv }} llvm-cov --all-features --workspace --lcov --output-path lcov.info
218+
cargo +${{ needs.setup.outputs.msrv }} llvm-cov --all-features --workspace --lcov --output-path lcov.info
258219
259220
- name: Upload coverage to Codecov
260221
uses: codecov/codecov-action@v5

0 commit comments

Comments
 (0)