fix(cache): make tar scratch cleanup best-effort
Log scratch-directory cleanup failures without replacing a successful archive read or the original tool error. Keep scratch ownership in execReadCommands and cover both outcomes for extraction and listing.
This commit is contained in:
1 parent
cd705bb67f
commit
3607dcfa49
2 files changed
+33
No files matched your search
@@ -1,4 +1,6 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
|
import * as io from '@actions/io'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as tar from '../src/internal/tar'
|
import * as tar from '../src/internal/tar'
|
||||||
@@ -178,6 +180,32 @@ describeWindows.each([
|
|||||||
expectCleanScratch()
|
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']>([
|
test.each<[Operation, 'decompress' | 'tar']>([
|
||||||
['extract', 'decompress'],
|
['extract', 'decompress'],
|
||||||
['extract', 'tar'],
|
['extract', 'tar'],
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
import {exec} from '@actions/exec'
|
import {exec} from '@actions/exec'
|
||||||
import * as io from '@actions/io'
|
import * as io from '@actions/io'
|
||||||
import {existsSync, writeFileSync} from 'fs'
|
import {existsSync, writeFileSync} from 'fs'
|
||||||
@@ -286,7 +287,11 @@ async function execReadCommands(
|
|||||||
await execCommands(commands, tempDirectory)
|
await execCommands(commands, tempDirectory)
|
||||||
} finally {
|
} finally {
|
||||||
if (tempDirectory) {
|
if (tempDirectory) {
|
||||||
|
try {
|
||||||
await io.rmRF(tempDirectory)
|
await io.rmRF(tempDirectory)
|
||||||
|
} catch (error) {
|
||||||
|
core.debug(`Failed to delete temporary tar directory: ${error}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user