Add GitHub Actions tool cache support (#76)

Signed-off-by: Michi U. <4169888+michemache@users.noreply.github.com>
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
Co-authored-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
Michi U.andDiogenes Fernandes authored and GitHub committed 2026-01-13 17:20:26 -03:00
1 parent e95ccdd206
commit 274fe8537f
5 files changed
+132 -5

No files matched your search

+17 -2
View File
@@ -133,6 +133,7 @@ async function run () {
const credentialsHostname = core.getInput('cli_config_credentials_hostname');
const credentialsToken = core.getInput('cli_config_credentials_token');
const wrapper = core.getInput('tofu_wrapper') === 'true';
const useCache = core.getInput('cache') === 'true';
let githubToken = core.getInput('github_token');
if (githubToken === '' && !(process.env.FORGEJO_ACTIONS || process.env.GITEA_ACTIONS)) {
// Only default to the environment variable when running in GitHub Actions. Don't do this for other CI systems
@@ -174,8 +175,22 @@ async function run () {
throw new Error(`OpenTofu version ${version} not available for ${platform} and ${arch}`);
}
// Download requested version
const pathToCLI = await downloadAndExtractCLI(build.url);
// Download requested version if not cached
let pathToCLI;
if (useCache) {
const cachedPath = tc.find('tofu', release.version, arch);
if (cachedPath) {
core.debug(`Using cached OpenTofu version ${release.version} from ${cachedPath}`);
pathToCLI = cachedPath;
} else {
core.debug(`OpenTofu version ${release.version} not found in cache, downloading...`);
const extractedPath = await downloadAndExtractCLI(build.url);
core.debug(`Caching OpenTofu version ${release.version} to tool cache`);
pathToCLI = await tc.cacheDir(extractedPath, 'tofu', release.version, arch);
}
} else {
pathToCLI = await downloadAndExtractCLI(build.url);
}
// Install our wrapper
if (wrapper) {