Skip to content

Commit 3ad8ebb

Browse files
fix(test): use local openvm for testing cargo openvm init (#1842)
Currently if we change the workspace version before tagging, the integration test for `cargo openvm init` will break because it creates a guest crate that references the tagged version. I updated the test so it patches to the local openvm if the environmental variable `USE_LOCAL_OPENVM=1` is set.
1 parent 5f7553f commit 3ad8ebb

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.github/workflows/cli.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: OpenVM CLI Tests
33
on:
44
push:
55
branches: ["main"]
6+
tags: ["v*"]
67
pull_request:
78
branches: ["**"]
89
paths:
@@ -14,6 +15,13 @@ on:
1415
- "examples/**"
1516
- "Cargo.toml"
1617
- ".github/workflows/cli.yml"
18+
workflow_dispatch:
19+
inputs:
20+
use_local_openvm:
21+
description: "Test cargo openvm init using local patch"
22+
required: true
23+
type: boolean
24+
default: false
1725

1826
concurrency:
1927
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
@@ -75,6 +83,14 @@ jobs:
7583
cargo build
7684
cargo run --bin cargo-openvm -- openvm keygen --config ./example/app_config.toml --output-dir .
7785
86+
- name: Set USE_LOCAL_OPENVM environment variable
87+
run: |
88+
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/tags/* ]] || [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.use_local_openvm }}" == "false" ]]; then
89+
echo "USE_LOCAL_OPENVM=0" >> $GITHUB_ENV
90+
else
91+
echo "USE_LOCAL_OPENVM=1" >> $GITHUB_ENV
92+
fi
93+
7894
- name: Run CLI tests
7995
working-directory: crates/cli
8096
run: |

crates/cli/tests/app_e2e.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{env, process::Command};
1+
use std::{env, fs::OpenOptions, io::Write, path::Path, process::Command};
22

33
use eyre::Result;
44
use tempfile::tempdir;
@@ -134,6 +134,9 @@ fn test_cli_init_build() -> Result<()> {
134134
"cli-package",
135135
],
136136
)?;
137+
if matches!(env::var("USE_LOCAL_OPENVM"), Ok(x) if x == "1") {
138+
append_patch_to_cargo_toml(&manifest_path)?;
139+
}
137140

138141
run_cmd(
139142
"cargo",
@@ -171,3 +174,26 @@ fn run_cmd(program: &str, args: &[&str]) -> Result<()> {
171174
}
172175
Ok(())
173176
}
177+
178+
fn append_patch_to_cargo_toml(file_path: impl AsRef<Path>) -> Result<()> {
179+
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR");
180+
let openvm_path = Path::new(MANIFEST_DIR)
181+
.parent()
182+
.unwrap()
183+
.join("toolchain")
184+
.join("openvm");
185+
let mut file = OpenOptions::new()
186+
.create(false)
187+
.append(true)
188+
.open(file_path)?;
189+
190+
// Add a newline first to ensure proper formatting
191+
writeln!(file)?;
192+
writeln!(
193+
file,
194+
r#"[patch."https://github.com/openvm-org/openvm.git"]"#
195+
)?;
196+
writeln!(file, r#"openvm = {{ path = "{}" }}"#, openvm_path.display())?;
197+
198+
Ok(())
199+
}

0 commit comments

Comments
 (0)