mirror of
https://code.forgejo.org/forgejo/upload-artifact.git
synced 2024-11-22 08:22:40 +00:00
Add an option to specify retention period
This commit is contained in:
parent
58740802ef
commit
59018c2f85
8 changed files with 66 additions and 10 deletions
|
@ -17,6 +17,12 @@ inputs:
|
||||||
error: Fail the action with an error message
|
error: Fail the action with an error message
|
||||||
ignore: Do not output any warnings or errors, the action does not fail
|
ignore: Do not output any warnings or errors, the action does not fail
|
||||||
default: 'warn'
|
default: 'warn'
|
||||||
|
retention-days:
|
||||||
|
description: >
|
||||||
|
Duration after which artifact will expire in days. 0 means using default retention.
|
||||||
|
|
||||||
|
Minimum 1 day.
|
||||||
|
Maximum 90 days unless changed from the repository settings page.
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
39
dist/index.js
vendored
39
dist/index.js
vendored
|
@ -3767,7 +3767,7 @@ class DefaultArtifactClient {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create an entry for the artifact in the file container
|
// Create an entry for the artifact in the file container
|
||||||
const response = yield uploadHttpClient.createArtifactInFileContainer(name);
|
const response = yield uploadHttpClient.createArtifactInFileContainer(name, options);
|
||||||
if (!response.fileContainerResourceUrl) {
|
if (!response.fileContainerResourceUrl) {
|
||||||
core.debug(response.toString());
|
core.debug(response.toString());
|
||||||
throw new Error('No URL provided by the Artifact Service to upload an artifact to');
|
throw new Error('No URL provided by the Artifact Service to upload an artifact to');
|
||||||
|
@ -4019,6 +4019,9 @@ function run() {
|
||||||
const options = {
|
const options = {
|
||||||
continueOnError: false
|
continueOnError: false
|
||||||
};
|
};
|
||||||
|
if (inputs.retentionDays) {
|
||||||
|
options.retentionDays = inputs.retentionDays;
|
||||||
|
}
|
||||||
const uploadResponse = yield artifactClient.uploadArtifact(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options);
|
const uploadResponse = yield artifactClient.uploadArtifact(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options);
|
||||||
if (uploadResponse.failedItems.length > 0) {
|
if (uploadResponse.failedItems.length > 0) {
|
||||||
core.setFailed(`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
|
core.setFailed(`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
|
||||||
|
@ -4108,6 +4111,10 @@ function getWorkSpaceDirectory() {
|
||||||
return workspaceDirectory;
|
return workspaceDirectory;
|
||||||
}
|
}
|
||||||
exports.getWorkSpaceDirectory = getWorkSpaceDirectory;
|
exports.getWorkSpaceDirectory = getWorkSpaceDirectory;
|
||||||
|
function getRetentionDays() {
|
||||||
|
return process.env['GITHUB_RETENTION_DAYS'];
|
||||||
|
}
|
||||||
|
exports.getRetentionDays = getRetentionDays;
|
||||||
//# sourceMappingURL=config-variables.js.map
|
//# sourceMappingURL=config-variables.js.map
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -6390,11 +6397,16 @@ function getInputs() {
|
||||||
if (!noFileBehavior) {
|
if (!noFileBehavior) {
|
||||||
core.setFailed(`Unrecognized ${constants_1.Inputs.IfNoFilesFound} input. Provided: ${ifNoFilesFound}. Available options: ${Object.keys(constants_1.NoFileOptions)}`);
|
core.setFailed(`Unrecognized ${constants_1.Inputs.IfNoFilesFound} input. Provided: ${ifNoFilesFound}. Available options: ${Object.keys(constants_1.NoFileOptions)}`);
|
||||||
}
|
}
|
||||||
return {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName: name,
|
||||||
searchPath: path,
|
searchPath: path,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior
|
||||||
};
|
};
|
||||||
|
const retentionDaysStr = core.getInput(constants_1.Inputs.RetentionDays);
|
||||||
|
if (retentionDaysStr) {
|
||||||
|
inputs.retentionDays = parseInt(retentionDaysStr);
|
||||||
|
}
|
||||||
|
return inputs;
|
||||||
}
|
}
|
||||||
exports.getInputs = getInputs;
|
exports.getInputs = getInputs;
|
||||||
|
|
||||||
|
@ -6666,12 +6678,17 @@ class UploadHttpClient {
|
||||||
* @param {string} artifactName Name of the artifact being created
|
* @param {string} artifactName Name of the artifact being created
|
||||||
* @returns The response from the Artifact Service if the file container was successfully created
|
* @returns The response from the Artifact Service if the file container was successfully created
|
||||||
*/
|
*/
|
||||||
createArtifactInFileContainer(artifactName) {
|
createArtifactInFileContainer(artifactName, options) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const parameters = {
|
const parameters = {
|
||||||
Type: 'actions_storage',
|
Type: 'actions_storage',
|
||||||
Name: artifactName
|
Name: artifactName
|
||||||
};
|
};
|
||||||
|
// calculate retention period
|
||||||
|
if (options && options.retentionDays) {
|
||||||
|
const maxRetentionStr = config_variables_1.getRetentionDays();
|
||||||
|
parameters.RetentionDays = utils_1.getProperRetention(options.retentionDays, maxRetentionStr);
|
||||||
|
}
|
||||||
const data = JSON.stringify(parameters, null, 2);
|
const data = JSON.stringify(parameters, null, 2);
|
||||||
const artifactUrl = utils_1.getArtifactUrl();
|
const artifactUrl = utils_1.getArtifactUrl();
|
||||||
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
|
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
|
||||||
|
@ -7314,6 +7331,7 @@ var Inputs;
|
||||||
Inputs["Name"] = "name";
|
Inputs["Name"] = "name";
|
||||||
Inputs["Path"] = "path";
|
Inputs["Path"] = "path";
|
||||||
Inputs["IfNoFilesFound"] = "if-no-files-found";
|
Inputs["IfNoFilesFound"] = "if-no-files-found";
|
||||||
|
Inputs["RetentionDays"] = "retention-days";
|
||||||
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
})(Inputs = exports.Inputs || (exports.Inputs = {}));
|
||||||
var NoFileOptions;
|
var NoFileOptions;
|
||||||
(function (NoFileOptions) {
|
(function (NoFileOptions) {
|
||||||
|
@ -8137,6 +8155,21 @@ function createEmptyFilesForArtifact(emptyFilesToCreate) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.createEmptyFilesForArtifact = createEmptyFilesForArtifact;
|
exports.createEmptyFilesForArtifact = createEmptyFilesForArtifact;
|
||||||
|
function getProperRetention(retentionInput, retentionSetting) {
|
||||||
|
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) {
|
||||||
|
core_1.warning(`Retention days is greater than the max value allowed by the repository setting, reduce retention to ${maxRetention} days`);
|
||||||
|
retention = maxRetention;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retention;
|
||||||
|
}
|
||||||
|
exports.getProperRetention = getProperRetention;
|
||||||
//# sourceMappingURL=utils.js.map
|
//# sourceMappingURL=utils.js.map
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -5,9 +5,9 @@
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/artifact": {
|
"@actions/artifact": {
|
||||||
"version": "0.3.5",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/artifact/-/artifact-0.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/artifact/-/artifact-0.4.0.tgz",
|
||||||
"integrity": "sha512-y27pBEnUjOqCP2zUf86YkiqGOp1r0C9zUOmGmcxizsHMls0wvk+FJwd+l8JIoukvj1BeBHYP+c+9AEqOt5AqMA==",
|
"integrity": "sha512-iPDMvCIogq22F3r11xyBbH2wtUuJYfa3llGM8Kxilx6lVrcGpWa5Bnb1ukD/MEmCn9SBXdz6eqNLa10GQ20HNg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/core": "^1.2.1",
|
"@actions/core": "^1.2.1",
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/actions/upload-artifact#readme",
|
"homepage": "https://github.com/actions/upload-artifact#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/artifact": "^0.3.5",
|
"@actions/artifact": "^0.4.0",
|
||||||
"@actions/core": "^1.2.3",
|
"@actions/core": "^1.2.3",
|
||||||
"@actions/glob": "^0.1.0",
|
"@actions/glob": "^0.1.0",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
export enum Inputs {
|
export enum Inputs {
|
||||||
Name = 'name',
|
Name = 'name',
|
||||||
Path = 'path',
|
Path = 'path',
|
||||||
IfNoFilesFound = 'if-no-files-found'
|
IfNoFilesFound = 'if-no-files-found',
|
||||||
|
RetentionDays = 'retention-days'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum NoFileOptions {
|
export enum NoFileOptions {
|
||||||
|
|
|
@ -22,9 +22,16 @@ export function getInputs(): UploadInputs {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
const inputs = {
|
||||||
artifactName: name,
|
artifactName: name,
|
||||||
searchPath: path,
|
searchPath: path,
|
||||||
ifNoFilesFound: noFileBehavior
|
ifNoFilesFound: noFileBehavior
|
||||||
|
} as UploadInputs
|
||||||
|
|
||||||
|
const retentionDaysStr = core.getInput(Inputs.RetentionDays)
|
||||||
|
if (retentionDaysStr) {
|
||||||
|
inputs.retentionDays = parseInt(retentionDaysStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return inputs
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,10 @@ async function run(): Promise<void> {
|
||||||
const options: UploadOptions = {
|
const options: UploadOptions = {
|
||||||
continueOnError: false
|
continueOnError: false
|
||||||
}
|
}
|
||||||
|
if (inputs.retentionDays) {
|
||||||
|
options.retentionDays = inputs.retentionDays
|
||||||
|
}
|
||||||
|
|
||||||
const uploadResponse = await artifactClient.uploadArtifact(
|
const uploadResponse = await artifactClient.uploadArtifact(
|
||||||
inputs.artifactName,
|
inputs.artifactName,
|
||||||
searchResult.filesToUpload,
|
searchResult.filesToUpload,
|
||||||
|
|
|
@ -15,4 +15,9 @@ export interface UploadInputs {
|
||||||
* The desired behavior if no files are found with the provided search path
|
* The desired behavior if no files are found with the provided search path
|
||||||
*/
|
*/
|
||||||
ifNoFilesFound: NoFileOptions
|
ifNoFilesFound: NoFileOptions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duration after which artifact will expire in days
|
||||||
|
*/
|
||||||
|
retentionDays: number
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue