Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for pulumi in the tool cache #1025

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 21 additions & 10 deletions src/libs/pulumi-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const platform = getPlatform();
core.debug(`Platform: ${platform}`);
Expand Down Expand Up @@ -96,6 +108,13 @@ export async function downloadCli(range: string): Promise<void> {
}
}

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}`);
Expand Down Expand Up @@ -158,18 +177,10 @@ export async function downloadCli(range: string): Promise<void> {
}
}

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);
}