Skip to content

Commit

Permalink
suffix download tmp file with version. delete tmp file after extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjur committed Feb 13, 2024
1 parent cb7149a commit 6a81b92
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/gitleaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const exec = require("@actions/exec");
const cache = require("@actions/cache");
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
const { readFileSync } = require("fs");
const { readFileSync, existsSync, unlinkSync } = require("fs");
const os = require("os");
const path = require("path");
const artifact = require("@actions/artifact");
Expand Down Expand Up @@ -45,22 +45,25 @@ async function Install(version) {
try {
downloadPath = await tc.downloadTool(
gitleaksReleaseURL,
path.join(os.tmpdir(), `gitleaks.tmp`)
path.join(os.tmpdir(), `gitleaks-${version}.tmp`)
);
} catch (error) {
core.error(
`could not install gitleaks from ${gitleaksReleaseURL}, error: ${error}`
);
}

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 (existsSync(downloadPath)) {
unlinkSync(downloadPath);
}
try {
await cache.saveCache([pathToInstall], cacheKey);
} catch (error) {
Expand Down

0 comments on commit 6a81b92

Please sign in to comment.