Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache nuclei to toolcache dir. #57

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6799,7 +6799,13 @@ async function getLatestInfo() {
async function downloadAndInstall(selectedVersion) {
const toolName = "nuclei";
const latest = await getLatestInfo();
const version = selectedVersion ? selectedVersion : latest.tag_name.replace(/v/g, '');
const version = selectedVersion ? selectedVersion : latest.tag_name.replace(/v/g, '');

let cachedPath = tool_cache.find(toolName, version);
let binPath = `${cachedPath}/${toolName}`;
if (external_fs_default().existsSync(binPath)) {
return binPath
}

core.startGroup(`Download and install Nuclei ${version}`);

Expand All @@ -6818,7 +6824,9 @@ async function downloadAndInstall(selectedVersion) {
throw new Error("Unable to extract Nuclei.");
}

const binPath = `${installDir}/${toolName}`
cachedPath = await tool_cache.cacheFile(`${installDir}/${toolName}`, toolName, toolName, version);
binPath = `${cachedPath}/${toolName}`;

external_fs_default().chmodSync(binPath, "777");

core.info(`Nuclei ${version} was successfully installed to ${installDir}.`);
Expand Down Expand Up @@ -10791,6 +10799,7 @@ async function run() {
}

// run tool
delete process.env.GITHUB_TOKEN
exec.exec(binPath, params, options);
} catch (error) {
core.setFailed(error.message);
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function run() {
}

// run tool
delete process.env.GITHUB_TOKEN
exec.exec(binPath, params, options);
} catch (error) {
core.setFailed(error.message);
Expand Down
11 changes: 10 additions & 1 deletion src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ async function getLatestInfo() {
export async function downloadAndInstall(selectedVersion) {
const toolName = "nuclei";
const latest = await getLatestInfo();

const version = selectedVersion ? selectedVersion : latest.tag_name.replace(/v/g, '');

let cachedPath = tc.find(toolName, version);
let binPath = `${cachedPath}/${toolName}`;
if (fs.existsSync(binPath)) {
return binPath
}

core.startGroup(`Download and install Nuclei ${version}`);

const packageName = getPackage();
Expand All @@ -56,7 +63,9 @@ export async function downloadAndInstall(selectedVersion) {
throw new Error("Unable to extract Nuclei.");
}

const binPath = `${installDir}/${toolName}`
cachedPath = await tc.cacheFile(`${installDir}/${toolName}`, toolName, toolName, version);
binPath = `${cachedPath}/${toolName}`;

fs.chmodSync(binPath, "777");

core.info(`Nuclei ${version} was successfully installed to ${installDir}.`);
Expand Down