@actions/upload-artifact
警告
events/upload-artifact@v3 は、2024 年 11 月 30 日に非推奨になる予定です。もっと詳しく知る。同様に、v1/v2 は2024 年 6 月 30 日に廃止される予定です。アーティファクト アクションの v4 を使用するようにワークフローを更新してください。この非推奨は、顧客が使用している GitHub Enterprise Server の既存のバージョンには影響しません。
ワークフロー実行からアクション アーティファクトをアップロードします。 @actions/artifact パッケージによって内部的に強化されています。
「ダウンロード アーティファクト」も参照してください。
@actions/upload-artifact
重要
現在、upload-artifact@v4+ は GHES ではまだサポートされていません。 GHES を使用している場合は、v3 を使用する必要があります。
Upload-artifact@v4 と download-artifact@v4 のリリースは、Artifacts のバックエンド アーキテクチャに対する大きな変更です。パフォーマンスと動作が数多く改善されました。
詳細については、 @actions/artifact
ドキュメントを参照してください。
新しいサブアクション、 actions/upload-artifact/merge
もあります。詳細については、そのアクションの README を確認してください。
自己ホスト型ランナーでは、追加のファイアウォール ルールが必要になる場合があります。
同じ名前のアーティファクトに複数回アップロードします。
この新しいバージョンでのアーティファクトの作成方法により、同じ名前のアーティファクトに複数回アップロードすることはできなくなりました。アップロードを異なる名前を持つ複数のアーティファクトに分割するか、一度だけアップロードする必要があります。そうしないと、エラーが発生します。
個々のジョブのアーティファクトの制限。ワークフロー実行内の各ジョブには、500 個のアーティファクトの制限が設けられました。
v4.4
以降では、隠しファイルはデフォルトで除外されます。
重大な変更については、MIGRATION.md を参照してください。
- uses : actions/upload-artifact@v4
with :
# Name of the artifact to upload.
# Optional. Default is 'artifact'
name :
# A file, directory or wildcard pattern that describes what to upload
# Required.
path :
# The desired behavior if no files are found using the provided path.
# Available Options:
# warn: Output a warning but do not fail the action
# error: Fail the action with an error message
# ignore: Do not output any warnings or errors, the action does not fail
# Optional. Default is 'warn'
if-no-files-found :
# Duration after which artifact will expire in days. 0 means using default retention.
# Minimum 1 day.
# Maximum 90 days unless changed from the repository settings page.
# Optional. Defaults to repository settings.
retention-days :
# The level of compression for Zlib to be applied to the artifact archive.
# The value can range from 0 to 9.
# For large files that are not easily compressed, a value of 0 is recommended for significantly faster uploads.
# Optional. Default is '6'
compression-level :
# If true, an artifact with a matching name will be deleted before a new one is uploaded.
# If false, the action will fail if an artifact for the given name already exists.
# Does not fail if the artifact does not exist.
# Optional. Default is 'false'
overwrite :
# Whether to include hidden files in the provided path in the artifact
# The file contents of any hidden files in the path should be validated before
# enabled this to avoid uploading sensitive information.
# Optional. Default is 'false'
include-hidden-files :
名前 | 説明 | 例 |
---|---|---|
artifact-id | アーティファクトの GitHub ID。REST API で使用できます。 | 1234 |
artifact-url | アーティファクトをダウンロードするための URL。課題やプル リクエスト内のアーティファクトへのリンクなど、多くのシナリオで使用できます。この URL が機能するには、ユーザーはログインする必要があります。この URL は、アーティファクトの有効期限が切れていない限り、またはアーティファクト、実行、またはリポジトリが削除されていない限り有効です。 | https://github.com/example-org/example-repo/actions/runs/1/artifacts/1234 |
steps :
- run : mkdir -p path/to/artifact
- run : echo hello > path/to/artifact/world.txt
- uses : actions/upload-artifact@v4
with :
name : my-artifact
path : path/to/artifact/world.txt
- uses : actions/upload-artifact@v4
with :
name : my-artifact
path : path/to/artifact/ # or path/to/artifact
- uses : actions/upload-artifact@v4
with :
name : my-artifact
path : path/**/[abc]rtifac?/*
- uses : actions/upload-artifact@v4
with :
name : my-artifact
path : |
path/output/bin/
path/output/test-results
!path/**/*.tmp
サポートされているワイルドカードと動作およびドキュメントについては、ファイルの検索に内部的に使用される @actions/glob を参照してください。
ワイルドカード パターンが使用される場合、パス階層は最初のワイルドカード パターンの後に保持されます。
path/to/*/directory/foo?.txt =>
∟ path/to/some/directory/foo1.txt
∟ path/to/some/directory/foo2.txt
∟ path/to/other/directory/foo1.txt
would be flattened and uploaded as =>
∟ some/directory/foo1.txt
∟ some/directory/foo2.txt
∟ other/directory/foo1.txt
複数のパスが入力として指定された場合、すべての検索パスの最も共通性の低い祖先がアーティファクトのルート ディレクトリとして使用されます。除外パスはディレクトリ構造に影響を与えません。
相対ファイル パスと絶対ファイル パスの両方が許可されます。相対パスは、現在の作業ディレクトリをルートとします。ワイルドカード文字で始まるパスは、YAML エイリアスとして解釈されないように引用符で囲む必要があります。
大規模なデータまたは簡単に圧縮可能なデータをアーティファクトにアップロードする場合は、圧縮レベルを調整するとメリットが得られる場合があります。デフォルトでは、圧縮レベルは6
で、GNU Gzip と同じです。
値の範囲は 0 ~ 9 です。
レベルが高いほど圧縮率は高くなりますが、完了までに時間がかかります。圧縮が容易ではない大きなファイルの場合、アップロードを大幅に高速化するために値0
を推奨します。
たとえば、ランダムなバイナリ データをアップロードする場合、圧縮を完全にオプトアウトするとメリットがなくなるため、時間を大幅に節約できます。
- name : Make a 1GB random binary file
run : |
dd if=/dev/urandom of=my-1gb-file bs=1M count=1000
- uses : actions/upload-artifact@v4
with :
name : my-artifact
path : my-1gb-file
compression-level : 0 # no compression
ただし、圧縮されやすいデータ (プレーンテキスト、コードなど) をアップロードする場合は、圧縮レベルを高くすることでスペースとコストを節約できます。ただし、これは CPU の負荷が高くなるため、アップロードが遅くなります。
- name : Make a file with a lot of repeated text
run : |
for i in {1..100000}; do echo -n 'foobar' >> foobar.txt; done
- uses : actions/upload-artifact@v4
with :
name : my-artifact
path : foobar.txt
compression-level : 9 # maximum compression
パス (複数のパス) でアーティファクトのファイルが見つからない場合、アクションは成功しますが、警告が出力されます。特定のシナリオでは、アクションを失敗するか、警告を抑制することが望ましい場合があります。 if-no-files-found
オプションを使用すると、ファイルが見つからない場合のアクションの動作をカスタマイズできます。
- uses : actions/upload-artifact@v4
with :
name : my-artifact
path : path/to/artifact/
if-no-files-found : error # 'warn' or 'ignore' are also available, defaults to `warn`
以前のバージョンのupload-artifact
とは異なり、複数のジョブを介した同じアーティファクトへのアップロードはv4
ではサポートされていません。
- run : echo hi > world.txt
- uses : actions/upload-artifact@v4
with :
# implicitly named as 'artifact'
path : world.txt
- run : echo howdy > extra-file.txt
- uses : actions/upload-artifact@v4
with :
# also implicitly named as 'artifact', will fail here!
path : extra-file.txt
作成された各アーティファクトは冪等であるため、複数のジョブが同じアーティファクトを変更できないため、アーティファクト名は一意である必要があります。
マトリックスのシナリオでは、同じアーティファクトに誤ってアップロードしないように注意してください。アップロードしないと、競合エラーが発生します。マトリックスのプレフィックスまたはサフィックスを使用してアーティファクトに名前を付けることが最善です。
jobs :
upload :
name : Generate Build Artifacts
strategy :
matrix :
os : [ubuntu-latest, windows-latest]
version : [a, b, c]
runs-on : ${{ matrix.os }}
steps :
- name : Build
run : ./some-script --version=${{ matrix.version }} > my-binary
- name : Upload
uses : actions/upload-artifact@v4
with :
name : binary-${{ matrix.os }}-${{ matrix.version }}
path : my-binary
これにより、 binary-ubuntu-latest-a
、 binary-windows-latest-b
などのアーティファクトが生成されます。
以前の動作では、アーティファクト名が同じであることが許可されていたため、予期しない突然変異や偶発的な破損が発生していました。 Upload-artifact@v4 によって作成されたアーティファクトは不変です。
$HOME
の代わりにパス入力で~
使用できます。基本的なチルダ展開がサポートされています。
- run : |
mkdir -p ~/new/artifact
echo hello > ~/new/artifact/world.txt
- uses : actions/upload-artifact@v4
with :
name : my-artifacts
path : ~/new/**/*
環境変数とコンテキスト式を入力に使用することもできます。ドキュメントについては、コンテキストと式の構文を参照してください。
env :
name : my-artifact
steps :
- run : |
mkdir -p ${{ github.workspace }}/artifact
echo hello > ${{ github.workspace }}/artifact/world.txt
- uses : actions/upload-artifact@v4
with :
name : ${{ env.name }}-name
path : ${{ github.workspace }}/artifact/**/*
他の手順で作成した環境変数については、必ずenv
式構文を使用してください。
steps :
- run : |
mkdir testing
echo "This is a file to upload" > testing/file.txt
echo "artifactPath=testing/file.txt" >> $GITHUB_ENV
- uses : actions/upload-artifact@v4
with :
name : artifact
path : ${{ env.artifactPath }} # this will resolve to testing/file.txt at runtime
アーティファクトはデフォルトで 90 日間保持されます。 retention-days
入力を使用して、より短い保持期間を指定できます。
- name : Create a file
run : echo "I won't live long" > my_file.txt
- name : Upload Artifact
uses : actions/upload-artifact@v4
with :
name : my-artifact
path : my_file.txt
retention-days : 5
保持期間は 1 ~ 90 の範囲にする必要があります。詳細については、アーティファクトとログの保存ポリシーを参照してください。
アーティファクトのアップロードが成功すると、 artifact-id
出力が利用可能になります。この ID は、Artifact REST API で使用できる一意の識別子です。
- uses : actions/upload-artifact@v4
id : artifact-upload-step
with :
name : my-artifact
path : path/to/artifact/content/
- name : Output artifact ID
run : echo 'Artifact ID is ${{ steps.artifact-upload-step.outputs.artifact-id }}'
jobs :
job1 :
runs-on : ubuntu-latest
outputs :
output1 : ${{ steps.artifact-upload-step.outputs.artifact-id }}
steps :
- uses : actions/upload-artifact@v4
id : artifact-upload-step
with :
name : my-artifact
path : path/to/artifact/content/
job2 :
runs-on : ubuntu-latest
needs : job1
steps :
- env :
OUTPUT1 : ${{needs.job1.outputs.output1}}
run : echo "Artifact ID from previous job is $OUTPUT1"
アーティファクトを変異させることはできませんが、アーティファクトを完全に上書きすることはできます。ただし、これによりアーティファクトに新しい ID が与えられ、以前の ID は存在しなくなることに注意してください。
jobs :
upload :
runs-on : ubuntu-latest
steps :
- name : Create a file
run : echo "hello world" > my-file.txt
- name : Upload Artifact
uses : actions/upload-artifact@v4
with :
name : my-artifact # NOTE: same artifact name
path : my-file.txt
upload-again :
needs : upload
runs-on : ubuntu-latest
steps :
- name : Create a different file
run : echo "goodbye world" > my-file.txt
- name : Upload Artifact
uses : actions/upload-artifact@v4
with :
name : my-artifact # NOTE: same artifact name
path : my-file.txt
overwrite : true
デフォルトでは、機密情報が意図せずにアップロードされることを避けるために、このアクションでは隠しファイルは無視されます。
隠しファイルをアップロードする必要がある場合は、 include-hidden-files
入力を使用できます。アップロードされたアーティファクトに含めるべきではない機密情報を含むファイルは、 path
を使用して除外できます。
- uses : actions/upload-artifact@v4
with :
name : my-artifact
include-hidden-files : true
path : |
path/output/
!path/output/.production.env
隠しファイルは、 で始まるファイルとして定義されます.
または . で始まるフォルダー内のファイル.
。 Windows では、隠し属性を持つファイルとディレクトリは、 .
接頭語。
個々のジョブ内で、そのジョブに対して作成できるアーティファクトの数は 500 に制限されています。
共有ストレージ割り当てを超過した場合、アーティファクトによって制限される場合もあります。ストレージは 6 ~ 12 時間ごとに計算されます。詳細については、ドキュメントを参照してください。
アーティファクトがアップロードされると、すべてのファイルが不変の Zip アーカイブにまとめられます。現在、Zip 以外の形式でアーティファクトをダウンロードしたり、個々のアーティファクトのコンテンツをダウンロードしたりする方法はありません。
ファイルのアクセス許可は、アーティファクトのアップロード中に維持されません。すべてのディレクトリには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
ワークフロー概要ページの下部には、成果物専用のセクションがあります。以下は、表示される可能性のあるもののスクリーンショットです。
アーティファクトを削除するために使用できるゴミ箱アイコンがあります。このアイコンは、リポジトリへの書き込み権限を持つユーザーにのみ表示されます。
アーティファクトのサイズはバイト単位で示されます。表示されるアーティファクトのサイズは、アップロード中にupload-artifact
が作成する zip のサイズを示します。