Back to Blog
1 min read

GitHub Actions Artifact Management

Artifact management in GitHub Actions enables sharing build outputs between jobs and preserving files for later use. This post covers best practices for working with artifacts.

Working with Artifacts

name: Build and Test Pipeline

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: npm ci && npm run build

      - uses: actions/upload-artifact@v3
        with:
          name: build-output
          path: dist/
          retention-days: 7
          if-no-files-found: error

  test:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/download-artifact@v3
        with:
          name: build-output
          path: dist/

      - run: npm test

      - uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: test-results
          path: |
            coverage/
            test-results/

  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v3
        with:
          name: build-output

      - run: echo "Deploying..."

Multi-Platform Artifacts

jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - run: npm ci && npm run build

      - uses: actions/upload-artifact@v3
        with:
          name: build-${{ matrix.os }}
          path: dist/

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v3
        with:
          path: artifacts/

Proper artifact management enables efficient multi-job pipelines and deployment workflows.

Michael John Peña

Michael John Peña

Senior Data Engineer based in Sydney. Writing about data, cloud, and technology.