From 3ac861d89663708aeb40a7970e399003339df26d Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:29:34 +0530 Subject: [PATCH 1/8] Update action.yml --- action.yml | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index b4c80a5a..f8b00ec1 100644 --- a/action.yml +++ b/action.yml @@ -14,8 +14,7 @@ inputs: required: false preRelease: description: - 'A flag to download from prerelease. It should be combined with latest - flag' + 'A flag to download from prerelease. It should be combined with latest flag' default: 'false' required: false tag: @@ -24,8 +23,7 @@ inputs: required: false fileName: description: - "Name of the file to download (use '*' to download all assets other than - tarball or zipball)" + "Name of the file to download (use '*' to download all assets other than tarball or zipball)" default: '' required: false tarBall: @@ -40,21 +38,23 @@ inputs: description: 'Relative path under $GITHUB_WORKSPACE to place the downloaded files' default: '.' - required: true + required: false extract: description: - 'If the downloaded assets should be extracted to `out-file-path`. Supports - tar, tar.gz and zip' + 'If the downloaded assets should be extracted. Supports tar, tar.gz and zip' default: 'false' required: false + extract-path: + description: 'Path where downloaded assets should be extracted. Defaults to `out-file-path` if not set. + default: '' + required: false token: description: 'Github token to access private repos' default: ${{ github.token }} required: false github-api-url: description: - 'The URL of the Github API, only use this input if you are using Github - Enterprise' + 'The URL of the Github API, only use this input if you are using Github Enterprise' default: 'https://api.github.com' required: false releaseId: @@ -68,8 +68,7 @@ outputs: description: 'The release name / title' downloaded_files: description: - "The array of downloaded files, useful when using wildcard '*' to download - multiple files." + "The array of downloaded files, useful when using wildcard '*' to download multiple files." runs: using: 'node20' From c797e3203a9285ca1f7cf4fce68dad83d9813caf Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:32:57 +0530 Subject: [PATCH 2/8] Update download-settings.ts --- src/download-settings.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/download-settings.ts b/src/download-settings.ts index 88f5b6c0..bc1e2303 100644 --- a/src/download-settings.ts +++ b/src/download-settings.ts @@ -45,7 +45,12 @@ export interface IReleaseDownloadSettings { outFilePath: string /** - * Extract downloaded files to outFilePath + * Extract downloaded files */ extractAssets: boolean + + /** + * Path to extract files + */ + extractPath: string } From b49dd501c073b2d5fb6563ae0035f6fd2e2bf1a0 Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:43:43 +0530 Subject: [PATCH 3/8] Update input-helper.ts --- src/input-helper.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/input-helper.ts b/src/input-helper.ts index 1d92f406..0b056a16 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -53,6 +53,10 @@ export function getInputs(): IReleaseDownloadSettings { outFilePath: path.resolve( githubWorkspacePath, core.getInput('out-file-path') || '.' + ), + extractPath: path.resolve( + githubWorkspacePath, + core.getInput('extract-path') || core.getInput('out-file-path') || '.' ) } } From d9ae33d66e3e0aa3c1cd8e7104cb66c3e7132bf9 Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 09:52:23 +0530 Subject: [PATCH 4/8] Update main.ts --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index f94ce06c..78355666 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,7 +26,7 @@ async function run(): Promise { if (downloadSettings.extractAssets) { for (const asset of res) { - await extract(asset, downloadSettings.outFilePath) + await extract(asset, downloadSettings.extractPath) } } From d047149396b14e4a486441e3867c45f06ac526b5 Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:01:56 +0530 Subject: [PATCH 5/8] Update action.yml --- action.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index f8b00ec1..658c5ee4 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,8 @@ inputs: required: false preRelease: description: - 'A flag to download from prerelease. It should be combined with latest flag' + 'A flag to download from prerelease. It should be combined with latest + flag' default: 'false' required: false tag: @@ -23,7 +24,8 @@ inputs: required: false fileName: description: - "Name of the file to download (use '*' to download all assets other than tarball or zipball)" + "Name of the file to download (use '*' to download all assets other than + tarball or zipball)" default: '' required: false tarBall: @@ -41,11 +43,14 @@ inputs: required: false extract: description: - 'If the downloaded assets should be extracted. Supports tar, tar.gz and zip' + 'If the downloaded assets should be extracted. Supports tar, tar.gz and + zip' default: 'false' required: false extract-path: - description: 'Path where downloaded assets should be extracted. Defaults to `out-file-path` if not set. + description: + 'Path where downloaded assets should be extracted. Defaults to + `out-file-path` if not set.' default: '' required: false token: @@ -54,7 +59,8 @@ inputs: required: false github-api-url: description: - 'The URL of the Github API, only use this input if you are using Github Enterprise' + 'The URL of the Github API, only use this input if you are using Github + Enterprise' default: 'https://api.github.com' required: false releaseId: @@ -68,7 +74,8 @@ outputs: description: 'The release name / title' downloaded_files: description: - "The array of downloaded files, useful when using wildcard '*' to download multiple files." + "The array of downloaded files, useful when using wildcard '*' to download + multiple files." runs: using: 'node20' From 14777d0a434f329c11e51be63b4eeefc56d0431c Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:13:36 +0530 Subject: [PATCH 6/8] Add files via upload --- dist/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index bb56a7d0..6620fed5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8463,7 +8463,7 @@ var HttpCodes; })(HttpCodes || (exports.HttpCodes = HttpCodes = {})); const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect]; const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout]; -const NetworkRetryErrors = ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED']; +const NetworkRetryErrors = ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED', 'EHOSTUNREACH']; const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD']; const ExponentialBackoffCeiling = 10; const ExponentialBackoffTimeSlice = 5; @@ -32587,7 +32587,8 @@ function getInputs() { tarBall: core.getBooleanInput('tarBall'), zipBall: core.getBooleanInput('zipBall'), extractAssets: core.getBooleanInput('extract'), - outFilePath: path.resolve(githubWorkspacePath, core.getInput('out-file-path') || '.') + outFilePath: path.resolve(githubWorkspacePath, core.getInput('out-file-path') || '.'), + extractPath: path.resolve(githubWorkspacePath, core.getInput('extract-path') || core.getInput('out-file-path') || '.') }; } @@ -32642,7 +32643,7 @@ async function run() { const res = await downloader.download(downloadSettings); if (downloadSettings.extractAssets) { for (const asset of res) { - await (0, unarchive_1.extract)(asset, downloadSettings.outFilePath); + await (0, unarchive_1.extract)(asset, downloadSettings.extractPath); } } core.info(`Done: ${res}`); @@ -37766,10 +37767,11 @@ class Minimatch { for (let i = 0; i < globParts.length - 1; i++) { for (let j = i + 1; j < globParts.length; j++) { const matched = this.partsMatch(globParts[i], globParts[j], !this.preserveMultipleSlashes); - if (!matched) - continue; - globParts[i] = matched; - globParts[j] = []; + if (matched) { + globParts[i] = []; + globParts[j] = matched; + break; + } } } return globParts.filter(gs => gs.length); From d7f216d49842437872eda97e7d27af8b8c18480e Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:15:05 +0530 Subject: [PATCH 7/8] Update main.test.ts --- __tests__/main.test.ts | 45 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 5ba78cfc..50574fa9 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -152,7 +152,8 @@ test('Download all files from public repo', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(7) @@ -169,7 +170,8 @@ test('Download single file from public repo', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(1) @@ -186,7 +188,8 @@ test('Fail loudly if given filename is not found in a release', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = downloader.download(downloadSettings) await expect(result).rejects.toThrow( @@ -205,7 +208,8 @@ test('Fail loudly if release is not identified', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = downloader.download(downloadSettings) await expect(result).rejects.toThrow( @@ -224,7 +228,8 @@ test('Download files with wildcard from public repo', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(2) @@ -241,7 +246,8 @@ test('Download single file with wildcard from public repo', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(1) @@ -258,7 +264,8 @@ test('Download multiple pdf files with wildcard filename', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(2) @@ -275,7 +282,8 @@ test('Download a csv file with wildcard filename', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(1) @@ -294,7 +302,8 @@ test('Download file from Github Enterprise server', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(1) @@ -311,7 +320,8 @@ test('Download file from release identified by ID', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(1) @@ -328,7 +338,8 @@ test('Download all archive files from public repo', async () => { tarBall: false, zipBall: false, extractAssets: true, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) if (downloadSettings.extractAssets) { @@ -367,7 +378,8 @@ test('Fail when a release with no assets are obtained', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = downloader.download(downloadSettings) await expect(result).rejects.toThrow( @@ -386,7 +398,8 @@ test('Download from latest prerelease', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) expect(result.length).toBe(1) @@ -403,7 +416,8 @@ test('Fail when a release with no prerelease is obtained', async () => { tarBall: false, zipBall: false, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = downloader.download(downloadSettings) await expect(result).rejects.toThrow('No prereleases found!') @@ -420,7 +434,8 @@ test('Download from a release containing only tarBall & zipBall', async () => { tarBall: true, zipBall: true, extractAssets: false, - outFilePath: outputFilePath + outFilePath: outputFilePath, + extractPath: outputFilePath } const result = await downloader.download(downloadSettings) From 00455f2fe2c567fd6eef1e3c131ed643d196f041 Mon Sep 17 00:00:00 2001 From: Naveen Prashanth <78990165+gnpaone@users.noreply.github.com> Date: Sat, 21 Sep 2024 10:28:59 +0530 Subject: [PATCH 8/8] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70afba18..a782525b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ specified files from both private and public repositories. zipBall: true # Relative path under $GITHUB_WORKSPACE to place the downloaded file(s) - # It will create the target directory automatically if not present + # It will create the target directory automatically if not present, defaults to root directory # eg: out-file-path: "my-downloads" => It will create directory $GITHUB_WORKSPACE/my-downloads out-file-path: '' @@ -51,6 +51,12 @@ specified files from both private and public repositories. # Prints a warning if enabled but file is not an archive - but does not fail. extract: false + # Relative path under $GITHUB_WORKSPACE to extract the downloaded file(s) if extract flag is set + # Checks all downloaded files if they end with zip, tar or tar.gz and extracts them to this path if specified. + # If not set it points to "out-file-path" directory. + # eg: extract-path: "my-downloads" => It will create directory $GITHUB_WORKSPACE/my-downloads + extract-path: '' + # Github access token to download files from private repositories # https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets # eg: token: ${{ secrets.MY_TOKEN }}