Skip to content

Commit 91df900

Browse files
Copilotpelikhan
andauthored
fix: derive asset dir from GH_AW_AGENT_OUTPUT instead of RUNNER_TEMP in upload_assets
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 2a7fd2b commit 91df900

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

actions/setup/js/upload_assets.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ async function main() {
8686

8787
core.info(`Found ${uploadItems.length} upload-asset item(s)`);
8888

89-
const assetsDir = path.join(process.env.RUNNER_TEMP || "/tmp", "gh-aw", "safeoutputs", "assets");
89+
// Derive the base directory from GH_AW_AGENT_OUTPUT when available.
90+
// In the upload_assets job, the agent artifact (including safeoutputs/assets/)
91+
// is downloaded to the same parent directory as agent_output.json, which may
92+
// differ from RUNNER_TEMP when the download path is explicitly set to /tmp/gh-aw/.
93+
const agentOutputFile = process.env.GH_AW_AGENT_OUTPUT;
94+
const baseDir = agentOutputFile ? path.dirname(agentOutputFile) : path.join(process.env.RUNNER_TEMP || "/tmp", "gh-aw");
95+
const assetsDir = path.join(baseDir, "safeoutputs", "assets");
9096
let uploadCount = 0;
9197
let missingAssetCount = 0;
9298
let hasChanges = false;

actions/setup/js/upload_assets.test.cjs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ import path from "path";
44
const mockCore = { debug: vi.fn(), info: vi.fn(), notice: vi.fn(), warning: vi.fn(), error: vi.fn(), setFailed: vi.fn(), setOutput: vi.fn(), summary: { addRaw: vi.fn().mockReturnThis(), write: vi.fn().mockResolvedValue(void 0) } };
55
((global.core = mockCore),
66
describe("upload_assets.cjs", () => {
7-
let uploadAssetsScript, mockExec, tempFilePath;
7+
let uploadAssetsScript, mockExec, tempFilePath, tempBase;
88
const setAgentOutput = data => {
9-
tempFilePath = path.join("/tmp", `test_agent_output_${Date.now()}_${Math.random().toString(36).slice(2)}.json`);
9+
tempFilePath = path.join(tempBase, "agent_output.json");
1010
const content = "string" == typeof data ? data : JSON.stringify(data);
1111
(fs.writeFileSync(tempFilePath, content), (process.env.GH_AW_AGENT_OUTPUT = tempFilePath));
1212
},
13-
getAssetsDir = () => path.join(process.env.RUNNER_TEMP || "/tmp", "gh-aw", "safeoutputs", "assets"),
13+
getAssetsDir = () => path.join(tempBase, "safeoutputs", "assets"),
1414
executeScript = async () => ((global.core = mockCore), (global.exec = mockExec), await eval(`(async () => { ${uploadAssetsScript}; await main(); })()`));
1515
(beforeEach(() => {
1616
(vi.clearAllMocks(), delete process.env.GH_AW_ASSETS_BRANCH, delete process.env.GH_AW_AGENT_OUTPUT, delete process.env.GH_AW_SAFE_OUTPUTS_STAGED);
17+
tempBase = fs.mkdtempSync(path.join("/tmp", "test-gh-aw-"));
1718
const scriptPath = path.join(__dirname, "upload_assets.cjs");
1819
((uploadAssetsScript = fs.readFileSync(scriptPath, "utf8")), (mockExec = { exec: vi.fn().mockResolvedValue(0) }));
1920
}),
2021
afterEach(() => {
21-
tempFilePath && fs.existsSync(tempFilePath) && fs.unlinkSync(tempFilePath);
22+
tempBase && fs.existsSync(tempBase) && fs.rmSync(tempBase, { recursive: !0, force: !0 });
23+
tempBase = void 0;
24+
tempFilePath = void 0;
2225
}),
2326
describe("git commit command - vulnerability fix", () => {
2427
it("should not wrap commit message in extra quotes to prevent command injection", async () => {
@@ -138,13 +141,11 @@ const mockCore = { debug: vi.fn(), info: vi.fn(), notice: vi.fn(), warning: vi.f
138141
fs.existsSync("test.png") && fs.unlinkSync("test.png"));
139142
}));
140143
describe("missing asset handling", () => {
141-
it("should skip missing assets while uploading present assets from RUNNER_TEMP", async () => {
144+
it("should skip missing assets while uploading present assets", async () => {
142145
process.env.GH_AW_ASSETS_BRANCH = "assets/test-workflow";
143146
process.env.GH_AW_SAFE_OUTPUTS_STAGED = "false";
144-
const runnerTempDir = fs.mkdtempSync(path.join("/tmp", "upload-assets-runner-temp-"));
145-
process.env.RUNNER_TEMP = runnerTempDir;
146-
const assetDir = path.join(runnerTempDir, "gh-aw", "safeoutputs", "assets");
147-
fs.mkdirSync(assetDir, { recursive: !0 });
147+
const assetDir = getAssetsDir();
148+
fs.existsSync(assetDir) || fs.mkdirSync(assetDir, { recursive: !0 });
148149
const presentAssetSourcePath = path.join(assetDir, "present.png");
149150
fs.writeFileSync(presentAssetSourcePath, "present content");
150151
const crypto = require("crypto"),
@@ -172,8 +173,6 @@ const mockCore = { debug: vi.fn(), info: vi.fn(), notice: vi.fn(), warning: vi.f
172173
uploadCountCall && expect(uploadCountCall[1]).toBe("1");
173174
fs.existsSync(presentAssetSourcePath) && fs.unlinkSync(presentAssetSourcePath);
174175
fs.existsSync(path.join(process.cwd(), presentTargetFile)) && fs.unlinkSync(path.join(process.cwd(), presentTargetFile));
175-
fs.rmSync(runnerTempDir, { recursive: !0, force: !0 });
176-
delete process.env.RUNNER_TEMP;
177176
});
178177
});
179178
}));

0 commit comments

Comments
 (0)