5793b08cd9
* `@actions/artifact`: convert to an ESM module * Update the package-lock.json * Undo the GHES ignores * Fix the reference to `@actions/http-client` in the lock file * Bump `@actions/core` to `3.0.0` * Remove `jest.config.cjs` * Import `OctoKitOptions` from `@octokit/core/types` * Pull the package version from `package.json` * Workaround getting the package version for the user-agent * Fix the `archiver` import * Fix linting
35 lines
944 B
TypeScript
35 lines
944 B
TypeScript
import {Timestamp} from '../../generated/index.js'
|
|
import * as core from '@actions/core'
|
|
|
|
export function getExpiration(retentionDays?: number): Timestamp | undefined {
|
|
if (!retentionDays) {
|
|
return undefined
|
|
}
|
|
|
|
const maxRetentionDays = getRetentionDays()
|
|
if (maxRetentionDays && maxRetentionDays < retentionDays) {
|
|
core.warning(
|
|
`Retention days cannot be greater than the maximum allowed retention set within the repository. Using ${maxRetentionDays} instead.`
|
|
)
|
|
retentionDays = maxRetentionDays
|
|
}
|
|
|
|
const expirationDate = new Date()
|
|
expirationDate.setDate(expirationDate.getDate() + retentionDays)
|
|
|
|
return Timestamp.fromDate(expirationDate)
|
|
}
|
|
|
|
function getRetentionDays(): number | undefined {
|
|
const retentionDays = process.env['GITHUB_RETENTION_DAYS']
|
|
if (!retentionDays) {
|
|
return undefined
|
|
}
|
|
const days = parseInt(retentionDays)
|
|
if (isNaN(days)) {
|
|
return undefined
|
|
}
|
|
|
|
return days
|
|
}
|