Skip to content

Commit

Permalink
fix: fix exec
Browse files Browse the repository at this point in the history
  • Loading branch information
swarit-pandey committed Sep 10, 2024
1 parent 9a39c8b commit 81f7924
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
import * as artifact from "@actions/artifact";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import {
ENCODING,
IS_GITHUB_ACTIONS,
Expand Down Expand Up @@ -102,29 +103,31 @@ function stopKnoxctlScan(): void {
try {
process.kill(Number(pid), "SIGINT");
log("Sent SIGINT signal to knoxctl scan process");
await new Promise((resolve) => setTimeout(resolve, 5000));
try {
process.kill(Number(pid), 0);
log("Process is still running. Attempting to force kill...");
process.kill(Number(pid), "SIGKILL");
} catch (error) {
log("knoxctl scan process has been terminated");
}
fs.unlinkSync(pidFile);
log("Removed PID file");

// Change permissions of output files
const outputDir = getOutputDir();
log(`Changing permissions of output files in ${outputDir}`);
try {
await exec.exec(`sudo chown -R $(id -u):$(id -g) ${outputDir}`);
log("Successfully changed ownership of output files");
} catch (error) {
log(
`Failed to change ownership of output files: ${error instanceof Error ? error.message : String(error)}`,
"warning",
);
}
setTimeout(() => {
try {
process.kill(Number(pid), 0);
log("Process is still running. Attempting to force kill...");
process.kill(Number(pid), "SIGKILL");
} catch (error) {
log("knoxctl scan process has been terminated");
}
fs.unlinkSync(pidFile);
log("Removed PID file");

// Change ownership of output files
const outputDir = getOutputDir();
exec
.exec(`sudo chown -R $(id -u):$(id -g) ${outputDir}`)
.then(() => {
log("Changed ownership of output files");
})
.catch((error) => {
log(
`Failed to change ownership of output files: ${error instanceof Error ? error.message : String(error)}`,
"warning",
);
});
}, 5000);
} catch (error) {
log(
`Failed to stop knoxctl scan process: ${error instanceof Error ? error.message : String(error)}`,
Expand Down

0 comments on commit 81f7924

Please sign in to comment.