注目イベント!
アドベントカレンダー2024開催中!
一年を締めくくる特別なイベント、アドベントカレンダーを今年も開催しています!
初心者からベテランまで楽しめる内容で、毎日新しい技術トピックをお届けします。
詳細はこちらから!
event banner

Immediate Download of Artifacts with Artifacts Action v4 in GitHub Actions

| 5 min read
Author: masahiro-kondo masahiro-kondoの画像
Information

To reach a broader audience, this article has been translated from Japanese.
You can find the original version here.

Introduction

#

The v4 of actions/upload-artifact and actions/download-artifact, used for uploading and downloading artifacts in GitHub Actions workflows, is now generally available (GA).

GitHub Actions - Artifacts v4 is now Generally Available

Improvements include faster uploads and the ability to download artifacts as soon as the upload is complete, even if the entire workflow has not finished.

Key Changes

#
  1. Artifacts are now treated within the scope of a job, not the workflow
  2. Artifacts are not backward compatible with previous versions
  3. Artifact immutability is guaranteed, upload and download performance is improved, and protection against corruption that often occurs with simultaneous uploads is provided
  4. Up to 10 artifacts can be uploaded in a single job

For the first point, especially in workflows that execute jobs in parallel using the Matrix strategy, it was not possible to download artifacts until the entire workflow had finished. Now, artifacts can be downloaded as soon as the job succeeds. This allows for immediate download and verification of artifacts from jobs that have finished, even when running time-consuming jobs in parallel.

Regarding the second point, when exchanging artifacts between dependent jobs, it is necessary to use the same version of upload-artifact and download-artifact.

For the third point, it is no longer possible to upload artifacts with the same name multiple times. Flows that generate artifacts with the same name in multiple jobs and use the artifacts from the last job executed will need to be revised.

For more details on the changes, please refer to the following.

v4 -whats-new

Trying it Out

#

Let's apply it to an existing job. Below is a workflow for building and uploading binaries for an Electron app I'm developing personally for different platforms (Windows / macOS / Ubuntu), using strategy/matrix to execute jobs for each target OS. The final step in each job uses upload-artifact to upload the built binaries.

name: Build binaries

on:
  workflow_dispatch:
    inputs:
      beta:
        description: 'Build with Electron beta' # Parameter to specify whether to use the Electron beta version
        required: true
        default: 'false'

jobs:
  build:

    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, macos-latest, ubuntu-latest] # Target OS (Runner)

    steps:
    - uses: actions/checkout@v4
    - name: Setup nodejs
      uses: actions/setup-node@v4
      with:
        node-version: '18'
    - name: Install dependencies
      run: npm install
    - name: Install Electron beta
      if: github.event.inputs.beta == 'true'
      run: npm install electron@beta
    - name: Package
      run: npm run pack # Execute electron-builder with npm script
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    - name: Upload artifacts
      uses: actions/upload-artifact@v3
      with:
        name: package-${{ matrix.os }}
        path: dist/**  # Upload artifacts under dist
Information

In this flow, including the target OS name in the artifact name ensures that the artifact names are unique for each job.

Setting fail-fast: false ensures that if one job fails, the other jobs are not cancelled, and the artifacts from successful jobs are uploaded.

Initially executing with v3, the build summary page shows the progress for each target OS, but artifacts are not displayed until a job is completed.

Job Summary in progress

Artifacts were not available for download until all jobs had completed.

Job Summary completed

Now, let's update the final step of the workflow to use upload-artifact v4.

    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: package-${{ matrix.os }}
        path: dist/**  # Upload artifacts under dist

With v4 specified, artifacts from completed jobs became available for download immediately.

Information

The screen updates in real-time without needing to reload.

Conclusion

#

We tried Artifacts Action v4. It's convenient to be able to use artifacts without waiting for the workflow to finish, especially when building artifacts takes time. The performance of uploads has also improved, so it's something we'd like to migrate to as soon as possible.

豆蔵では共に高め合う仲間を募集しています!

recruit

具体的な採用情報はこちらからご覧いただけます。