Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Test all feature combinations #277

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/rust-toolchain@1.74.1 # 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