@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