Skip to content

Commit

Permalink
Make artifact retention configurable
Browse files Browse the repository at this point in the history
- Added a new `artifact-retention-days` input parameter to control retention of uploaded artifacts
- Artifacts retention will use repository settings if not overridden.
  • Loading branch information
bigdaz authored Nov 9, 2023
1 parent f757bcf commit 9bca466
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 12 deletions.
13 changes: 9 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.
Expand All @@ -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.
Expand Down
22 changes: 20 additions & 2 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/dependency-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions src/input-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
22 changes: 22 additions & 0 deletions test/jest/input-params.test.ts
Original file line number Diff line number Diff line change
@@ -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'.")
})
})
})

0 comments on commit 9bca466

Please # to comment.