diff --git a/__tests__/tarConcurrency.test.ts b/__tests__/tarConcurrency.test.ts index 0d84d89..b9ebde5 100644 --- a/__tests__/tarConcurrency.test.ts +++ b/__tests__/tarConcurrency.test.ts @@ -1,4 +1,6 @@ +import * as core from '@actions/core' import * as exec from '@actions/exec' +import * as io from '@actions/io' import * as fs from 'fs' import * as path from 'path' import * as tar from '../src/internal/tar' @@ -178,6 +180,32 @@ describeWindows.each([ expectCleanScratch() }) + test.each<[Operation, boolean]>([ + ['extract', false], + ['extract', true], + ['list', false], + ['list', true] + ])( + 'preserves the %s result when cleanup fails (command fails=%s)', + async (operation, commandFails) => { + const debugMock = jest.spyOn(core, 'debug').mockImplementation(() => {}) + jest + .spyOn(io, 'rmRF') + .mockRejectedValue(new Error('simulated cleanup failure')) + failStage = commandFails ? 'tar' : undefined + + const result = readers[operation](archives[0], compression) + if (commandFails) { + await expect(result).rejects.toThrow('simulated tar failure') + } else { + await expect(result).resolves.toBeUndefined() + } + expect(debugMock).toHaveBeenCalledWith( + expect.stringContaining('simulated cleanup failure') + ) + } + ) + test.each<[Operation, 'decompress' | 'tar']>([ ['extract', 'decompress'], ['extract', 'tar'], diff --git a/src/internal/tar.ts b/src/internal/tar.ts index 7b8d81a..cad3ac6 100644 --- a/src/internal/tar.ts +++ b/src/internal/tar.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core' import {exec} from '@actions/exec' import * as io from '@actions/io' import {existsSync, writeFileSync} from 'fs' @@ -286,7 +287,11 @@ async function execReadCommands( await execCommands(commands, tempDirectory) } finally { if (tempDirectory) { - await io.rmRF(tempDirectory) + try { + await io.rmRF(tempDirectory) + } catch (error) { + core.debug(`Failed to delete temporary tar directory: ${error}`) + } } } }