Skip to content

Commit 1d01e47

Browse files
authored
Refactor CI workflows (#3414)
This improves the ergonomics of the CI workflows and cuts down on CI runtime by adding a new `check` job for feature flags which only need to be tested using `cargo check` rather than `cargo test`. I removed the dedicated `nightly` job by including it in the `test` job. Also added `temp_cache` to the list of features to check; for some reason it wasn't included in CI before.
1 parent 8a7a817 commit 1d01e47

File tree

3 files changed

+51
-75
lines changed

3 files changed

+51
-75
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,27 @@ jobs:
1717
name:
1818
- stable
1919
- beta
20-
# The build matrix doesn't support the `env` variable in expressions
21-
# see: jobs.nightly
22-
# - nightly
20+
- nightly
2321
- Windows
22+
- macOS
2423
- native-tls
2524
- no default features
2625
- no cache
2726
- no gateway
28-
- unstable Discord API features
27+
- chrono
2928
- zlib compression
3029
- zstd compression
3130
- zlib and zstd compression
3231

3332
include:
3433
- name: beta
3534
toolchain: beta
35+
- name: nightly
36+
toolchain: nightly
3637
- name: Windows
3738
os: windows-latest
39+
- name: macOS
40+
os: macos-latest
3841
- name: native-tls
3942
features: default_native_tls
4043
- name: no default features
@@ -45,15 +48,6 @@ jobs:
4548
features: model rustls_backend
4649
- name: chrono
4750
features: chrono
48-
- name: unstable API + typesize
49-
features: default unstable typesize
50-
dont-test: true
51-
- name: builder without model
52-
features: builder
53-
dont-test: true
54-
- name: unstable Discord API (no default features)
55-
features: unstable
56-
dont-test: true
5751
- name: zlib compression
5852
features: default transport_compression_zlib
5953
- name: zstd compression
@@ -68,60 +62,46 @@ jobs:
6862
- name: Install toolchain
6963
uses: dtolnay/rust-toolchain@master
7064
with:
71-
toolchain: ${{ matrix.toolchain || 'stable' }}
65+
toolchain: ${{
66+
(matrix.toolchain == 'nightly' && env.rust_nightly)
67+
|| matrix.toolchain
68+
|| 'stable'
69+
}}
7270

7371
- name: Add problem matchers
74-
shell: bash
7572
run: echo "::add-matcher::.github/matchers/rust.json"
7673

7774
- name: Cache
7875
uses: Swatinem/rust-cache@v2
7976

80-
- name: Build all features
81-
if: matrix.features == ''
82-
run: cargo build --features full
83-
84-
- name: Test all features
85-
if: matrix.features == ''
86-
run: cargo test --features full
77+
- name: Run tests
78+
run: cargo test --no-default-features --features "${{ matrix.features || 'full' }}"
8779

88-
- name: Build some features
89-
if: matrix.features
90-
run: cargo build --no-default-features --features "${{ matrix.features }}"
91-
92-
- name: Test some features
93-
if: ${{ !matrix.dont-test && matrix.features }}
94-
run: cargo test --no-default-features --features "${{ matrix.features }}"
95-
96-
nightly:
97-
name: Test (nightly)
80+
check:
81+
name: Check
9882
runs-on: ubuntu-latest
9983

100-
steps:
101-
- name: Checkout sources
102-
uses: actions/checkout@v4
103-
104-
- name: Install toolchain (${{ env.rust_nightly }})
105-
uses: dtolnay/rust-toolchain@master
106-
with:
107-
toolchain: ${{ env.rust_nightly }}
108-
109-
- name: Add problem matchers
110-
shell: bash
111-
run: echo "::add-matcher::.github/matchers/rust.json"
112-
113-
- name: Cache
114-
uses: Swatinem/rust-cache@v2
115-
116-
- name: Build all features
117-
run: cargo build --features full
118-
119-
- name: Test all features
120-
run: cargo test --features full
84+
strategy:
85+
fail-fast: false
86+
matrix:
87+
name:
88+
- builder without model
89+
- unstable + typesize
90+
- unstable (no default features)
91+
- temp cache
92+
- temp cache + typesize
12193

122-
macOS:
123-
name: Test (macOS)
124-
runs-on: macos-latest
94+
include:
95+
- name: builder without model
96+
features: builder
97+
- name: unstable + typesize
98+
features: default unstable typesize
99+
- name: unstable (no default features)
100+
features: unstable
101+
- name: temp cache
102+
features: default temp_cache
103+
- name: temp cache + typesize
104+
features: default temp_cache typesize
125105

126106
steps:
127107
- name: Checkout sources
@@ -131,24 +111,20 @@ jobs:
131111
uses: dtolnay/rust-toolchain@stable
132112

133113
- name: Add problem matchers
134-
shell: bash
135114
run: echo "::add-matcher::.github/matchers/rust.json"
136115

137116
- name: Cache
138117
uses: Swatinem/rust-cache@v2
139118

140-
- name: Build
141-
run: cargo build
142-
143-
- name: Test
144-
run: cargo test
119+
- name: Run checks
120+
run: cargo check --no-default-features --features "${{ matrix.features || 'full' }}"
145121

146122
MSRV:
147123
runs-on: ubuntu-latest
148124

149125
# We only run this job on the current branch as keeping MSRV the same is not important on next.
150126
if: (github.event_name == 'push' && github.ref_name == 'current') ||
151-
(github.event_name == 'pull_request' && github.base_ref == 'current')
127+
(github.event_name == 'pull_request' && github.base_ref == 'current')
152128

153129
steps:
154130
- name: Checkout sources
@@ -165,7 +141,7 @@ jobs:
165141
- name: Cache
166142
uses: Swatinem/rust-cache@v2
167143

168-
- name: Check
144+
- name: Run checks
169145
run: cargo check --features full
170146

171147
min_versions:
@@ -200,10 +176,8 @@ jobs:
200176
- name: Checkout sources
201177
uses: actions/checkout@v4
202178

203-
- name: Install toolchain (${{ env.rust_nightly }})
204-
uses: dtolnay/rust-toolchain@master
205-
with:
206-
toolchain: ${{ env.rust_nightly }}
179+
- name: Install toolchain
180+
uses: dtolnay/rust-toolchain@stable
207181

208182
- name: Add problem matchers
209183
run: echo "::add-matcher::.github/matchers/rust.json"
@@ -214,8 +188,6 @@ jobs:
214188
- name: Build docs
215189
run: |
216190
cargo doc --no-deps --features full,unstable
217-
env:
218-
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links
219191
220192
examples:
221193
name: Examples
@@ -266,3 +238,5 @@ jobs:
266238
run: cargo check -p e15_webhook
267239
- name: 'Check example 16'
268240
run: cargo check -p e16_interactions_endpoint
241+
- name: 'Check testing example'
242+
run: cargo check -p testing

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ chrono = ["dep:chrono", "typesize?/chrono"]
130130
full = ["default", "collector", "voice", "voice_model", "interactions_endpoint"]
131131

132132
# Enables temporary caching in functions that retrieve data via the HTTP API.
133-
temp_cache = ["cache", "mini-moka", "typesize?/mini_moka"]
133+
temp_cache = ["cache", "mini-moka", "typesize?/mini_moka", "typesize?/dashmap"]
134134

135135
typesize = ["dep:typesize", "dashmap/typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize", "extract_map/typesize"]
136136

src/cache/wrappers.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub(crate) struct MaybeOwnedArc<T>(
123123
#[cfg(feature = "temp_cache")]
124124
impl<T> MaybeOwnedArc<T> {
125125
pub(crate) fn new(inner: T) -> Self {
126-
Self(Arc::new(inner))
126+
Self(Arc::new(inner).into())
127127
}
128128

129129
pub(crate) fn get_inner(self) -> Arc<T> {
@@ -142,8 +142,10 @@ impl<T: typesize::TypeSize> typesize::TypeSize for MaybeOwnedArc<T> {
142142
self.0.extra_size()
143143
}
144144

145-
fn get_collection_item_count(&self) -> Option<usize> {
146-
self.0.get_collection_item_count()
145+
typesize::if_typesize_details! {
146+
fn get_collection_item_count(&self) -> Option<usize> {
147+
self.0.get_collection_item_count()
148+
}
147149
}
148150
}
149151

@@ -159,6 +161,6 @@ impl<T> std::ops::Deref for MaybeOwnedArc<T> {
159161
#[cfg(feature = "temp_cache")]
160162
impl<T> Clone for MaybeOwnedArc<T> {
161163
fn clone(&self) -> Self {
162-
Self(Arc::clone(&self.0))
164+
Self(self.0.clone().into())
163165
}
164166
}

0 commit comments

Comments
 (0)