@actions/download-artifact
警告
actions/download-artifact@v3 计划于2024 年 11 月 30 日弃用。了解更多。同样,v1/v2 计划于2024 年 6 月 30 日弃用。请更新您的工作流程以使用工件操作的 v4。此弃用不会影响客户正在使用的 GitHub Enterprise Server 的任何现有版本。
从工作流程运行中下载操作工件。由 @actions/artifact 包内部驱动。
另请参见上传工件。
@actions/download-artifact
重要的
GHES 目前尚不支持 download-artifact@v4+。如果您使用 GHES,则必须使用 v3。
upload-artifact@v4和download-artifact@v4的发布是Artifacts后端架构的重大改变。他们有许多性能和行为方面的改进。
有关更多信息,请参阅@actions/artifact
文档。
action/upload-artifact@v3
及以下版本创建的工件。有关重大更改的帮助,请参阅 MIGRATION.md。
- uses : actions/download-artifact@v4
with :
# Name of the artifact to download.
# If unspecified, all artifacts for the run are downloaded.
# Optional.
name :
# Destination path. Supports basic tilde expansion.
# 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.
github-token :
# The repository owner and the repository name joined together by "/".
# If github-token is specified, this is the repository that artifacts will be downloaded from.
# Optional. Default is ${{ github.repository }}
repository :
# The id of the workflow run where the desired download artifact was uploaded from.
# If github-token is specified, this is the run that artifacts will be downloaded from.
# Optional. Default is ${{ github.run_id }}
run-id :
姓名 | 描述 | 例子 |
---|---|---|
download-path | 下载工件的绝对路径 | /tmp/my/download/path |
下载到当前工作目录( $GITHUB_WORKSPACE
):
steps :
- uses : actions/download-artifact@v4
with :
name : my-artifact
- name : Display structure of downloaded files
run : ls -R
下载到特定目录(也支持~
扩展):
steps :
- uses : actions/download-artifact@v4
with :
name : my-artifact
path : your/destination/dir
- name : Display structure of downloaded files
run : ls -R your/destination/dir
如果未提供name
输入参数,则将下载所有工件。为了区分下载的工件,默认情况下将为每个单独的工件创建一个由工件名称表示的目录。可以使用merge-multiple
输入参数更改此行为。
例如,如果有两个工件Artifact-A
和Artifact-B
,并且目录为etc/usr/artifacts/
,则目录结构将如下所示:
etc/usr/artifacts/
Artifact-A/
... contents of Artifact-A
Artifact-B/
... contents of Artifact-B
将所有工件下载到当前工作目录:
steps :
- uses : actions/download-artifact@v4
- name : Display structure of downloaded files
run : ls -R
将所有工件下载到特定目录:
steps :
- uses : actions/download-artifact@v4
with :
path : path/to/artifacts
- name : Display structure of downloaded files
run : ls -R path/to/artifacts
要将它们下载到同一目录:
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
这将导致:
path/to/artifacts/
... contents of Artifact-A
... contents of Artifact-B
在多个 arch/os 场景中,您可能在不同的作业中构建了 Artifacts。要将所有工件下载到同一目录(或匹配 glob 模式),您可以使用该pattern
并merge-multiple
输入。
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
这会产生一个像这样的目录:
my-artifact/
file-macos-latest.txt
file-ubuntu-latest.txt
file-windows-latest.txt
从其他工作流运行甚至其他存储库下载工件可能很有用。默认情况下,权限是有范围的,因此他们只能下载当前工作流程运行中的工件。要提升此场景的权限,您可以指定github-token
以及其他存储库和运行标识符:
steps :
- uses : actions/download-artifact@v4
with :
name : my-other-artifact
github-token : ${{ secrets.GH_PAT }} # token with actions:read permissions on target repo
repository : actions/toolkit
run-id : 1234
在工件上传期间不会维护文件权限。所有目录将有755
,所有文件将有644
。例如,如果您使用chmod
使文件可执行,然后上传该文件,则下载后不再保证该文件被设置为可执行文件。
如果您必须保留权限,则可以在上传工件之前将所有文件tar
在一起。下载后, tar
文件将保持文件权限和区分大小写。
- name : ' Tar files '
run : tar -cvf my_files.tar /path/to/my/directory
- name : ' Upload Artifact '
uses : actions/upload-artifact@v4
with :
name : my-artifact
path : my_files.tar