Skip to content

Commit d92b019

Browse files
Copilotpelikhan
andauthored
fix: use sudo rm -rf in post.js to handle root-owned files in /tmp/gh-aw
Files written by Docker containers or privileged scripts during the job are owned by root, causing fs.rmSync to fail with EACCES. GitHub-hosted runners have passwordless sudo, so try `sudo rm -rf` first and fall back to fs.rmSync for self-hosted runners without sudo. Agent-Logs-Url: https://github.com/github/gh-aw/sessions/4905a7a0-58f6-4f2f-b856-8cae909dc609 Co-authored-by: pelikhan <[email protected]>
1 parent 6a4781d commit d92b019

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

actions/setup/post.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@
22
// Removes the /tmp/gh-aw/ directory created during the main action step.
33
// Runs in the post-job phase so that temporary files are erased after the
44
// workflow job completes, regardless of success or failure.
5+
//
6+
// Files inside /tmp/gh-aw/ may be owned by root (written by Docker containers
7+
// or privileged scripts), so we use `sudo rm -rf` — GitHub-hosted runners have
8+
// passwordless sudo. We fall back to fs.rmSync for self-hosted runners that
9+
// don't have sudo but do have direct write access.
510

11+
const { spawnSync } = require("child_process");
612
const fs = require("fs");
713

814
const tmpDir = "/tmp/gh-aw";
915

10-
try {
11-
console.log(`Cleaning up ${tmpDir}...`);
12-
fs.rmSync(tmpDir, { recursive: true, force: true });
16+
console.log(`Cleaning up ${tmpDir}...`);
17+
18+
// Try sudo rm -rf first (handles root-owned files on GitHub-hosted runners)
19+
const result = spawnSync("sudo", ["rm", "-rf", tmpDir], { stdio: "inherit" });
20+
21+
if (result.status === 0) {
1322
console.log(`Cleaned up ${tmpDir}`);
14-
} catch (err) {
15-
// Log but do not fail — cleanup is best-effort
16-
console.error(`Warning: failed to clean up ${tmpDir}: ${err.message}`);
23+
} else {
24+
// Fall back to fs.rmSync for environments without sudo
25+
try {
26+
fs.rmSync(tmpDir, { recursive: true, force: true });
27+
console.log(`Cleaned up ${tmpDir}`);
28+
} catch (err) {
29+
// Log but do not fail — cleanup is best-effort
30+
console.error(`Warning: failed to clean up ${tmpDir}: ${err.message}`);
31+
}
1732
}

0 commit comments

Comments
 (0)