From 4b293b76fe7d1ec89678312e28c6a57671e2ec33 Mon Sep 17 00:00:00 2001 From: Yur Timenkov Date: Mon, 9 Oct 2023 14:50:37 +0200 Subject: [PATCH 1/2] Search for pulumi in the tool cache --- src/libs/pulumi-cli.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/libs/pulumi-cli.ts b/src/libs/pulumi-cli.ts index e6c0d122..33d8061f 100644 --- a/src/libs/pulumi-cli.ts +++ b/src/libs/pulumi-cli.ts @@ -55,6 +55,18 @@ export function getPlatform(): string | undefined { return platforms[`${runnerPlatform}-${runnerArch}`]; } +async function exportFromCache(cachedPath: string, expectedVersion: string) { + core.addPath(cachedPath); + + // Check that running pulumi now returns a version we expect + const versionExec = await exec.exec(`pulumi`, ['version'], true); + const pulumiVersion = versionExec.stdout.trim(); + core.debug(`Running pulumi verison returned: ${pulumiVersion}`); + if (!semver.satisfies(pulumiVersion, expectedVersion)) { + throw new Error('Installed version did not satisfy the resolved version'); + } +} + export async function downloadCli(range: string): Promise { const platform = getPlatform(); core.debug(`Platform: ${platform}`); @@ -96,6 +108,13 @@ export async function downloadCli(range: string): Promise { } } + let cachedPath = tc.find('pulumi', range); + if (cachedPath) { + core.info('Found Pulumi in the tool cache'); + await exportFromCache(cachedPath, range); + return; + } + const { version, downloads } = await getVersionObject(range); core.info(`Matched version: ${version}`); @@ -158,18 +177,10 @@ export async function downloadCli(range: string): Promise { } } - const cachedPath = await tc.cacheDir( + cachedPath = await tc.cacheDir( path.join(destination, 'bin'), 'pulumi', version, ); - core.addPath(cachedPath); - - // Check that running pulumi now returns a version we expect - const versionExec = await exec.exec(`pulumi`, ['version'], true); - const pulumiVersion = versionExec.stdout.trim(); - core.debug(`Running pulumi verison returned: ${pulumiVersion}`); - if (!semver.satisfies(pulumiVersion, version)) { - throw new Error('Installed version did not satisfy the resolved version'); - } + await exportFromCache(cachedPath, version); } From 4d70d7c73a887ccad36466aa096c60a00887fbaa Mon Sep 17 00:00:00 2001 From: Yur Timenkov Date: Mon, 9 Oct 2023 16:19:42 +0200 Subject: [PATCH 2/2] Updated changelog with PR number. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d82c619..bef68537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ **(none)** +- feat: Search for pulumi in the tool cache + ([#1025](https://github.com/pulumi/actions/pull/1025)) + --- ## 4.6.0 (2023-10-12)