Skip to content

Commit

Permalink
Merge pull request #259 from actions/robherley/glob-downloads
Browse files Browse the repository at this point in the history
Support pattern matching to filter artifacts & merge to same directory
  • Loading branch information
robherley authored Dec 18, 2023
2 parents 1bd0606 + 3181fe8 commit f44cd7b
Show file tree
Hide file tree
Showing 12 changed files with 15,463 additions and 10,691 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
"plugin:prettier/recommended"
],
"plugins": ["@typescript-eslint"]
}
}
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,25 @@ jobs:
Write-Error "File contents of downloaded artifacts are incorrect"
}
shell: pwsh

# Test glob downloading both artifacts to same directory
- name: Download all Artifacts
uses: ./
with:
pattern: Artifact-*
path: single/directory
merge-multiple: true

- name: Verify successful download
run: |
$fileA = "single/directory/file-A.txt"
$fileB = "single/directory/file-B.txt"
if(!(Test-Path -path $fileA) -or !(Test-Path -path $fileB))
{
Write-Error "Expected files do not exist"
}
if(!((Get-Content $fileA) -ceq "Lorem ipsum dolor sit amet") -or !((Get-Content $fileB) -ceq "Hello world from file B"))
{
Write-Error "File contents of downloaded artifacts are incorrect"
}
shell: pwsh
26 changes: 26 additions & 0 deletions .licenses/npm/minimatch-9.0.3.dep.yml

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

26 changes: 26 additions & 0 deletions .licenses/npm/minimatch.dep.yml

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

82 changes: 79 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See also [upload-artifact](https://github.com/actions/upload-artifact).
- [Examples](#examples)
- [Download Single Artifact](#download-single-artifact)
- [Download All Artifacts](#download-all-artifacts)
- [Download multiple (filtered) Artifacts to the same directory](#download-multiple-filtered-artifacts-to-the-same-directory)
- [Download Artifacts from other Workflow Runs or Repositories](#download-artifacts-from-other-workflow-runs-or-repositories)
- [Limitations](#limitations)
- [Permission Loss](#permission-loss)
Expand All @@ -38,6 +39,8 @@ For more information, see the [`@actions/artifact`](https://github.com/actions/t
1. On self hosted runners, additional [firewall rules](https://github.com/actions/toolkit/tree/main/packages/artifact#breaking-changes) may be required.
2. Downloading artifacts that were created from `action/upload-artifact@v3` and below are not supported.

For assistance with breaking changes, see [MIGRATION.md](docs/MIGRATION.md).

## Usage

### Inputs
Expand All @@ -46,13 +49,25 @@ For more information, see the [`@actions/artifact`](https://github.com/actions/t
- uses: actions/download-artifact@v4
with:
# Name of the artifact to download.
# Optional. If unspecified, all artifacts for the run are downloaded.
# If unspecified, all artifacts for the run are downloaded.
# Optional.
name:

# Destination path. Supports basic tilde expansion.
# Optional. Defaults is $GITHUB_WORKSPACE
# Optional. Default is $GITHUB_WORKSPACE
path:

# A glob pattern to the artifacts that should be downloaded.
# Ignored if name is specified.
# Optional.
pattern:

# When multiple artifacts are matched, this changes the behavior of the destination directories.
# If true, the downloaded artifacts will be in the same directory specified by path.
# If false, the downloaded artifacts will be extracted into individual named directories within the specified path.
# Optional. Default is 'false'
merge-multiple:

# The GitHub token used to authenticate with the GitHub API.
# This is required when downloading artifacts from a different repository or from a different workflow run.
# Optional. If unspecified, the action will download artifacts from the current repo and the current workflow run.
Expand Down Expand Up @@ -105,7 +120,7 @@ steps:

### Download All Artifacts

If the `name` input parameter is not provided, all artifacts will be downloaded. **To differentiate between downloaded artifacts, a directory denoted by the artifacts name will be created for each individual artifact.**
If the `name` input parameter is not provided, all artifacts will be downloaded. To differentiate between downloaded artifacts, by default a directory denoted by the artifacts name will be created for each individual artifact. This behavior can be changed with the `merge-multiple` input parameter.

Example, if there are two artifacts `Artifact-A` and `Artifact-B`, and the directory is `etc/usr/artifacts/`, the directory structure will look like this:

Expand Down Expand Up @@ -137,6 +152,67 @@ steps:
run: ls -R path/to/artifacts
```

To download them to the _same_ directory:

```yaml
steps:
- uses: actions/download-artifact@v4
with:
path: path/to/artifacts
merge-multiple: true
- name: Display structure of downloaded files
run: ls -R path/to/artifacts
```

Which will result in:

```
path/to/artifacts/
... contents of Artifact-A
... contents of Artifact-B
```

### Download multiple (filtered) Artifacts to the same directory

In multiple arch/os scenarios, you may have Artifacts built in different jobs. To download all Artifacts to the same directory (or matching a glob pattern), you can use the `pattern` and `merge-multiple` inputs.

```yaml
jobs:
upload:
strategy:
matrix:
runs-on: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- name: Create a File
run: echo "hello from ${{ matrix.runs-on }}" > file-${{ matrix.runs-on }}.txt
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: my-artifact-${{ matrix.runs-on }}
path: file-${{ matrix.runs-on }}.txt
download:
needs: upload
runs-on: ubuntu-latest
steps:
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: my-artifact
pattern: my-artifact-*
merge-multiple: true
- run: ls -R my-artifact
```

This results in a directory like so:

```
my-artifact/
file-macos-latest.txt
file-ubuntu-latest.txt
file-windows-latest.txt
```

### Download Artifacts from other Workflow Runs or Repositories

It may be useful to download Artifacts from other workflow runs, or even other repositories. By default, the permissions are scoped so they can only download Artifacts within the current workflow run. To elevate permissions for this scenario, you can specify a `github-token` along with other repository and run identifiers:
Expand Down
11 changes: 10 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ description: 'Download a build artifact that was previously uploaded in the work
author: 'GitHub'
inputs:
name:
description: 'Name of the artifact to download. If unspecified, all artifacts for the run are downloaded'
description: 'Name of the artifact to download. If unspecified, all artifacts for the run are downloaded.'
required: false
path:
description: 'Destination path. Supports basic tilde expansion. Defaults to $GITHUB_WORKSPACE'
required: false
pattern:
description: 'A glob pattern matching the artifacts that should be downloaded. Ignored if name is specified.'
required: false
merge-multiple:
description: 'When multiple artifacts are matched, this changes the behavior of the destination directories.
If true, the downloaded artifacts will be in the same directory specified by path.
If false, the downloaded artifacts will be extracted into individual named directories within the specified path.'
required: false
default: 'false'
github-token:
description: 'The GitHub token used to authenticate with the GitHub API.
This is required when downloading artifacts from a different repository or from a different workflow run.
Expand Down
Loading

0 comments on commit f44cd7b

Please sign in to comment.