Make artifact retention configurable

- Added a new `artifact-retention-days` input parameter to control retention of uploaded artifacts
- Artifacts retention will use repository settings if not overridden.
This commit is contained in:
Daz DeBoer 2023-11-09 08:06:31 +01:00 committed by GitHub
parent f757bcfd86
commit 9bca466e27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 94 additions and 12 deletions

View file

@ -54,6 +54,11 @@ inputs:
# gradle-home-cache-excludes: |
# caches/build-cache-1
gradle-home-cache-cleanup:
description: When 'true', the action will attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
required: false
default: false
arguments:
description: Gradle command line arguments (supports multi-line input)
required: false
@ -68,6 +73,10 @@ inputs:
required: false
default: 'disabled'
artifact-retention-days:
description: Specifies the number of days to retain any artifacts generated by the action. If not set, the default retention settings for the repository will apply.
required: false
# EXPERIMENTAL & INTERNAL ACTION INPUTS
# The following action properties allow fine-grained tweaking of the action caching behaviour.
# These properties are experimental and not (yet) designed for production use, and may change without notice in a subsequent release of `gradle-build-action`.
@ -80,10 +89,6 @@ inputs:
description: Used to uniquely identify the current job invocation. Defaults to the matrix values for this job; this should not be overridden by users (INTERNAL).
required: false
default: ${{ toJSON(matrix) }}
gradle-home-cache-cleanup:
description: When 'true', the action will attempt to remove any stale/unused entries from the Gradle User Home prior to saving to the GitHub Actions cache.
required: false
default: false
github-token:
description: The GitHub token used to authenticate when submitting via the Dependency Submission API.

22
dist/main/index.js vendored
View file

@ -93671,7 +93671,9 @@ function uploadDependencyGraphs() {
const relativeGraphFiles = graphFiles.map(x => getRelativePathFromWorkspace(x));
core.info(`Uploading dependency graph files: ${relativeGraphFiles}`);
const artifactClient = artifact.create();
artifactClient.uploadArtifact(DEPENDENCY_GRAPH_ARTIFACT, graphFiles, workspaceDirectory);
artifactClient.uploadArtifact(DEPENDENCY_GRAPH_ARTIFACT, graphFiles, workspaceDirectory, {
retentionDays: (0, input_params_1.getArtifactRetentionDays)()
});
return graphFiles;
});
}
@ -93979,7 +93981,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DependencyGraphOption = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(2186));
const string_argv_1 = __nccwpck_require__(9663);
function isCacheDisabled() {
@ -94066,6 +94068,22 @@ function getDependencyGraphOption() {
throw TypeError(`The value '${val} is not valid for 'dependency-graph. Valid values are: [disabled, generate-and-upload, generate-and-submit, download-and-submit]. The default value is 'disabled'.`);
}
exports.getDependencyGraphOption = getDependencyGraphOption;
function getArtifactRetentionDays() {
const val = core.getInput('artifact-retention-days');
return parseNumericInput('artifact-retention-days', val, 0);
}
exports.getArtifactRetentionDays = getArtifactRetentionDays;
function parseNumericInput(paramName, paramValue, paramDefault) {
if (paramValue.length === 0) {
return paramDefault;
}
const numericValue = parseInt(paramValue);
if (isNaN(numericValue)) {
throw TypeError(`The value '${paramValue}' is not a valid numeric value for '${paramName}'.`);
}
return numericValue;
}
exports.parseNumericInput = parseNumericInput;
function getBooleanInput(paramName, paramDefault = false) {
const paramValue = core.getInput(paramName);
switch (paramValue.toLowerCase().trim()) {

File diff suppressed because one or more lines are too long

22
dist/post/index.js vendored
View file

@ -93671,7 +93671,9 @@ function uploadDependencyGraphs() {
const relativeGraphFiles = graphFiles.map(x => getRelativePathFromWorkspace(x));
core.info(`Uploading dependency graph files: ${relativeGraphFiles}`);
const artifactClient = artifact.create();
artifactClient.uploadArtifact(DEPENDENCY_GRAPH_ARTIFACT, graphFiles, workspaceDirectory);
artifactClient.uploadArtifact(DEPENDENCY_GRAPH_ARTIFACT, graphFiles, workspaceDirectory, {
retentionDays: (0, input_params_1.getArtifactRetentionDays)()
});
return graphFiles;
});
}
@ -93847,7 +93849,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DependencyGraphOption = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.DependencyGraphOption = exports.parseNumericInput = exports.getArtifactRetentionDays = exports.getDependencyGraphOption = exports.isDependencyGraphEnabled = exports.isJobSummaryEnabled = exports.getGithubToken = exports.getJobMatrix = exports.getArguments = exports.getGradleExecutable = exports.getGradleVersion = exports.getBuildRootDirectory = exports.getCacheExcludes = exports.getCacheIncludes = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheStrictMatch = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(2186));
const string_argv_1 = __nccwpck_require__(9663);
function isCacheDisabled() {
@ -93934,6 +93936,22 @@ function getDependencyGraphOption() {
throw TypeError(`The value '${val} is not valid for 'dependency-graph. Valid values are: [disabled, generate-and-upload, generate-and-submit, download-and-submit]. The default value is 'disabled'.`);
}
exports.getDependencyGraphOption = getDependencyGraphOption;
function getArtifactRetentionDays() {
const val = core.getInput('artifact-retention-days');
return parseNumericInput('artifact-retention-days', val, 0);
}
exports.getArtifactRetentionDays = getArtifactRetentionDays;
function parseNumericInput(paramName, paramValue, paramDefault) {
if (paramValue.length === 0) {
return paramDefault;
}
const numericValue = parseInt(paramValue);
if (isNaN(numericValue)) {
throw TypeError(`The value '${paramValue}' is not a valid numeric value for '${paramName}'.`);
}
return numericValue;
}
exports.parseNumericInput = parseNumericInput;
function getBooleanInput(paramName, paramDefault = false) {
const paramValue = core.getInput(paramName);
switch (paramValue.toLowerCase().trim()) {

File diff suppressed because one or more lines are too long

View file

@ -11,7 +11,7 @@ import * as path from 'path'
import fs from 'fs'
import * as layout from './repository-layout'
import {DependencyGraphOption, getJobMatrix} from './input-params'
import {DependencyGraphOption, getJobMatrix, getArtifactRetentionDays} from './input-params'
const DEPENDENCY_GRAPH_ARTIFACT = 'dependency-graph'
@ -60,7 +60,9 @@ async function uploadDependencyGraphs(): Promise<string[]> {
core.info(`Uploading dependency graph files: ${relativeGraphFiles}`)
const artifactClient = artifact.create()
artifactClient.uploadArtifact(DEPENDENCY_GRAPH_ARTIFACT, graphFiles, workspaceDirectory)
artifactClient.uploadArtifact(DEPENDENCY_GRAPH_ARTIFACT, graphFiles, workspaceDirectory, {
retentionDays: getArtifactRetentionDays()
})
return graphFiles
}

View file

@ -88,6 +88,23 @@ export function getDependencyGraphOption(): DependencyGraphOption {
)
}
export function getArtifactRetentionDays(): number {
const val = core.getInput('artifact-retention-days')
return parseNumericInput('artifact-retention-days', val, 0)
// Zero indicates that the default repository settings should be used
}
export function parseNumericInput(paramName: string, paramValue: string, paramDefault: number): number {
if (paramValue.length === 0) {
return paramDefault
}
const numericValue = parseInt(paramValue)
if (isNaN(numericValue)) {
throw TypeError(`The value '${paramValue}' is not a valid numeric value for '${paramName}'.`)
}
return numericValue
}
function getBooleanInput(paramName: string, paramDefault = false): boolean {
const paramValue = core.getInput(paramName)
switch (paramValue.toLowerCase().trim()) {

View file

@ -0,0 +1,22 @@
import * as inputParams from '../../src/input-params'
describe('input params', () => {
describe('parses numeric input', () => {
it('uses default value', () => {
const val = inputParams.parseNumericInput('param-name', '', 88)
expect(val).toBe(88)
})
it('parses numeric input', () => {
const val = inputParams.parseNumericInput('param-name', '34', 88)
expect(val).toBe(34)
})
it('fails on non-numeric input', () => {
const t = () => {
inputParams.parseNumericInput('param-name', 'xyz', 88)
};
expect(t).toThrow(TypeError)
expect(t).toThrow("The value 'xyz' is not a valid numeric value for 'param-name'.")
})
})
})