はじめに
github-actionsで成果物を保存するために使うartifactであるが、v3は2024/11/30に廃止されるとのことなので、v4にアップデートした。
actions/download-artifact@v3 is scheduled for deprecation on November 30, 2024. Learn more.
@actions/download-artifact
actions/upload-artifact@v3 is scheduled for deprecation on November 30, 2024. Learn more.
@actions/upload-artifact
BreakingChanges
upload-artifact
- On self hosted runners, additional [firewall rules](https://github.com/actions/toolkit/tree/main/packages/artifact#breaking-changes) may be required.
- Uploading to the same named Artifact multiple times. Due to how Artifacts are created in this new version, it is no longer possible to upload to the same named Artifact multiple times. You must either split the uploads into multiple Artifacts with different names, or only upload once. Otherwise you will encounter an error.
- Limit of Artifacts for an individual job. Each job in a workflow run now has a limit of 500 artifacts.
@actions/download-artifact
1.セルフホストランナーの場合、ファイアウォールルールを変更が必要の可能性がある
セルフホストランナーを用いる場合、ファイアウォールのルールを変更しなければならない可能性があるらしい
communication-between-self-hosted-runners-and-githubに記載されているルールを許可する必要があるとのこと
セルフホストランナーを用いている場合は、対応する必要があるか各セルフホストランナーで動かしてみるとよいと思う
自分の環境では特に問題はなさそうだった
2.同じnameのartifactをアップロードするとエラーが発生するようになった
同じnameのartifactをアップロードして上書きしていく処理がいくつか存在した
マイグレーションパターンが記載されていたので後述する
3.1ジョブあたり500個までのアーティファクトの制限がついた
1ジョブあたり500個もアップロードすることはないと思うので修正対応なし
download-artifact
- On self hosted runners, additional [firewall rules](https://github.com/actions/toolkit/tree/main/packages/artifact#breaking-changes) may be required.
- Downloading artifacts that were created from
action/upload-artifact@v3and below are not supported.
1.セルフホストランナーの場合、ファイアウォールルールを変更する必要がある
upload-artifactと同様
2.action/upload-artifact@v3でアップロードしたものはv4でダウンロードする事が不可能
downloadだけV4にするとエラーが発生するため、upload-artifactも同時にv4にする必要がある
対応
v4で同じnameのartifactをアップロードが出来なくなったことに関する対応
upload-artifactの2.同じnameのartifactをアップロードするとエラーが発生するようになったについては対応が必要そうだった
この対応について、公式でまとめられていたので、それについて記載する
https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md
1.同じname、異なるPathのArtifactをダウンロードするパターン
v3では、pathが異なる同じnameのArtifactをアップロードし、そのnameを指定してダウンロードすると自動でディレクトリが作成され全てダウンロードされる仕様だった
例えば、以下のジョブを実行すると
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@v3
with:
name: my-artifact # NOTE: same artifact name
path: file-${{ matrix.runs-on }}.txt
download:
needs: upload
runs-on: ubuntu-latest
steps:
- name: Download All Artifacts
uses: actions/download-artifact@v3
with:
name: my-artifact
path: my-artifact
- run: ls -R my-artifact
以下のようにダウンロードされる
my-artifact/
file-macos-latest.txt
file-ubuntu-latest.txt
file-windows-latest.txt
しかし、v4ではArtifactのnameは一意なので、Downloadの際に今まで通りnameを指定しても1つしかダウンロードできない。
そのため、以下のように部分一致で引っ掛かるようなnameを指定し、patternを指定しmerge-multiple: trueを利用する
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@v3
+ uses: actions/upload-artifact@v4
with:
- name: my-artifact
+ 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@v3
+ uses: actions/download-artifact@v4
with:
- name: my-artifact
path: my-artifact
+ pattern: my-artifact-*
+ merge-multiple: true
- run: ls -R my-artifact
2.同じname、同じPathのArtifactをアップロードするパターン
v3ではm、同じname、同じPathでArtidactをアップロードすると上書き保存される
例えば、以下のようなジョブを実行すると
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@v3
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@v3
with:
name: my-artifact # NOTE: same artifact name
path: my-file.txt
ジョブの実行結果は、my-file.txtに最後のアップロード結果(“goofbye world”)が記載される
v4では、このような場合は以下のようにoverwrite: trueをつけることで解決できる。
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@v3
+ 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@v3
+ uses: actions/upload-artifact@v4
with:
name: my-artifact # NOTE: same artifact name
path: my-file.txt
+ overwrite: true
3.同じname、異なるPathのArtifactをアップロードするパターン
v3では、同じnameのアーティファクトをアップロードすると、全てがアップロードされた
例えば、以下のようなジョブを実行すると
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@v3
with:
name: all-my-files # NOTE: same artifact name
path: file-${{ matrix.runs-on }}.txt
以下のようにアップロードされる
.
∟ file-ubuntu-latest.txt
∟ file-macos-latest.txt
∟ file-windows-latest.txt
v4では同じnameでのアップロードはできないため、複数のartifactを1つな名前に結合したい場合、以下のようにactions/upload-artifact/merge@v4を利用する
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@v3
+ uses: actions/upload-artifact@v4
with:
- name: all-my-files
+ name: my-artifact-${{ matrix.runs-on }}
path: file-${{ matrix.runs-on }}.txt
+ merge:
+ runs-on: ubuntu-latest
+ needs: upload
+ steps:
+ - name: Merge Artifacts
+ uses: actions/upload-artifact/merge@v4
+ with:
+ name: all-my-files
+ pattern: my-artifact-*