From 3bd996fb725ccf90aa76e8629931767a2307245a Mon Sep 17 00:00:00 2001 From: Wires77 Date: Sat, 18 Apr 2026 10:02:19 -0500 Subject: [PATCH] fix #729: Remove archive after extraction (#792) * fix #729: Remove archive after extraction Almost all uses of this action that will be extracting a release archive will not need the archive after the fact, so I opted to not put this behind a flag option. * Move extraction info log after file removal * Remove unwanted async from rm, fix tests --------- Co-authored-by: Robin Raju --- __tests__/unarchive.test.ts | 4 +++- src/unarchive.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/__tests__/unarchive.test.ts b/__tests__/unarchive.test.ts index 73b1da6..b173e5b 100644 --- a/__tests__/unarchive.test.ts +++ b/__tests__/unarchive.test.ts @@ -36,8 +36,10 @@ describe('extract', () => { test('extracts a tar.gz archive into a created destination directory', async () => { const destination = path.join(testRoot, 'tar-gz-output') + const archivePath = path.join(testRoot, 'tar-zip-ball-only-repo.tar.gz') + fs.copyFileSync(fixturePath('tar-zip-ball-only-repo.tar.gz'), archivePath) - await extract(fixturePath('tar-zip-ball-only-repo.tar.gz'), destination) + await extract(archivePath, destination) expect(fs.existsSync(destination)).toBe(true) expect(fs.readdirSync(destination).length).toBeGreaterThan(0) diff --git a/src/unarchive.ts b/src/unarchive.ts index bf7b1d2..a9f9294 100644 --- a/src/unarchive.ts +++ b/src/unarchive.ts @@ -50,6 +50,14 @@ export const extract = async ( await zip.extract(null, destDir) await zip.close() } + + fs.rm(filePath, err => { + if (err) { + core.warning( + `Failed to delete archive ${filename} after extraction: ${err.message}` + ) + } + }) core.info(`Extracted ${filename} to ${destDir}`) } catch (err) { // Provide context for extraction failures