mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-06 01:53:16 +08:00
Add an option to specify retention days for artifacts (#575)
* Add an option to specify retention days for artifacts * Validate against settings exposed as env var to give early feedback * Fix lint * Add tests and addressing feedback * Update packages/artifact/__tests__/upload.test.ts Co-authored-by: Konrad Pabjan <konradpabjan@github.com> * Update packages/artifact/README.md Co-authored-by: Konrad Pabjan <konradpabjan@github.com> * Update packages/artifact/src/internal/utils.ts Co-authored-by: Konrad Pabjan <konradpabjan@github.com> * Update packages/artifact/__tests__/util.test.ts Co-authored-by: Konrad Pabjan <konradpabjan@github.com> Co-authored-by: Konrad Pabjan <konradpabjan@github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {debug, info} from '@actions/core'
|
||||
import {debug, info, warning} from '@actions/core'
|
||||
import {promises as fs} from 'fs'
|
||||
import {HttpCodes, HttpClient} from '@actions/http-client'
|
||||
import {BearerCredentialHandler} from '@actions/http-client/auth'
|
||||
@@ -302,3 +302,24 @@ export async function createEmptyFilesForArtifact(
|
||||
await (await fs.open(filePath, 'w')).close()
|
||||
}
|
||||
}
|
||||
|
||||
export function getProperRetention(
|
||||
retentionInput: number,
|
||||
retentionSetting: string | undefined
|
||||
): number {
|
||||
if (retentionInput < 0) {
|
||||
throw new Error('Invalid retention, minimum value is 1.')
|
||||
}
|
||||
|
||||
let retention = retentionInput
|
||||
if (retentionSetting) {
|
||||
const maxRetention = parseInt(retentionSetting)
|
||||
if (!isNaN(maxRetention) && maxRetention < retention) {
|
||||
warning(
|
||||
`Retention days is greater than the max value allowed by the repository setting, reduce retention to ${maxRetention} days`
|
||||
)
|
||||
retention = maxRetention
|
||||
}
|
||||
}
|
||||
return retention
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user