From c93af4c99354f1d4212ce8c8b2cb26df1eca4057 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 17 Jun 2025 07:54:22 +0200 Subject: [PATCH] feat: display module ID in upgrade confirm --- .../upgrade/upgrade-assert.services.ts | 7 ++-- .../upgrade.mission-control.services.ts | 9 +++- .../upgrade/upgrade.orbiter.services.ts | 10 +++-- .../upgrade/upgrade.satellite.services.ts | 42 ++++++++++++++----- .../modules/upgrade/upgrade.services.ts | 18 +++++--- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/src/services/modules/upgrade/upgrade-assert.services.ts b/src/services/modules/upgrade/upgrade-assert.services.ts index c770d809..dd94b911 100644 --- a/src/services/modules/upgrade/upgrade-assert.services.ts +++ b/src/services/modules/upgrade/upgrade-assert.services.ts @@ -1,6 +1,6 @@ import {isNullish} from '@dfinity/utils'; import {satelliteBuildType, type SatelliteParameters} from '@junobuild/admin'; -import {cyan, yellow} from 'kleur'; +import {cyan, magenta, yellow} from 'kleur'; import type {AssertWasmModule, UpgradeWasm} from '../../../types/upgrade'; import {isHeadless} from '../../../utils/process.utils'; import {NEW_CMD_LINE, confirmAndExit} from '../../../utils/prompt.utils'; @@ -59,10 +59,11 @@ export const assertSatelliteBuildType = async ({ }; export const assertUpgradeHash = async ({ + moduleId, hash, reset -}: Required>) => { +}: Required> & {moduleId: string}) => { await confirmAndExit( - `The Wasm hash for the upgrade is ${cyan(hash)}.${NEW_CMD_LINE}Start upgrade${reset ? ' and reset' : ''} now?` + `Upgrade module ${cyan(moduleId)} with Wasm hash ${magenta(hash)}${NEW_CMD_LINE}Start upgrade${reset ? ' and reset' : ''} now?` ); }; diff --git a/src/services/modules/upgrade/upgrade.mission-control.services.ts b/src/services/modules/upgrade/upgrade.mission-control.services.ts index 0d2d2564..2f0a1933 100644 --- a/src/services/modules/upgrade/upgrade.mission-control.services.ts +++ b/src/services/modules/upgrade/upgrade.mission-control.services.ts @@ -14,6 +14,9 @@ import {NEW_CMD_LINE} from '../../../utils/prompt.utils'; import {logUpgradeResult, readUpgradeOptions} from '../../../utils/upgrade.utils'; import {selectVersion, upgradeWasmJunoCdn, upgradeWasmLocal} from './upgrade.services'; +type MissionControl = Omit & + Required>; + export const upgradeMissionControl = async (args?: string[]) => { const missionControl = await getCliMissionControl(); @@ -56,7 +59,7 @@ const updateMissionControlRelease = async ({ missionControlParameters }: { args?: string[]; - missionControlParameters: MissionControlParameters; + missionControlParameters: MissionControl; }): Promise<{success: boolean; err?: unknown}> => { const currentVersion = await missionControlVersion({ missionControl: missionControlParameters @@ -87,6 +90,7 @@ const updateMissionControlRelease = async ({ return await upgradeWasmJunoCdn({ version, assetKey: 'mission_control', + moduleId: missionControlParameters.missionControlId, upgrade: upgradeMissionControlWasm }); }; @@ -95,7 +99,7 @@ const upgradeMissionControlCustom = async ({ missionControlParameters, args }: { - missionControlParameters: MissionControlParameters; + missionControlParameters: MissionControl; args?: string[]; }): Promise<{success: boolean; err?: unknown}> => { const src = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); @@ -119,6 +123,7 @@ const upgradeMissionControlCustom = async ({ return await upgradeWasmLocal({ src, assetKey: 'mission_control', + moduleId: missionControlParameters.missionControlId, upgrade: upgradeMissionControlWasm }); }; diff --git a/src/services/modules/upgrade/upgrade.orbiter.services.ts b/src/services/modules/upgrade/upgrade.orbiter.services.ts index 449d3c9b..4f345883 100644 --- a/src/services/modules/upgrade/upgrade.orbiter.services.ts +++ b/src/services/modules/upgrade/upgrade.orbiter.services.ts @@ -19,6 +19,9 @@ import { upgradeWasmLocal } from './upgrade.services'; +type Orbiter = Required> & + Omit; + export const upgradeOrbiters = async (args?: string[]) => { const authOrbiters = await getCliOrbiters(); @@ -59,7 +62,7 @@ const upgradeOrbiterCustom = async ({ orbiterParameters, args }: { - orbiterParameters: OrbiterParameters; + orbiterParameters: Orbiter; args?: string[]; }): Promise<{success: boolean; err?: unknown}> => { const src = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); @@ -86,6 +89,7 @@ const upgradeOrbiterCustom = async ({ return await upgradeWasmLocal({ src, assetKey: 'orbiter', + moduleId: orbiterParameters.orbiterId, upgrade: upgradeOrbiterWasm, reset }); @@ -94,8 +98,7 @@ const upgradeOrbiterCustom = async ({ const updateOrbiterRelease = async ({ args, ...orbiterParameters -}: Required> & - Omit & {args?: string[]}): Promise<{ +}: Orbiter & {args?: string[]}): Promise<{ success: boolean; err?: unknown; }> => { @@ -131,6 +134,7 @@ const updateOrbiterRelease = async ({ return await upgradeWasmJunoCdn({ version, assetKey: 'orbiter', + moduleId: orbiterParameters.orbiterId, upgrade: upgradeOrbiterWasm, reset }); diff --git a/src/services/modules/upgrade/upgrade.satellite.services.ts b/src/services/modules/upgrade/upgrade.satellite.services.ts index abfc7314..459942df 100644 --- a/src/services/modules/upgrade/upgrade.satellite.services.ts +++ b/src/services/modules/upgrade/upgrade.satellite.services.ts @@ -28,6 +28,9 @@ import { upgradeWasmLocal } from './upgrade.services'; +type Satellite = Omit & + Required>; + export const upgradeSatellite = async (args?: string[]) => { const {satellite} = await assertConfigAndLoadSatelliteContext(); const {satelliteId} = satellite; @@ -56,7 +59,7 @@ const upgradeSatelliteCustom = async ({ satellite, args }: { - satellite: SatelliteParameters; + satellite: Satellite; args?: string[]; }): Promise<{success: boolean; err?: unknown}> => { const src = nextArg({args, option: '-s'}) ?? nextArg({args, option: '--src'}); @@ -74,36 +77,50 @@ const upgradeSatelliteCustom = async ({ export const upgradeSatelliteWithSrc = async ({ src, + satellite, ...rest }: { - satellite: SatelliteParameters; + satellite: Satellite; src: string; args?: string[]; }): Promise<{success: boolean; err?: unknown}> => { const upgrade = async (params: UpgradeWasmParams): Promise<{success: boolean; err?: unknown}> => { - return await upgradeWasmLocal({src, assetKey: 'satellite', ...params}); + return await upgradeWasmLocal({ + src, + assetKey: 'satellite', + moduleId: satellite.satelliteId, + ...params + }); }; return await upgradeSatelliteWithUpgradeFn({ ...rest, + satellite, upgradeFn: upgrade }); }; export const upgradeSatelliteWithCdn = async ({ cdn, + satellite, ...rest }: { - satellite: SatelliteParameters; + satellite: Satellite; cdn: UpgradeCdn; args?: string[]; }): Promise<{success: boolean; err?: unknown}> => { const upgrade = async (params: UpgradeWasmParams): Promise<{success: boolean; err?: unknown}> => { - return await upgradeWasmCdn({cdn, assetKey: 'satellite', ...params}); + return await upgradeWasmCdn({ + cdn, + assetKey: 'satellite', + moduleId: satellite.satelliteId, + ...params + }); }; return await upgradeSatelliteWithUpgradeFn({ ...rest, + satellite, upgradeFn: upgrade }); }; @@ -113,7 +130,7 @@ const upgradeSatelliteWithUpgradeFn = async ({ args, upgradeFn }: { - satellite: SatelliteParameters; + satellite: Satellite; args?: string[]; upgradeFn: (params: UpgradeWasmParams) => Promise<{success: boolean; err?: unknown}>; }): Promise<{success: boolean; err?: unknown}> => { @@ -138,14 +155,14 @@ const upgradeSatelliteRelease = async ({ satellite, args }: { - satellite: SatelliteParameters; + satellite: Satellite; args?: string[]; }): Promise<{success: boolean; err?: unknown}> => { const currentVersion = await satelliteVersion({ satellite }); - const displayHint = `satellite "${await satelliteKey(satellite.satelliteId ?? '')}"`; + const displayHint = `satellite "${await satelliteKey(satellite.satelliteId)}"`; const version = await selectVersion({currentVersion, assetKey: SATELLITE_WASM_NAME, displayHint}); if (isNullish(version)) { @@ -155,7 +172,12 @@ const upgradeSatelliteRelease = async ({ const {noSnapshot, preClearChunks} = readUpgradeOptions(args); const upgrade = async (params: UpgradeWasmParams): Promise<{success: boolean; err?: unknown}> => { - return await upgradeWasmJunoCdn({version, assetKey: 'satellite', ...params}); + return await upgradeWasmJunoCdn({ + version, + assetKey: 'satellite', + moduleId: satellite.satelliteId, + ...params + }); }; return await executeUpgradeSatellite({ @@ -176,7 +198,7 @@ const executeUpgradeSatellite = async ({ preClearChunks, noSnapshot }: { - satellite: SatelliteParameters; + satellite: Satellite; args?: string[]; currentVersion: string; preClearChunks: boolean; diff --git a/src/services/modules/upgrade/upgrade.services.ts b/src/services/modules/upgrade/upgrade.services.ts index a2ec49e1..3cc91f26 100644 --- a/src/services/modules/upgrade/upgrade.services.ts +++ b/src/services/modules/upgrade/upgrade.services.ts @@ -29,12 +29,13 @@ const executeUpgradeWasm = async ({ hash, assert, reset = false, - assetKey -}: {assetKey: AssetKey} & UpgradeWasm) => { + assetKey, + moduleId +}: {assetKey: AssetKey; moduleId: string} & UpgradeWasm) => { await assert?.({wasmModule: wasm}); if (isNotHeadless()) { - await assertUpgradeHash({hash, reset}); + await assertUpgradeHash({hash, reset, moduleId}); } console.log(''); @@ -87,10 +88,12 @@ export const upgradeWasmLocal = async ({ upgrade, reset, assert, - assetKey + assetKey, + moduleId }: { src: string; assetKey: AssetKey; + moduleId: string; } & UpgradeWasmParams): Promise<{ success: boolean; err?: unknown; @@ -111,7 +114,7 @@ export const upgradeWasmLocal = async ({ spinner.stop(); - await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, assetKey}); + await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, assetKey, moduleId}); return {success: true}; } catch (err: unknown) { @@ -128,6 +131,7 @@ export const upgradeWasmJunoCdn = async ({ }: { version: string; assetKey: AssetKey; + moduleId: string; cdn?: UpgradeCdn; } & UpgradeWasmParams): Promise<{ success: boolean; @@ -147,12 +151,14 @@ export const upgradeWasmJunoCdn = async ({ export const upgradeWasmCdn = async ({ assetKey, + moduleId, upgrade, assert, reset, cdn }: { assetKey: AssetKey; + moduleId: string; cdn: UpgradeCdn; } & UpgradeWasmParams): Promise<{ success: boolean; @@ -187,7 +193,7 @@ export const upgradeWasmCdn = async ({ spinner.stop(); - await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, assetKey}); + await executeUpgradeWasm({upgrade, wasm, hash, reset, assert, assetKey, moduleId}); return {success: true}; } catch (err: unknown) {