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 }} 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) diff --git a/action.yml b/action.yml index b4c80a5a..658c5ee4 100644 --- a/action.yml +++ b/action.yml @@ -40,13 +40,19 @@ 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 }} 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); 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 } 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') || '.' ) } } 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) } }