Skip to content

Commit 13c3a5a

Browse files
gabriele-0201pepyakin
authored andcommitted
ci: update ci and add xtask testing
1 parent da7db7e commit 13c3a5a

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ jobs:
3131
run: cargo build --verbose --all
3232
- name: cargo test
3333
run: cargo test --verbose --all
34+
- name: cargo xtask test
35+
run: cargo xtask test --ci

docker/gha-runner.Dockerfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

8-
ARG RUSTC_VERSION=nightly-2023-10-16
8+
ARG RUSTC_VERSION=stable
99

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

@@ -15,6 +15,7 @@ ENV CARGO_TARGET_DIR=/cargo_target
1515
ENV RUSTFLAGS=""
1616
ENV RUSTUP_HOME=/rustup
1717

18+
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
1819
RUN \
1920
apt-get update && \
2021
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
@@ -28,7 +29,9 @@ RUN \
2829
make \
2930
libssl-dev \
3031
pkg-config \
31-
docker-compose-plugin
32+
docker-compose-plugin \
33+
nodejs \
34+
multitail
3235

3336
RUN \
3437
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION
@@ -44,3 +47,10 @@ RUN curl \
4447
| bash
4548
RUN cargo binstall --no-confirm --no-symlinks cargo-risczero
4649
RUN cargo risczero install
50+
51+
# Install Zombienet and copy Polkadot binaries, which are all required for xtask tests
52+
RUN npm install -g @zombienet/cli
53+
54+
COPY --from=parity/polkadot:v1.6.0 /usr/bin/polkadot /usr/bin/
55+
COPY --from=parity/polkadot:v1.6.0 /usr/lib/polkadot/polkadot-prepare-worker /usr/bin/
56+
COPY --from=parity/polkadot:v1.6.0 /usr/lib/polkadot/polkadot-execute-worker /usr/bin/

xtask/src/build.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ pub fn build(params: BuildParams) -> anyhow::Result<()> {
2727
)
2828
.run()?;
2929

30+
#[rustfmt::skip]
3031
with_logs(
3132
"Building sovereign demo-rollup",
32-
cmd!(&cargo, "build", "--release").dir("demo/sovereign/demo-rollup"),
33-
)
34-
.run()?;
33+
cmd!(
34+
"sh", "-c",
35+
format!(
36+
"cd demo/sovereign/demo-rollup/ && {} build --release",
37+
cargo
38+
)
39+
),
40+
).run()?;
3541

3642
Ok(())
3743
}

xtask/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ pub mod test {
1818
use clap::Args;
1919
#[derive(Debug, Args)]
2020
pub struct Params {
21+
/// If the test is executed in CI
22+
#[clap(long, default_value = "false")]
23+
pub ci: bool,
24+
2125
#[clap(flatten)]
2226
pub build: BuildParams,
2327

xtask/src/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn create_with_logs(
3939

4040
info!("{description}");
4141
let _ = log_file
42-
.write(format!("{}/n", description).as_bytes())
42+
.write(format!("{}\n", description).as_bytes())
4343
.map_err(|e| warn!("Error writing into {log_path}, error: {e}"));
4444
let _ = log_file
4545
.flush()

xtask/src/main.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fn main() -> anyhow::Result<()> {
2020
}
2121

2222
fn test(params: test::Params) -> anyhow::Result<()> {
23+
init_env(params.ci)?;
24+
2325
build::build(params.build)?;
2426

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

44+
// Set up environment variables needed by the compilation and testing process.
45+
//
46+
// If ci flag is specified, all binaries are added to PATH env variable
47+
// and the sovereign constant manifest position is specified through the
48+
// CONSTANTS_MANIFEST new env variable
49+
fn init_env(ci: bool) -> anyhow::Result<()> {
50+
if ci {
51+
#[rustfmt::skip]
52+
let project_dir = duct::cmd!(
53+
"sh", "-c",
54+
"cargo locate-project | jq -r '.root' | grep -oE '^.*/'"
55+
)
56+
.stdout_capture()
57+
.run()?;
58+
let project_dir = std::str::from_utf8(&project_dir.stdout)?.trim();
59+
60+
let path = std::env::var("PATH").unwrap_or_else(|_| "".to_string());
61+
62+
// `cargo_target` is the target used in ci by cargo as destination
63+
// for all intermediate and final artifacts
64+
let new_path = format!("/cargo_target/release/:{}", path);
65+
std::env::set_var("PATH", new_path);
66+
67+
let path = std::path::Path::new(project_dir).join("demo/sovereign/constants.json");
68+
if !path.exists() {
69+
anyhow::bail!(
70+
"The `constants.json` file for Sovereign does not exist,\n \
71+
or it is not in the expected position, `demo/sovereign/constants.json`"
72+
)
73+
}
74+
std::env::set_var("CONSTANTS_MANIFEST", path);
75+
}
76+
77+
Ok(())
78+
}
79+
4280
fn init_logging() -> anyhow::Result<()> {
4381
use tracing_subscriber::fmt;
4482
use tracing_subscriber::prelude::*;

0 commit comments

Comments
 (0)