Skip to content

Commit

Permalink
CI: Test all feature combinations (#277)
Browse files Browse the repository at this point in the history
- Remove caching from the `lint` job as it is less critical for these quick checks (now takes ~1 min).
- Introduce `CACHE_VERSION` to the cache key, updated bi-weekly.
- Use only release artifacts (needed to not exceed the 10GB github actions limit, but also makes sense as we test the end user targets).
  • Loading branch information
JoseSK999 authored Nov 19, 2024
1 parent 826c5ee commit 176a17f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
62 changes: 44 additions & 18 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ jobs:
with:
components: rustfmt, clippy

- name: Cache Rust
uses: Swatinem/rust-cache@v2

- name: Run cargo fmt
run: cargo +nightly fmt --all --check

- name: Run cargo clippy
run: cargo +nightly clippy --all-targets
env:
PWD: ${{ github.workspace }} # without it ci can't see env!("PWD")

cross-testing:
strategy:
Expand All @@ -39,25 +34,56 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/[email protected] # The version in our `rust-toolchain.toml`
with:
components: rustfmt, clippy
- uses: taiki-e/install-action@cargo-hack

- name: Cache Rust
uses: actions/cache@v4
# Bi-weekly numbers to refresh caches every two weeks, ensuring recent project changes are cached
- name: Set bi-weekly cache key
run: |
YEAR=$(date +%Y)
BIWEEK=$(( ($(date +%U) + 1) / 2 ))
echo "CACHE_VERSION=${YEAR}(${BIWEEK})" >> $GITHUB_ENV
shell: bash

# Restore cached dependencies and build artifacts
- name: Restore Rust cache
id: cache
uses: actions/cache/restore@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build Floresta
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose
env:
PWD: ${{ github.workspace }} # without it ci can't see env!("PWD")
target/release/
# Cache key depends on the bi-week we are on (cache version)
key: ${{ runner.os }}-cargo-${{ env.CACHE_VERSION }}-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.CACHE_VERSION }}-
${{ runner.os }}-cargo-
# Build only the binaries
- name: Build binaries
run: cargo build --release --bins --verbose

# Run the feature testing script
- name: Run feature tests
run: ./contrib/test_features.sh --verbose
shell: bash # Ensure the script runs using bash on all platforms

# Save cache only if the previous steps succeeded and there was not an exact cache key match
# This happens everytime we modify any `cargo.lock` or `cargo.toml`, or each two weeks (caching recent changes)
- name: Save Rust cache
if: success() && steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/release/
key: ${{ steps.cache.outputs.cache-primary-key }}

build-docker:
runs-on: ubuntu-latest
Expand Down
11 changes: 10 additions & 1 deletion crates/floresta-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod rpc_types;
mod tests {
use std::fs;
use std::net::TcpListener;
use std::path::Path;
use std::process::Child;
use std::process::Command;
use std::process::Stdio;
Expand Down Expand Up @@ -60,7 +61,15 @@ mod tests {
// CARGO_MANIFEST_DIR is always floresta-cli's directory; PWD changes based on where the
// command is executed.
let root = format!("{}/../..", env!("CARGO_MANIFEST_DIR"));
let florestad_path = format!("{root}/target/debug/florestad");
let release_path = format!("{root}/target/release/florestad");
let debug_path = format!("{root}/target/debug/florestad");

let release_found = Path::new(&release_path).try_exists().unwrap();
// If release target not found, default to the debug path
let florestad_path = match release_found {
true => release_path,
false => debug_path,
};

// makes a temporary directory
let test_code = rand::random::<u64>();
Expand Down

0 comments on commit 176a17f

Please sign in to comment.