feat(sync): expose ICP context as env vars in sync script steps#550
Merged
Conversation
Sync script steps now receive ICP_CLI_ENVIRONMENT, ICP_CLI_NETWORK, ICP_CLI_CID (current canister), and ICP_CLI_CID_<NAME> (all project canisters) as environment variables on every executed command. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds three integration tests: - sync_script_icp_env_vars: single-canister sync verifies all four vars (ICP_CLI_ENVIRONMENT, ICP_CLI_NETWORK, ICP_CLI_CID, ICP_CLI_CID_<NAME>) - sync_script_icp_cid_cross_canister: multi-canister sync verifies each canister's script can see other canisters' ICP_CLI_CID_<NAME> vars - deploy_sync_script_icp_env_vars: deploy-triggered sync path also receives the correct env and CID vars Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a Sync Script Variables section to the environment variables reference, and cross-references it from build-deploy-sync.md and creating-recipes.md, following the same pattern as ICP_WASM_OUTPUT_PATH. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR exposes deployment context to script-type sync steps by injecting environment variables (environment name, network name, current canister ID, and all known canister IDs) into every executed sync command, and updates docs + integration tests to cover the new behavior.
Changes:
- Add
ICP_CLI_ENVIRONMENT,ICP_CLI_NETWORK,ICP_CLI_CID, andICP_CLI_CID_<NAME>env vars forscriptsync steps. - Plumb network name + canister ID mapping through the sync execution pipeline (CLI → operations →
icpsyncer). - Add sync/deploy integration tests and update docs/changelog to document the new variables.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/reference/environment-variables.md | Documents new sync-script environment variables. |
| docs/guides/creating-recipes.md | Adds recipe guide section listing build/sync script env vars. |
| docs/concepts/build-deploy-sync.md | Describes script sync steps and available env vars. |
| crates/icp/src/canister/sync/script.rs | Injects the new env vars into sync script command execution. |
| crates/icp/src/canister/sync/mod.rs | Extends sync Params to carry network name and canister ID map. |
| crates/icp-cli/src/operations/sync.rs | Threads network + canister ID map into per-canister sync execution. |
| crates/icp-cli/src/commands/sync.rs | Collects environment ID mapping and passes it into sync_many. |
| crates/icp-cli/src/commands/deploy.rs | Collects environment ID mapping for deploy-triggered sync. |
| crates/icp-cli/tests/sync_tests.rs | Adds integration test asserting env vars are present during icp sync. |
| crates/icp-cli/tests/deploy_tests.rs | Adds integration test asserting env vars are present during deploy-triggered sync. |
| CHANGELOG.md | Notes the new sync-script env vars in Unreleased. |
Comments suppressed due to low confidence (1)
crates/icp-cli/src/operations/sync.rs:105
let canister_ids = canister_ids.clone();clones the entire ID map per-canister task; combined with the per-step clone, this can amplify overhead. Prefer capturing a sharedArc<IdMapping>(or borrowing a shared reference if lifetimes allow) to avoid repeated full clones.
let agent = agent.clone();
let syncer = syncer.clone();
let environment = environment.clone();
let network = network.clone();
let canister_ids = canister_ids.clone();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…keys and correct docs Normalization previously only handled `-`, `.`, and spaces; any other character (unicode, `@`, `/`, etc.) would produce an invalid POSIX env var name. Now any character outside `[A-Z0-9]` is replaced with `_`. Docs updated to reflect that ICP_CLI_CID_<NAME> is populated from the environment's ID mapping, not necessarily every canister in the project. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
adamspofford-dfinity
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scriptsteps now receiveICP_CLI_ENVIRONMENT,ICP_CLI_NETWORK,ICP_CLI_CID, andICP_CLI_CID_<NAME>as environment variables on every executed command.ICP_CLI_CID_<NAME>is set for each canister in the environment's ID mapping (name uppercased, with any character outside[A-Z0-9]replaced by_so the key is a valid POSIX env var name).Test plan
sync_tests.rs— verifies all four variable families are set inscriptsync steps viaicp syncdeploy_tests.rs— verifies the same variables are set when sync runs as part oficp deploy🤖 Generated with Claude Code