feat: add support for unzip argument in downloadArtifact - #409
Conversation
|
I've rebased the PR on the latest commit of main. |
There was a problem hiding this comment.
Pull request overview
This PR adds support for selective artifact unzipping when downloading artifacts, addressing a frequently requested feature. The implementation introduces a new unzip input parameter that allows users to control whether downloaded artifacts should be automatically extracted or kept in their zipped format. This is accomplished by passing the unzip flag to the underlying downloadArtifact method from @actions/toolkit.
Key changes:
- Added new
unzipinput parameter that acceptstrue,false,*, or comma-separated artifact IDs/names - Modified download logic to determine per-artifact whether to unzip based on the input value
- Added integration tests in the workflow to verify zipped artifact downloads
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| action.yml | Adds the unzip input definition with default value '*' to unzip all artifacts by default |
| src/constants.ts | Adds UnZip enum value to the Inputs enum for the new parameter |
| src/download-artifact.ts | Implements the unzip logic by parsing the input and passing the appropriate flag to each artifact download |
| .github/workflows/test.yml | Adds integration tests for downloading artifacts in zipped format using both pattern matching and artifact IDs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| description: 'IDs of the artifacts to download, comma-separated. Either inputs `artifact-ids` or `name` can be used, but not both.' | ||
| required: false | ||
| unzip: | ||
| description: 'Whenever to unzip the artifact after downloading. Comma separated list of artifact-ids, artifact-name or "*". Defaults to "*".' |
There was a problem hiding this comment.
The description uses "Whenever" but should use "Whether". "Whenever" means "every time that" while "Whether" means "if" which is the intended meaning here.
| description: 'Whenever to unzip the artifact after downloading. Comma separated list of artifact-ids, artifact-name or "*". Defaults to "*".' | |
| description: 'Whether to unzip the artifact after downloading. Comma separated list of artifact-ids, artifact-name or "*". Defaults to "*".' |
| MergeMultiple = 'merge-multiple', | ||
| ArtifactIds = 'artifact-ids' | ||
| ArtifactIds = 'artifact-ids', | ||
| UnZip = "unzip" |
There was a problem hiding this comment.
The enum value UnZip uses inconsistent casing compared to other enum values. It should be Unzip to match the PascalCase convention used by other values like ArtifactIds, MergeMultiple, etc.
| UnZip = "unzip" | |
| Unzip = "unzip" |
| expectedHash: artifact.digest | ||
| }) | ||
| })) | ||
| const unzip_list = inputs.unzip.split(','); |
There was a problem hiding this comment.
The comma-separated value parsing doesn't follow the same pattern used elsewhere in this file (lines 93-96). When inputs.unzip is empty, .split(',') returns [''] which could cause unexpected matches. Follow the existing pattern: const unzipList = inputs.unzip.split(',').map(s => s.trim()).filter(s => s !== ''); This ensures empty values are filtered out and whitespace is trimmed, consistent with how artifactIds is parsed.
| const unzip_list = inputs.unzip.split(','); | |
| const unzip_list = inputs.unzip.split(',').map(s => s.trim()).filter(s => s !== ''); |
| const unzip_list = inputs.unzip.split(','); | ||
| const downloadPromises = artifacts.map(artifact => { | ||
| const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzip_list.includes(artifact.id.toString()) || unzip_list.includes(artifact.name); |
There was a problem hiding this comment.
The variable unzip_list uses snake_case, but the codebase convention is camelCase for local variables (e.g., artifactIdList on line 93, resolvedPath on line 50, isSingleArtifactDownload on line 48). It should be unzipList to maintain consistency.
| const unzip_list = inputs.unzip.split(','); | |
| const downloadPromises = artifacts.map(artifact => { | |
| const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzip_list.includes(artifact.id.toString()) || unzip_list.includes(artifact.name); | |
| const unzipList = inputs.unzip.split(','); | |
| const downloadPromises = artifacts.map(artifact => { | |
| const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzipList.includes(artifact.id.toString()) || unzipList.includes(artifact.name); |
| const unzip_list = inputs.unzip.split(','); | ||
| const downloadPromises = artifacts.map(artifact => { | ||
| const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzip_list.includes(artifact.id.toString()) || unzip_list.includes(artifact.name); |
There was a problem hiding this comment.
The new unzip input functionality lacks unit test coverage. The existing test file __tests__/download.test.ts has comprehensive tests for other inputs (name, artifact-ids, pattern, etc.), but there are no tests verifying the unzip logic. Consider adding tests for:
unzip: 'true'- should unzip all artifactsunzip: 'false'- should not unzip any artifactsunzip: '*'- should unzip all artifactsunzip: '<artifact-id>'- should only unzip the specified artifact by IDunzip: '<artifact-name>'- should only unzip the specified artifact by nameunzip: '<id1>,<id2>'- should unzip multiple artifacts by ID
| description: 'IDs of the artifacts to download, comma-separated. Either inputs `artifact-ids` or `name` can be used, but not both.' | ||
| required: false | ||
| unzip: | ||
| description: 'Whenever to unzip the artifact after downloading. Comma separated list of artifact-ids, artifact-name or "*". Defaults to "*".' |
There was a problem hiding this comment.
The description could be clearer about the format of this input. Consider rewording to: "Whether to unzip the artifact after downloading. Accepts: 'true' or '' to unzip all artifacts, 'false' to keep all zipped, or a comma-separated list of artifact IDs or names to selectively unzip. Defaults to ''."
| description: 'Whenever to unzip the artifact after downloading. Comma separated list of artifact-ids, artifact-name or "*". Defaults to "*".' | |
| description: "Whether to unzip the artifact after downloading. Accepts: 'true' or '*' to unzip all artifacts, 'false' to keep all zipped, or a comma-separated list of artifact IDs or names to selectively unzip. Defaults to '*'." |
| const unzip_list = inputs.unzip.split(','); | ||
| const downloadPromises = artifacts.map(artifact => { | ||
| const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzip_list.includes(artifact.id.toString()) || unzip_list.includes(artifact.name); |
There was a problem hiding this comment.
The variable reference unzip_list should be unzipList to match the camelCase naming convention used throughout the codebase.
| const unzip_list = inputs.unzip.split(','); | |
| const downloadPromises = artifacts.map(artifact => { | |
| const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzip_list.includes(artifact.id.toString()) || unzip_list.includes(artifact.name); | |
| const unzipList = inputs.unzip.split(','); | |
| const downloadPromises = artifacts.map(artifact => { | |
| const unzip = inputs.unzip === 'true' || inputs.unzip === '*' || unzipList.includes(artifact.id.toString()) || unzipList.includes(artifact.name); |
| MergeMultiple = 'merge-multiple', | ||
| ArtifactIds = 'artifact-ids' | ||
| ArtifactIds = 'artifact-ids', | ||
| UnZip = "unzip" |
There was a problem hiding this comment.
The string value uses double quotes ("unzip"), but all other enum values in this file use single quotes (e.g., 'name', 'path', 'artifact-ids'). This should be changed to 'unzip' for consistency with the codebase's quote style.
| UnZip = "unzip" | |
| UnZip = 'unzip' |
|
Similar feature in the CLI: cli/cli#12435 |
This PR just add the possibility to filter what we want to unzip or not when downloading artifacts.
This feature was asked by so many people, and the implementation change almost nothing in the code. So it won't break any part of the action.
Here a simple example that show how it work : https://github.com/shiipou/download-artifact/blob/main/.github/workflows/test.yml
You can also try it with this workflow :
Workflow
This PR need this (actions/toolkit#2095) to be merged before.
This simply add a new
unzipinput, this input take as value : artefact-ids, artefact-names, true, false, or '*'.artefact-idswill be a comma separated string of artifact's ids we want to unzipartefact-nameswill be a comma separated string of artefact's names we want to unziptrueis used to unzip everythingfalseis used to keep everything zipped*is used to unzip everything