From 48214d1ae59422f1c49d7f27e8f50144cf6e0789 Mon Sep 17 00:00:00 2001 From: Juraj Simon Date: Mon, 29 Jul 2024 15:11:05 +0200 Subject: [PATCH] chore: update bundle --- dist/index.js | 64 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/dist/index.js b/dist/index.js index a841c13..2188779 100644 --- a/dist/index.js +++ b/dist/index.js @@ -128323,7 +128323,7 @@ const exec = __nccwpck_require__(71514); const cache = __nccwpck_require__(27799); const core = __nccwpck_require__(42186); const tc = __nccwpck_require__(27784); -const { readFileSync } = __nccwpck_require__(57147); +const { readFileSync, existsSync, unlinkSync } = __nccwpck_require__(57147); const os = __nccwpck_require__(22037); const path = __nccwpck_require__(71017); const { DefaultArtifactClient } = __nccwpck_require__(79450); @@ -128336,16 +128336,25 @@ const EXIT_CODE_LEAKS_DETECTED = 2; // or use the latest version of gitleaks if GITLEAKS_VERSION is not specified. // This function will also cache the downloaded gitleaks binary in the tool cache. async function Install(version) { - const pathToInstall = path.join(os.tmpdir(), `gitleaks-${version}`); + const pathToInstall = path.join(os.tmpdir(), `gitleaks-${version}-${os.userInfo().username}`); core.info( `Version to install: ${version} (target directory: ${pathToInstall})` ); + + if (existsSync(pathToInstall)) { + core.info(`Gitleaks already installed, skipping installation`); + core.addPath(pathToInstall); + return; + } else { + core.info(`Gitleaks install dir ${pathToInstall} not found, checking github cache...`); + } + const cacheKey = `gitleaks-cache-${version}-${process.platform}-${process.arch}`; let restoredFromCache = undefined; try { restoredFromCache = await cache.restoreCache([pathToInstall], cacheKey); } catch (error) { - core.warning(error); + core.warning(`Unable to restore from cache: ${error.message}`); } if (restoredFromCache !== undefined) { @@ -128356,31 +128365,44 @@ async function Install(version) { process.arch, version ); - core.info(`Downloading gitleaks from ${gitleaksReleaseURL}`); - let downloadPath = ""; - try { - downloadPath = await tc.downloadTool( - gitleaksReleaseURL, - path.join(os.tmpdir(), `gitleaks.tmp`) - ); - } catch (error) { - core.error( - `could not install gitleaks from ${gitleaksReleaseURL}, error: ${error}` - ); + + const tempPath = path.join(os.tmpdir(), `gitleaks-${version}-${os.userInfo().username}.tmp`); + + if (!existsSync(tempPath)) { + core.info(`Downloading gitleaks from ${gitleaksReleaseURL}...`); + let downloadPath = ""; + try { + downloadPath = await tc.downloadTool( + gitleaksReleaseURL, + tempPath + ); + } catch (error) { + core.setFailed( + `could not install gitleaks from ${gitleaksReleaseURL}, error: ${error.message}` + ); + return; + } + + core.info(`Extracting gitleaks from ${downloadPath}`); + if (gitleaksReleaseURL.endsWith(".zip")) { + await tc.extractZip(downloadPath, pathToInstall); + } else if (gitleaksReleaseURL.endsWith(".tar.gz")) { + await tc.extractTar(downloadPath, pathToInstall); + } else { + core.error(`Unsupported archive format: ${gitleaksReleaseURL}`); + } } - if (gitleaksReleaseURL.endsWith(".zip")) { - await tc.extractZip(downloadPath, pathToInstall); - } else if (gitleaksReleaseURL.endsWith(".tar.gz")) { - await tc.extractTar(downloadPath, pathToInstall); - } else { - core.error(`Unsupported archive format: ${gitleaksReleaseURL}`); + //cleanup + if (existsSync(tempPath)) { + unlinkSync(tempPath); } try { await cache.saveCache([pathToInstall], cacheKey); + core.info(`Gitleaks cached under key: ${cacheKey}`); } catch (error) { - core.warning(error); + core.warning(`Unable to save cache: ${error.message}`); } }