Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''

Expand All @@ -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 }}
Expand Down
45 changes: 30 additions & 15 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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!')
Expand All @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
16 changes: 9 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/download-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') || '.'
)
}
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function run(): Promise<void> {

if (downloadSettings.extractAssets) {
for (const asset of res) {
await extract(asset, downloadSettings.outFilePath)
await extract(asset, downloadSettings.extractPath)
}
}

Expand Down