Skip to content

feat(sync): expose ICP context as env vars in sync script steps#550

Merged
lwshang merged 6 commits into
mainfrom
lwshang/SDK-2710_sync_script_env_vars
May 14, 2026
Merged

feat(sync): expose ICP context as env vars in sync script steps#550
lwshang merged 6 commits into
mainfrom
lwshang/SDK-2710_sync_script_env_vars

Conversation

@lwshang
Copy link
Copy Markdown
Contributor

@lwshang lwshang commented May 13, 2026

Summary

  • Sync script steps now receive ICP_CLI_ENVIRONMENT, ICP_CLI_NETWORK, ICP_CLI_CID, and ICP_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).
  • Docs updated in the environment variables reference, build-deploy-sync concept page, and creating-recipes guide.

Test plan

  • sync_tests.rs — verifies all four variable families are set in script sync steps via icp sync
  • deploy_tests.rs — verifies the same variables are set when sync runs as part of icp deploy

🤖 Generated with Claude Code

lwshang and others added 4 commits May 13, 2026 11:47
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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and ICP_CLI_CID_<NAME> env vars for script sync steps.
  • Plumb network name + canister ID mapping through the sync execution pipeline (CLI → operations → icp syncer).
  • 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 shared Arc<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.

Comment thread docs/reference/environment-variables.md Outdated
Comment thread docs/guides/creating-recipes.md Outdated
Comment thread docs/concepts/build-deploy-sync.md Outdated
Comment thread crates/icp/src/canister/sync/script.rs
Comment thread crates/icp-cli/src/operations/sync.rs
…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>
@lwshang lwshang marked this pull request as ready for review May 13, 2026 18:00
@lwshang lwshang requested a review from a team as a code owner May 13, 2026 18:00
@lwshang lwshang enabled auto-merge (squash) May 14, 2026 17:36
@lwshang lwshang merged commit efadae8 into main May 14, 2026
94 checks passed
@lwshang lwshang deleted the lwshang/SDK-2710_sync_script_env_vars branch May 14, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants