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: update ci and add xtask testing #233

Merged
merged 1 commit into from
Feb 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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ jobs:
run: cargo build --verbose --all
- name: cargo test
run: cargo test --verbose --all
- name: cargo xtask test
run: cargo xtask test --ci
14 changes: 12 additions & 2 deletions docker/gha-runner.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

FROM rodnymolina588/gha-sysbox-runner@sha256:d10a36f2da30aa0df71d1ac062cc79fc5114eec7b6ae8a0c42cadf568e6eefa8

ARG RUSTC_VERSION=nightly-2023-10-16
ARG RUSTC_VERSION=stable

LABEL org.opencontainers.image.source=https://github.com/thrumdev/blobs

Expand All @@ -15,6 +15,7 @@ ENV CARGO_TARGET_DIR=/cargo_target
ENV RUSTFLAGS=""
ENV RUSTUP_HOME=/rustup

RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
Expand All @@ -28,7 +29,9 @@ RUN \
make \
libssl-dev \
pkg-config \
docker-compose-plugin
docker-compose-plugin \
nodejs \
multitail

RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
Expand All @@ -44,3 +47,10 @@ RUN curl \
| bash
RUN cargo binstall --no-confirm --no-symlinks cargo-risczero
RUN cargo risczero install

# Install Zombienet and copy Polkadot binaries, which are all required for xtask tests
RUN npm install -g @zombienet/cli

COPY --from=parity/polkadot:v1.6.0 /usr/bin/polkadot /usr/bin/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we could also extract this into an ARG.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered that using ARG is more complex than expected. Doing something like this:

ARG POLKADOT=parity/polkadot:v1.6.0
FROM $POLKADOT as polkadot
COPY --from=polkadot /usr/bin/polkadot /usr/bin/

does not work because ARG can be defined at build time with an argument variable, and parity/polkadot:v1.6.0 would be used only if it is not specified. However, if it is specified but not assigned to anything, it would be empty, which is not valid for the FROM command. To make it work, it should be:

ARG POLKADOT=parity/polkadot:v1.6.0
FROM ${POLKADOT:-parity/polkadot:v1.6.0} as polkadot
COPY --from=polkadot /usr/bin/polkadot /usr/bin/

But if the goal is to reduce the lines that need to be changed on a Polkadot update, I opted for:

FROM parity/polkadot:v1.6.0 as polkadot
COPY --from=polkadot /usr/bin/polkadot /usr/bin/

COPY --from=parity/polkadot:v1.6.0 /usr/lib/polkadot/polkadot-prepare-worker /usr/bin/
COPY --from=parity/polkadot:v1.6.0 /usr/lib/polkadot/polkadot-execute-worker /usr/bin/
12 changes: 9 additions & 3 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ pub fn build(params: BuildParams) -> anyhow::Result<()> {
)
.run()?;

#[rustfmt::skip]
with_logs(
"Building sovereign demo-rollup",
cmd!(&cargo, "build", "--release").dir("demo/sovereign/demo-rollup"),
)
.run()?;
cmd!(
"sh", "-c",
format!(
"cd demo/sovereign/demo-rollup/ && {} build --release",
cargo
)
),
).run()?;

Ok(())
}
4 changes: 4 additions & 0 deletions xtask/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub mod test {
use clap::Args;
#[derive(Debug, Args)]
pub struct Params {
/// If the test is executed in CI
#[clap(long, default_value = "false")]
pub ci: bool,

#[clap(flatten)]
pub build: BuildParams,

Expand Down
2 changes: 1 addition & 1 deletion xtask/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn create_with_logs(

info!("{description}");
let _ = log_file
.write(format!("{}/n", description).as_bytes())
.write(format!("{}\n", description).as_bytes())
.map_err(|e| warn!("Error writing into {log_path}, error: {e}"));
let _ = log_file
.flush()
Expand Down
38 changes: 38 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ fn main() -> anyhow::Result<()> {
}

fn test(params: test::Params) -> anyhow::Result<()> {
init_env(params.ci)?;

build::build(params.build)?;

// the variables must be kept alive and not dropped
Expand All @@ -39,6 +41,42 @@ fn test(params: test::Params) -> anyhow::Result<()> {
Ok(())
}

// Set up environment variables needed by the compilation and testing process.
//
// If ci flag is specified, all binaries are added to PATH env variable
// and the sovereign constant manifest position is specified through the
// CONSTANTS_MANIFEST new env variable
fn init_env(ci: bool) -> anyhow::Result<()> {
if ci {
#[rustfmt::skip]
let project_dir = duct::cmd!(
"sh", "-c",
"cargo locate-project | jq -r '.root' | grep -oE '^.*/'"
)
.stdout_capture()
.run()?;
let project_dir = std::str::from_utf8(&project_dir.stdout)?.trim();

let path = std::env::var("PATH").unwrap_or_else(|_| "".to_string());

// `cargo_target` is the target used in ci by cargo as destination
// for all intermediate and final artifacts
let new_path = format!("/cargo_target/release/:{}", path);
std::env::set_var("PATH", new_path);

let path = std::path::Path::new(project_dir).join("demo/sovereign/constants.json");
if !path.exists() {
anyhow::bail!(
"The `constants.json` file for Sovereign does not exist,\n \
or it is not in the expected position, `demo/sovereign/constants.json`"
)
}
std::env::set_var("CONSTANTS_MANIFEST", path);
}

Ok(())
}

fn init_logging() -> anyhow::Result<()> {
use tracing_subscriber::fmt;
use tracing_subscriber::prelude::*;
Expand Down