@@ -3767,7 +3767,7 @@ class DefaultArtifactClient {
37673767 }
37683768 else {
37693769 // Create an entry for the artifact in the file container
3770- const response = yield uploadHttpClient . createArtifactInFileContainer ( name ) ;
3770+ const response = yield uploadHttpClient . createArtifactInFileContainer ( name , options ) ;
37713771 if ( ! response . fileContainerResourceUrl ) {
37723772 core . debug ( response . toString ( ) ) ;
37733773 throw new Error ( 'No URL provided by the Artifact Service to upload an artifact to' ) ;
@@ -4019,6 +4019,9 @@ function run() {
40194019 const options = {
40204020 continueOnError : false
40214021 } ;
4022+ if ( inputs . retentionDays ) {
4023+ options . retentionDays = inputs . retentionDays ;
4024+ }
40224025 const uploadResponse = yield artifactClient . uploadArtifact ( inputs . artifactName , searchResult . filesToUpload , searchResult . rootDirectory , options ) ;
40234026 if ( uploadResponse . failedItems . length > 0 ) {
40244027 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() {
41084111 return workspaceDirectory ;
41094112}
41104113exports . getWorkSpaceDirectory = getWorkSpaceDirectory ;
4114+ function getRetentionDays ( ) {
4115+ return process . env [ 'GITHUB_RETENTION_DAYS' ] ;
4116+ }
4117+ exports . getRetentionDays = getRetentionDays ;
41114118//# sourceMappingURL=config-variables.js.map
41124119
41134120/***/ } ) ,
@@ -6390,11 +6397,19 @@ function getInputs() {
63906397 if ( ! noFileBehavior ) {
63916398 core . setFailed ( `Unrecognized ${ constants_1 . Inputs . IfNoFilesFound } input. Provided: ${ ifNoFilesFound } . Available options: ${ Object . keys ( constants_1 . NoFileOptions ) } ` ) ;
63926399 }
6393- return {
6400+ const inputs = {
63946401 artifactName : name ,
63956402 searchPath : path ,
63966403 ifNoFilesFound : noFileBehavior
63976404 } ;
6405+ const retentionDaysStr = core . getInput ( constants_1 . Inputs . RetentionDays ) ;
6406+ if ( retentionDaysStr ) {
6407+ inputs . retentionDays = parseInt ( retentionDaysStr ) ;
6408+ if ( isNaN ( inputs . retentionDays ) ) {
6409+ core . setFailed ( 'Invalid retention-days' ) ;
6410+ }
6411+ }
6412+ return inputs ;
63986413}
63996414exports . getInputs = getInputs ;
64006415
@@ -6666,12 +6681,17 @@ class UploadHttpClient {
66666681 * @param {string } artifactName Name of the artifact being created
66676682 * @returns The response from the Artifact Service if the file container was successfully created
66686683 */
6669- createArtifactInFileContainer ( artifactName ) {
6684+ createArtifactInFileContainer ( artifactName , options ) {
66706685 return __awaiter ( this , void 0 , void 0 , function * ( ) {
66716686 const parameters = {
66726687 Type : 'actions_storage' ,
66736688 Name : artifactName
66746689 } ;
6690+ // calculate retention period
6691+ if ( options && options . retentionDays ) {
6692+ const maxRetentionStr = config_variables_1 . getRetentionDays ( ) ;
6693+ parameters . RetentionDays = utils_1 . getProperRetention ( options . retentionDays , maxRetentionStr ) ;
6694+ }
66756695 const data = JSON . stringify ( parameters , null , 2 ) ;
66766696 const artifactUrl = utils_1 . getArtifactUrl ( ) ;
66776697 // use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
@@ -7314,6 +7334,7 @@ var Inputs;
73147334 Inputs [ "Name" ] = "name" ;
73157335 Inputs [ "Path" ] = "path" ;
73167336 Inputs [ "IfNoFilesFound" ] = "if-no-files-found" ;
7337+ Inputs [ "RetentionDays" ] = "retention-days" ;
73177338} ) ( Inputs = exports . Inputs || ( exports . Inputs = { } ) ) ;
73187339var NoFileOptions ;
73197340( function ( NoFileOptions ) {
@@ -8137,6 +8158,21 @@ function createEmptyFilesForArtifact(emptyFilesToCreate) {
81378158 } ) ;
81388159}
81398160exports . createEmptyFilesForArtifact = createEmptyFilesForArtifact ;
8161+ function getProperRetention ( retentionInput , retentionSetting ) {
8162+ if ( retentionInput < 0 ) {
8163+ throw new Error ( 'Invalid retention, minimum value is 1.' ) ;
8164+ }
8165+ let retention = retentionInput ;
8166+ if ( retentionSetting ) {
8167+ const maxRetention = parseInt ( retentionSetting ) ;
8168+ if ( ! isNaN ( maxRetention ) && maxRetention < retention ) {
8169+ core_1 . warning ( `Retention days is greater than the max value allowed by the repository setting, reduce retention to ${ maxRetention } days` ) ;
8170+ retention = maxRetention ;
8171+ }
8172+ }
8173+ return retention ;
8174+ }
8175+ exports . getProperRetention = getProperRetention ;
81408176//# sourceMappingURL=utils.js.map
81418177
81428178/***/ } ) ,
0 commit comments