-
Notifications
You must be signed in to change notification settings - Fork 12
feat: env-specific builds #696
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
base: main
Are you sure you want to change the base?
Changes from all commits
4723fa9
85b4900
3934ccf
a90912e
a3b3348
f532cfb
c7fe2e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ struct BuildFailure { | |
| pub(crate) async fn build( | ||
| canister_path: &Path, | ||
| canister: &Canister, | ||
| environment: &str, | ||
| pb: &mut MultiStepProgressBar, | ||
| builder: Arc<dyn Build>, | ||
| artifacts: Arc<dyn icp::store_artifact::Access>, | ||
|
|
@@ -69,6 +70,7 @@ pub(crate) async fn build( | |
| &Params { | ||
| path: canister_path.to_owned(), | ||
| output: wasm_output_path.to_owned(), | ||
| environment: environment.to_owned(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build output can now vary by environment, but the artifact store still has one slot per canister ( Key the artifact dir by environment, or keep a caveat in the docs in place of the deleted bullet. |
||
| }, | ||
|
adamspofford-dfinity marked this conversation as resolved.
|
||
| Some(tx), | ||
| pkg_cache, | ||
|
|
@@ -96,6 +98,7 @@ pub(crate) async fn build( | |
|
|
||
| pub(crate) async fn build_many_with_progress_bar( | ||
| canisters: Vec<(PathBuf, Canister)>, | ||
| environment: &str, | ||
| builder: Arc<dyn Build>, | ||
| artifacts: Arc<dyn icp::store_artifact::Access>, | ||
| pkg_cache: &PackageCache, | ||
|
|
@@ -112,6 +115,7 @@ pub(crate) async fn build_many_with_progress_bar( | |
| let build_result = build( | ||
| &canister_path, | ||
| &canister, | ||
| environment, | ||
| &mut pb, | ||
| builder, | ||
| artifacts, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ use std::{ | |
| use camino::Utf8Component; | ||
| use flate2::bufread::GzDecoder; | ||
| use icp::{ | ||
| fs::{create_dir_all, write, write_string}, | ||
| fs::{create_dir_all, read_to_string, write, write_string}, | ||
| prelude::*, | ||
| }; | ||
| use indoc::formatdoc; | ||
|
|
@@ -817,6 +817,60 @@ fn bundle_rejects_source_outside_project() { | |
| /// exist when bundling validates the sync sources, before the build. Validation | ||
| /// must resolve sync paths lexically (no canonicalization) so a not-yet-built | ||
| /// directory is accepted; the build then creates it before it is archived. | ||
| /// The environment reaching build steps as `ICP_CLI_ENVIRONMENT` defaults to `ic` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test landed between the doc comment and the fn it documents — the "resolve sync paths lexically" comment now describes |
||
| /// for a bundle, rather than the `local` the rest of the CLI defaults to. | ||
| #[test] | ||
| fn bundle_builds_for_ic_by_default() { | ||
| let ctx = TestContext::new(); | ||
| let project_dir = ctx.create_project_dir("icp"); | ||
| let wasm_src = ctx.make_asset("example_icp_mo.wasm"); | ||
| let recorded = project_dir.join("environment.txt"); | ||
|
|
||
| let pm = formatdoc! {r#" | ||
| canisters: | ||
| - name: my-canister | ||
| build: | ||
| steps: | ||
| - type: script | ||
| commands: | ||
| - echo "$ICP_CLI_ENVIRONMENT" > '{recorded}' | ||
| - cp '{wasm_src}' "$ICP_WASM_OUTPUT_PATH" | ||
| "#}; | ||
|
|
||
| write_string(&project_dir.join("icp.yaml"), &pm).expect("failed to write project manifest"); | ||
|
|
||
| let bundle_path = project_dir.join("bundle.tar.gz"); | ||
| ctx.icp() | ||
| .current_dir(&project_dir) | ||
| .args(["project", "bundle", "--output", bundle_path.as_str()]) | ||
| .assert() | ||
| .success(); | ||
|
|
||
| assert_eq!( | ||
| read_to_string(&recorded).expect("failed to read recorded environment"), | ||
| "ic\n" | ||
| ); | ||
|
|
||
| // An explicit --environment overrides the default. | ||
| ctx.icp() | ||
| .current_dir(&project_dir) | ||
| .args([ | ||
| "project", | ||
| "bundle", | ||
| "--output", | ||
| bundle_path.as_str(), | ||
| "--environment", | ||
| "staging", | ||
| ]) | ||
| .assert() | ||
| .success(); | ||
|
|
||
| assert_eq!( | ||
| read_to_string(&recorded).expect("failed to read recorded environment"), | ||
| "staging\n" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn bundle_accepts_synced_dir_created_by_build_step() { | ||
| let ctx = TestContext::new(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the trailing period — clap strips it from doc comments, so every other
--environmentrenders without one, and it shows up in the generatedcli.md. Same ondeploy.rs:104. Regeneratecli.mdafter.