Skip to content

Commit 4453ce6

Browse files
authored
Add an option to skip the tool-cache (#343)
It turns out that the tool-cache is adding almost a minute to every installation (even more on Windows), when the installation itself is only 10-20s. This introduces an option to disable the cache so we can feed it through to the other actions.
1 parent c8764a6 commit 4453ce6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/index.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export async function isAuthenticated(): Promise<boolean> {
165165
* specification is installed.
166166
* @returns The path of the installed tool.
167167
*/
168-
export async function installGcloudSDK(version: string): Promise<string> {
168+
export async function installGcloudSDK(version: string, skipToolCache?: boolean): Promise<string> {
169169
// Retrieve the release corresponding to the specified version and OS
170170
const osPlat = os.platform();
171171
const osArch = os.arch();
@@ -180,12 +180,24 @@ export async function installGcloudSDK(version: string): Promise<string> {
180180
throw new Error(`Failed to download release, url: ${url}`);
181181
}
182182

183-
// Install the downloaded release into the github action env
184-
const toolRoot = path.join(extPath, 'google-cloud-sdk');
185-
let toolPath = await toolCache.cacheDir(toolRoot, 'gcloud', resolvedVersion);
186-
toolPath = path.join(toolPath, 'bin');
187-
core.addPath(toolPath);
188-
return toolPath;
183+
// Either cache the tool or just add it directly to the path.
184+
if (skipToolCache) {
185+
// Caching the tool on disk takes a really long time, and it's not clear
186+
// whether it's even valuable since it's ONLY cached on disk on the runner.
187+
// For GitHub-managed runners, that is useless since they are ephemeral.
188+
//
189+
// See https://github.com/google-github-actions/setup-gcloud/issues/701 for
190+
// discussion, but it's actually faster to skip the caching and just add the
191+
// tool directly to the path.
192+
const toolRoot = path.join(extPath, 'google-cloud-sdk');
193+
core.addPath(path.join(toolRoot, 'bin'));
194+
return toolRoot;
195+
} else {
196+
const toolRoot = path.join(extPath, 'google-cloud-sdk');
197+
const cachedToolRoot = await toolCache.cacheDir(toolRoot, 'gcloud', resolvedVersion, osArch);
198+
core.addPath(path.join(cachedToolRoot, 'bin'));
199+
return cachedToolRoot;
200+
}
189201
}
190202

191203
/**

0 commit comments

Comments
 (0)