Skip to content

Commit

Permalink
Split tests after the matrix build
Browse files Browse the repository at this point in the history
Tweak the tests so we can pass a path to a compiled `margo`
binary (e.g. from a previous CI build step).
  • Loading branch information
shepmaster committed May 6, 2024
1 parent d6cc584 commit ec592c4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 30 deletions.
68 changes: 48 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ jobs:
- name: Install JS dependencies
run: pnpm install

- name: Build UI assets
run: pnpm build

- name: Format UI assets
run: pnpm fmt:check

- name: Build UI assets
run: pnpm build

- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
Expand All @@ -57,10 +57,10 @@ jobs:
name: assets
path: src/html/assets.rs

check:
name: Build and test

build:
name: Build
runs-on: ubuntu-latest

strategy:
matrix:
rust:
Expand All @@ -84,7 +84,6 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy

# https://doc.rust-lang.org/1.77.2/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci
- name: Cargo cache (platform-independent)
Expand All @@ -105,40 +104,69 @@ jobs:
target
key: cargo-build-${{ runner.os }}-${{ matrix.rust }}

- name: Build code
run: cargo build

- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.rust }}
path: target/debug/margo

check:
name: Check
runs-on: ubuntu-latest

needs: build

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download assets
uses: actions/download-artifact@v4
with:
name: assets
path: src/html

- name: Download binary
uses: actions/download-artifact@v4
with:
name: binary-stable
path: .

- name: Register binary
run: |
MARGO_BINARY="$(pwd)/margo"
chmod +x "${MARGO_BINARY}"
echo "MARGO_BINARY=${MARGO_BINARY}" >> $GITHUB_ENV
echo "${MARGO_BINARY}"
"${MARGO_BINARY}" --help
- name: Cargo cache (build conformance)
uses: actions/cache@v4
with:
path: |-
conformance/target
key: cargo-build-conformance-${{ runner.os }}-${{ matrix.rust }}
if: ${{ matrix.rust == 'stable' }}

- name: Build code
run: cargo build

- name: Format code
run: cargo fmt --all -- --check
if: ${{ matrix.rust == 'stable' }}

- name: Lint code
run: cargo clippy -- -D warnings
if: ${{ matrix.rust == 'stable' }}

- name: Test conformance
run: cd conformance && cargo run
if: ${{ matrix.rust == 'stable' }}

- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
working-directory: integration-tests
bundler-cache: true
if: ${{ matrix.rust == 'stable' }}

- name: Test UI
run: cd integration-tests && bundle exec rspec
if: ${{ matrix.rust == 'stable' }}

- name: Lint UI Tests
run: cd integration-tests && bundle exec rubocop
if: ${{ matrix.rust == 'stable' }}

- name: Test UI
run: cd integration-tests && bundle exec rspec
11 changes: 8 additions & 3 deletions conformance/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
use axum::Router;
use registry_conformance::{CommandExt, CreatedCrate, Registry};
use snafu::prelude::*;
use std::{future::IntoFuture, io, net::SocketAddr, path::PathBuf, process::ExitCode};
use std::{env, future::IntoFuture, io, net::SocketAddr, path::{Path, PathBuf}, process::ExitCode};
use tokio::{net::TcpListener, process::Command, task::JoinHandle};
use tokio_util::sync::CancellationToken;
use tower_http::services::ServeDir;

#[tokio::main]
async fn main() -> Result<ExitCode, BuildError> {
Margo::build().await?;
if env::var_os("MARGO_BINARY").is_none() {
Margo::build().await?;
}

Ok(registry_conformance::test_conformance::<Margo>(std::env::args()).await)
}
Expand Down Expand Up @@ -109,7 +111,10 @@ impl Margo {
}

fn command(&self) -> Command {
let mut cmd = Command::new(Self::EXE_PATH);
let exe_path = env::var_os("MARGO_BINARY").map(PathBuf::from);
let exe_path = exe_path.as_deref().unwrap_or_else(|| Path::new(Self::EXE_PATH));

let mut cmd = Command::new(exe_path);

cmd.kill_on_drop(true);

Expand Down
14 changes: 9 additions & 5 deletions integration-tests/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@
config.order = :random
Kernel.srand config.seed

config.before(:suite) do
system(
'cargo', 'build',
exception: true,
)
unless ENV.key?('MARGO_BINARY')
config.before(:suite) do
system(
'cargo', 'build',
exception: true,
)
end
end
end

MARGO_BINARY = ENV.fetch('MARGO_BINARY', '../target/debug/margo')

Capybara.default_driver = Capybara.javascript_driver = :selenium_headless
Capybara.run_server = false
2 changes: 1 addition & 1 deletion integration-tests/spec/support/crate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def publish_to(registry)
package = @root.join('target', 'package', "#{name}-#{version}.crate")

system(
'../target/debug/margo',
MARGO_BINARY,
'add',
'--registry',
registry.root.to_s,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/spec/support/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(root)
def start
@server.start
system(
'../target/debug/margo',
MARGO_BINARY,
'init',
'--base-url',
url,
Expand Down

0 comments on commit ec592c4

Please sign in to comment.