Skip to content

Commit 6107d93

Browse files
authored
chore(ci): minor fixes to improve CI workflow (#460)
1 parent 4d1c4b3 commit 6107d93

File tree

11 files changed

+59
-78
lines changed

11 files changed

+59
-78
lines changed

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
toolchain: 1.81
2424

25-
- uses: Swatinem/rust-cache@v2 # use a different cache key as coverae uses custom rustc args
25+
- uses: Swatinem/rust-cache@v2 # use a different cache key as coverage uses custom rustc args
2626
with:
2727
cache-provider: buildjet
2828
key: "coverage"
@@ -49,7 +49,7 @@ jobs:
4949
cargo build --bin madara --profile dev
5050
export COVERAGE_BIN=$(realpath target/debug/madara)
5151
rm -f target/madara-* lcov.info
52-
cargo test --profile dev --workspace -- --test-threads=1
52+
cargo test --profile dev --workspace
5353
5454
- name: Generate coverage info
5555
run: |

.github/workflows/db-version.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ jobs:
99
update-db-version:
1010
runs-on: ubuntu-latest
1111
if: contains(github.event.pull_request.labels.*.name, 'db-migration')
12+
permissions:
13+
contents: write
1214
steps:
1315
- uses: actions/checkout@v3
16+
with:
17+
ref: ${{ github.head_ref || github.ref_name }}
1418

1519
- name: Install yq
16-
run: sudo apt-get install -y yq
20+
uses: mikefarah/yq@master
1721

1822
- name: Check if PR already bumped
1923
id: check_bump
@@ -40,7 +44,7 @@ jobs:
4044
if: steps.check_bump.outputs.already_bumped == 'false'
4145
run: |
4246
if [[ -n "$(git status --porcelain)" ]]; then
43-
git add .db-versions.toml
47+
git add .db-versions.yml
4448
git commit -m "chore: bump db version"
45-
git push origin HEAD
49+
git push origin ${{ github.head_ref || github.ref_name }}
4650
fi

.github/workflows/pull-request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
permissions:
14+
contents: write
1415
pull-requests: write
1516

1617
jobs:
@@ -22,7 +23,7 @@ jobs:
2223
linters:
2324
name: Run linters
2425
needs: update_db_version
25-
if: ${{ always() }}
26+
if: ${{ github.event.pull_request.draft == false && always() }}
2627
uses: ./.github/workflows/linters.yml
2728

2829
rust_check:
@@ -38,18 +39,17 @@ jobs:
3839
coverage:
3940
name: Run Coverage
4041
needs: update_db_version
41-
if: ${{ always() }}
42+
if: ${{ github.event.pull_request.draft == false && always() }}
4243
secrets: inherit
4344
uses: ./.github/workflows/coverage.yml
4445

4546
build:
4647
name: Build Madara
4748
needs: update_db_version
48-
if: ${{ always() }}
49+
if: ${{ github.event.pull_request.draft == false && always() }}
4950
uses: ./.github/workflows/build.yml
5051

5152
js_test:
5253
name: Run JS Tests
5354
needs: build
54-
if: ${{ always() }}
5555
uses: ./.github/workflows/starknet-js-test.yml

Cargo.lock

Lines changed: 0 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ dotenv = "0.15.0"
221221
httpmock = "0.7.0"
222222
tempfile = "3.10.1"
223223
mockall = "0.13.0"
224-
serial_test = "3.1.1"
225224
itertools = "0.13.0"
226225
regex = "1.10.5"
227226
bytes = "1.6.0"

crates/madara/client/eth/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ tempfile.workspace = true
8181
dotenv.workspace = true
8282
httpmock.workspace = true
8383
tracing-test = "0.2.5"
84-
serial_test.workspace = true
8584
lazy_static.workspace = true
8685
mp-utils = { workspace = true, features = ["testing"] }
8786
mc-mempool = { workspace = true, features = ["testing"] }

crates/madara/client/eth/src/client.rs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ pub mod eth_client_getter_test {
167167
primitives::U256,
168168
};
169169

170-
use serial_test::serial;
171-
use std::ops::Range;
170+
use std::ops::{Deref, Range};
172171
use std::sync::Mutex;
173172
use tokio;
174173

@@ -212,12 +211,37 @@ pub mod eth_client_getter_test {
212211

213212
static ANVIL: Mutex<Option<Arc<AnvilInstance>>> = Mutex::new(None);
214213

215-
pub fn get_shared_anvil() -> Arc<AnvilInstance> {
216-
let mut anvil = ANVIL.lock().expect("poisoned lock");
217-
if anvil.is_none() {
218-
*anvil = Some(Arc::new(create_anvil_instance()));
214+
/// Wrapper for an Anvil instance that automatically cleans up when all handles are dropped
215+
pub struct AnvilHandle {
216+
instance: Arc<AnvilInstance>,
217+
}
218+
219+
impl Drop for AnvilHandle {
220+
fn drop(&mut self) {
221+
let mut guard = ANVIL.lock().expect("poisoned lock");
222+
// Check if this Arc is the last one (strong_count == 2 because of our reference
223+
// and the one in the static)
224+
if Arc::strong_count(&self.instance) == 2 {
225+
println!("Cleaning up Anvil instance");
226+
*guard = None;
227+
}
228+
}
229+
}
230+
231+
impl Deref for AnvilHandle {
232+
type Target = AnvilInstance;
233+
234+
fn deref(&self) -> &Self::Target {
235+
&self.instance
236+
}
237+
}
238+
239+
pub fn get_shared_anvil() -> AnvilHandle {
240+
let mut guard = ANVIL.lock().expect("poisoned lock");
241+
if guard.is_none() {
242+
*guard = Some(Arc::new(create_anvil_instance()));
219243
}
220-
Arc::clone(anvil.as_ref().unwrap())
244+
AnvilHandle { instance: Arc::clone(guard.as_ref().unwrap()) }
221245
}
222246

223247
pub fn create_anvil_instance() -> AnvilInstance {
@@ -245,7 +269,6 @@ pub mod eth_client_getter_test {
245269
EthereumClient { provider: Arc::new(provider), l1_core_contract: contract.clone(), l1_block_metrics }
246270
}
247271

248-
#[serial]
249272
#[tokio::test]
250273
async fn fail_create_new_client_invalid_core_contract() {
251274
let anvil = get_shared_anvil();
@@ -261,7 +284,6 @@ pub mod eth_client_getter_test {
261284
assert!(new_client_result.is_err(), "EthereumClient::new should fail with an invalid core contract address");
262285
}
263286

264-
#[serial]
265287
#[tokio::test]
266288
async fn get_latest_block_number_works() {
267289
let anvil = get_shared_anvil();
@@ -271,7 +293,6 @@ pub mod eth_client_getter_test {
271293
assert_eq!(block_number, L1_BLOCK_NUMBER, "provider unable to get the correct block number");
272294
}
273295

274-
#[serial]
275296
#[tokio::test]
276297
async fn get_last_event_block_number_works() {
277298
let anvil = get_shared_anvil();
@@ -283,7 +304,6 @@ pub mod eth_client_getter_test {
283304
assert_eq!(block_number, L1_BLOCK_NUMBER, "block number with given event not matching");
284305
}
285306

286-
#[serial]
287307
#[tokio::test]
288308
async fn get_last_verified_block_hash_works() {
289309
let anvil = get_shared_anvil();
@@ -294,7 +314,6 @@ pub mod eth_client_getter_test {
294314
assert_eq!(block_hash, expected, "latest block hash not matching");
295315
}
296316

297-
#[serial]
298317
#[tokio::test]
299318
async fn get_last_state_root_works() {
300319
let anvil = get_shared_anvil();
@@ -304,7 +323,6 @@ pub mod eth_client_getter_test {
304323
assert_eq!(state_root, expected, "latest block state root not matching");
305324
}
306325

307-
#[serial]
308326
#[tokio::test]
309327
async fn get_last_verified_block_number_works() {
310328
let anvil = get_shared_anvil();

crates/madara/client/eth/src/l1_gas_price.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,10 @@ mod eth_client_gas_price_worker_test {
135135
use crate::client::eth_client_getter_test::{create_ethereum_client, get_shared_anvil};
136136
use httpmock::{MockServer, Regex};
137137
use mc_mempool::GasPriceProvider;
138-
use serial_test::serial;
139138
use std::time::SystemTime;
140139
use tokio::task::JoinHandle;
141140
use tokio::time::{timeout, Duration};
142141

143-
#[serial]
144142
#[tokio::test]
145143
async fn gas_price_worker_when_infinite_loop_true_works() {
146144
let anvil = get_shared_anvil();
@@ -184,7 +182,6 @@ mod eth_client_gas_price_worker_test {
184182
assert_eq!(updated_price.eth_l1_data_gas_price, 1);
185183
}
186184

187-
#[serial]
188185
#[tokio::test]
189186
async fn gas_price_worker_when_infinite_loop_false_works() {
190187
let anvil = get_shared_anvil();
@@ -203,7 +200,6 @@ mod eth_client_gas_price_worker_test {
203200
assert_eq!(updated_price.eth_l1_data_gas_price, 1);
204201
}
205202

206-
#[serial]
207203
#[tokio::test]
208204
async fn gas_price_worker_when_gas_price_fix_works() {
209205
let anvil = get_shared_anvil();
@@ -224,7 +220,6 @@ mod eth_client_gas_price_worker_test {
224220
assert_eq!(updated_price.eth_l1_data_gas_price, 1);
225221
}
226222

227-
#[serial]
228223
#[tokio::test]
229224
async fn gas_price_worker_when_data_gas_price_fix_works() {
230225
let anvil = get_shared_anvil();
@@ -245,7 +240,6 @@ mod eth_client_gas_price_worker_test {
245240
assert_eq!(updated_price.eth_l1_data_gas_price, 20);
246241
}
247242

248-
#[serial]
249243
#[tokio::test]
250244
async fn gas_price_worker_when_eth_fee_history_fails_should_fails() {
251245
let mock_server = MockServer::start();
@@ -311,7 +305,6 @@ mod eth_client_gas_price_worker_test {
311305
mock.assert();
312306
}
313307

314-
#[serial]
315308
#[tokio::test]
316309
async fn update_gas_price_works() {
317310
let anvil = get_shared_anvil();

scripts/e2e-coverage.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ cargo build --bin madara --profile dev
1616
export COVERAGE_BIN=$(realpath target/debug/madara)
1717

1818
# Run tests with coverage collection
19-
cargo test --profile dev "${@:-"--workspace"}"
19+
if cargo test --profile dev "${@:-"--workspace"}"; then
20+
echo "✅ All tests passed successfully!"
21+
else
22+
echo "❌ Some tests failed."
23+
fi
2024

2125
# Generate coverage reports
2226
cargo llvm-cov report --lcov --output-path lcov.info # Generate LCOV report

scripts/e2e-tests.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ export ETH_FORK_URL=https://eth.merkle.io
1010

1111
# Build the binary
1212
cargo build --bin madara --profile dev
13-
export BINARY_PATH=$(realpath target/debug/madara)
13+
export COVERAGE_BIN=$(realpath target/debug/madara)
1414

1515
# Run the tests
16-
cargo test --profile dev "${@:-"--workspace"}"
16+
if cargo test --profile dev "${@:-"--workspace"}"; then
17+
echo "✅ All tests passed successfully!"
18+
else
19+
echo "❌ Some tests failed."
20+
exit 1
21+
fi

scripts/update-db-version.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
#
44
# Database version management script
@@ -64,7 +64,7 @@ CURRENT_VERSION=$(yq '.current_version' "$FILE")
6464
NEW_VERSION=$((CURRENT_VERSION + 1))
6565

6666
# Update version and append to history
67-
yq -i -y ".current_version = $NEW_VERSION |
68-
.versions = [{\"version\": $NEW_VERSION, \"pr\": $PR_NUMBER}] + .versions" "$FILE"
67+
yq e ".current_version = $NEW_VERSION |
68+
.versions = [{\"version\": $NEW_VERSION, \"pr\": $PR_NUMBER}] + .versions" -i "$FILE"
6969

7070
echo "Successfully updated DB version to ${NEW_VERSION} (PR #${PR_NUMBER})"

0 commit comments

Comments
 (0)