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 5, 2024
1 parent b3d7f4c commit 3942014
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
41 changes: 28 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -105,40 +105,55 @@ 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 binary
uses: actions/download-artifact@v4
with:
name: binary-stable
path: src/html

- 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' }}
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.has_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 3942014

Please sign in to comment.