Skip to content

Commit

Permalink
chore: update bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjur committed Jul 29, 2024
1 parent 4210f9e commit 48214d1
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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}`);
}
}

Expand Down

0 comments on commit 48214d1

Please sign in to comment.