canister-predeploy.sh
bash
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | #!/usr/bin/env bash |
| 2 | # Safe preflight before `dfx deploy` for hub/icp. |
| 3 | # |
| 4 | # What it does: |
| 5 | # 1. Static migration / actor contract checks (scripts/verify-canister-migration.mjs) |
| 6 | # 2. npm test (skip with SKIP_NPM_TEST=1) |
| 7 | # 3. dfx build hub (compiles Motoko; catches type errors before touching mainnet) |
| 8 | # 4. Optional: JSON export backup to ./backups/ (see env vars below) |
| 9 | # |
| 10 | # What it does NOT do: run deploy or upgrade. You still run `dfx deploy --network ic` yourself. |
| 11 | # |
| 12 | # Optional backup (recommended before mainnet upgrade if you have real user data): |
| 13 | # KNOWTATION_CANISTER_URL='https://<canister-id>.icp0.io' # no trailing slash; .raw.icp0.io also OK |
| 14 | # KNOWTATION_CANISTER_BACKUP_USER_ID='google:…' # same X-User-Id the gateway would send |
| 15 | # KNOWTATION_CANISTER_BACKUP_VAULT_ID='default' # optional |
| 16 | # Repo-root .env is loaded automatically (set -a source). If URL is unset but BACKUP_USER_ID is set, |
| 17 | # URL defaults from hub/icp/canister_ids.json (same as npm run canister:release-prep). |
| 18 | # |
| 19 | # If dfx crashes on "ColorOutOfRange", upgrade dfx or try another terminal; or run checks only: |
| 20 | # SKIP_DFX_BUILD=1 ./scripts/canister-predeploy.sh |
| 21 | # |
| 22 | # dfx build defaults to the **local** network; this repo only lists mainnet in canister_ids.json, |
| 23 | # so without a local `dfx canister create hub` you get "Cannot find canister id". Preflight uses |
| 24 | # **ic** by default. Override: DFX_PREFLIGHT_NETWORK=local (after `dfx start` + `dfx canister create hub`). |
| 25 | # |
| 26 | set -euo pipefail |
| 27 | |
| 28 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 29 | REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 30 | cd "$REPO_ROOT" |
| 31 | |
| 32 | export NO_COLOR="${NO_COLOR:-}" |
| 33 | export CI="${CI:-}" |
| 34 | export TERM="${TERM:-}" |
| 35 | |
| 36 | if [[ -f "$REPO_ROOT/.env" ]]; then |
| 37 | echo "==> Loading repo-root .env (backup env + tools)" |
| 38 | set -a |
| 39 | # shellcheck disable=SC1091 |
| 40 | source "$REPO_ROOT/.env" |
| 41 | set +a |
| 42 | fi |
| 43 | |
| 44 | # Same default as canister-release-prep: export needs only BACKUP_USER_ID for preflight backups. |
| 45 | if [[ -n "${KNOWTATION_CANISTER_BACKUP_USER_ID:-}" && -z "${KNOWTATION_CANISTER_URL:-}" ]]; then |
| 46 | echo "==> Defaulting KNOWTATION_CANISTER_URL from hub/icp/canister_ids.json (set KNOWTATION_CANISTER_URL to override)" |
| 47 | KNOWTATION_CANISTER_URL="$( |
| 48 | node -e " |
| 49 | const fs = require('fs'); |
| 50 | const j = JSON.parse(fs.readFileSync('hub/icp/canister_ids.json', 'utf8')); |
| 51 | const id = j.hub && j.hub.ic; |
| 52 | if (!id) throw new Error('Missing hub.ic in canister_ids.json'); |
| 53 | process.stdout.write('https://' + id + '.icp0.io'); |
| 54 | " |
| 55 | )" |
| 56 | export KNOWTATION_CANISTER_URL |
| 57 | echo " Using: $KNOWTATION_CANISTER_URL" |
| 58 | fi |
| 59 | |
| 60 | echo "==> [1/4] Migration / stable-shape contract (Node)" |
| 61 | node "$REPO_ROOT/scripts/verify-canister-migration.mjs" |
| 62 | |
| 63 | if [[ "${SKIP_NPM_TEST:-}" != "1" ]]; then |
| 64 | echo "==> [2/4] npm test (set SKIP_NPM_TEST=1 to skip)" |
| 65 | npm test |
| 66 | else |
| 67 | echo "==> [2/4] npm test SKIPPED (SKIP_NPM_TEST=1)" |
| 68 | fi |
| 69 | |
| 70 | DFX_PREFLIGHT_NETWORK="${DFX_PREFLIGHT_NETWORK:-ic}" |
| 71 | echo "==> [3/4] dfx build hub (--network $DFX_PREFLIGHT_NETWORK)" |
| 72 | ICP_DIR="$REPO_ROOT/hub/icp" |
| 73 | if [[ "${SKIP_DFX_BUILD:-}" == "1" ]]; then |
| 74 | echo " SKIPPED (SKIP_DFX_BUILD=1) — run 'cd hub/icp && dfx build hub --network ic' before mainnet deploy." |
| 75 | else |
| 76 | if ! command -v dfx >/dev/null 2>&1; then |
| 77 | echo "ERROR: dfx not on PATH. Install the IC SDK: https://internetcomputer.org/docs/current/developer-docs/setup/install" |
| 78 | exit 1 |
| 79 | fi |
| 80 | if ! ( cd "$ICP_DIR" && dfx build hub --network "$DFX_PREFLIGHT_NETWORK" ); then |
| 81 | echo "ERROR: dfx build failed. If you see 'ColorOutOfRange', update dfx or use SKIP_DFX_BUILD=1 after building in a working environment." |
| 82 | echo " If you see 'Cannot find canister id' on network local, run: cd hub/icp && dfx canister create hub" |
| 83 | echo " Or preflight against mainnet id: DFX_PREFLIGHT_NETWORK=ic npm run canister:preflight" |
| 84 | exit 1 |
| 85 | fi |
| 86 | WASM_OUT="$ICP_DIR/.dfx/$DFX_PREFLIGHT_NETWORK/canisters/hub/hub.wasm" |
| 87 | if [[ -f "$WASM_OUT" ]]; then |
| 88 | echo " Built wasm: $WASM_OUT ($(wc -c < "$WASM_OUT" | tr -d ' ') bytes)" |
| 89 | else |
| 90 | echo "WARN: Expected wasm not found at $WASM_OUT (dfx output layout may differ)." |
| 91 | fi |
| 92 | fi |
| 93 | |
| 94 | echo "==> [4/4] Optional canister export backup" |
| 95 | if [[ -n "${KNOWTATION_CANISTER_BACKUP_USER_ID:-}" ]]; then |
| 96 | bash "$SCRIPT_DIR/canister-export-backup.sh" |
| 97 | else |
| 98 | echo " Skipped (set KNOWTATION_CANISTER_BACKUP_USER_ID to export; URL defaults from hub/icp/canister_ids.json if omitted)" |
| 99 | fi |
| 100 | |
| 101 | echo "" |
| 102 | echo "canister-predeploy: OK. Next (you run manually): cd hub/icp && dfx deploy --network ic" |
| 103 | echo "Read docs/HOSTED-STORAGE-BILLING-ROADMAP.md before changing stable types." |
File History
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
1 day ago