@@ -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,16 @@ 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+ }
6409+ return inputs ;
63986410}
63996411exports . getInputs = getInputs ;
64006412
@@ -6666,12 +6678,17 @@ class UploadHttpClient {
66666678 * @param {string } artifactName Name of the artifact being created
66676679 * @returns The response from the Artifact Service if the file container was successfully created
66686680 */
6669- createArtifactInFileContainer ( artifactName ) {
6681+ createArtifactInFileContainer ( artifactName , options ) {
66706682 return __awaiter ( this , void 0 , void 0 , function * ( ) {
66716683 const parameters = {
66726684 Type : 'actions_storage' ,
66736685 Name : artifactName
66746686 } ;
6687+ // calculate retention period
6688+ if ( options && options . retentionDays ) {
6689+ const maxRetentionStr = config_variables_1 . getRetentionDays ( ) ;
6690+ parameters . RetentionDays = utils_1 . getProperRetention ( options . retentionDays , maxRetentionStr ) ;
6691+ }
66756692 const data = JSON . stringify ( parameters , null , 2 ) ;
66766693 const artifactUrl = utils_1 . getArtifactUrl ( ) ;
66776694 // use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
@@ -7314,6 +7331,7 @@ var Inputs;
73147331 Inputs [ "Name" ] = "name" ;
73157332 Inputs [ "Path" ] = "path" ;
73167333 Inputs [ "IfNoFilesFound" ] = "if-no-files-found" ;
7334+ Inputs [ "RetentionDays" ] = "retention-days" ;
73177335} ) ( Inputs = exports . Inputs || ( exports . Inputs = { } ) ) ;
73187336var NoFileOptions ;
73197337( function ( NoFileOptions ) {
@@ -8137,6 +8155,21 @@ function createEmptyFilesForArtifact(emptyFilesToCreate) {
81378155 } ) ;
81388156}
81398157exports . createEmptyFilesForArtifact = createEmptyFilesForArtifact ;
8158+ function getProperRetention ( retentionInput , retentionSetting ) {
8159+ if ( retentionInput < 0 ) {
8160+ throw new Error ( 'Invalid retention, minimum value is 1.' ) ;
8161+ }
8162+ let retention = retentionInput ;
8163+ if ( retentionSetting ) {
8164+ const maxRetention = parseInt ( retentionSetting ) ;
8165+ if ( ! isNaN ( maxRetention ) && maxRetention < retention ) {
8166+ core_1 . warning ( `Retention days is greater than the max value allowed by the repository setting, reduce retention to ${ maxRetention } days` ) ;
8167+ retention = maxRetention ;
8168+ }
8169+ }
8170+ return retention ;
8171+ }
8172+ exports . getProperRetention = getProperRetention ;
81408173//# sourceMappingURL=utils.js.map
81418174
81428175/***/ } ) ,
0 commit comments