upload-artifact

repository·main·Indexed 26 days ago

https://github.com/actions/upload-artifact

A GitHub Action used to upload files, directories, or wildcard patterns from a workflow run as artifacts. Version 7.0.1 supports features such as Zlib compression levels, custom retention periods, and the ability to overwrite existing artifacts. It includes a sub-action, `upload-artifact/merge`, which allows combining multiple artifacts created with v4 or later into a single new artifact.

Tokens
5.6K
Snippets
17
Records
31
Agent score
86%

What's inside upload-artifact

  1. Merge multiple GitHub Actions artifacts

    main

    The @actions/upload-artifact/merge sub-action allows you to combine multiple existing artifacts into a single new artifact. It works by downloading the specified artifacts to a temporary directory and re-uploading them as one.

    Important Constraints:

    • This action can only merge artifacts created with actions/upload-artifact@v4 or later.
    • upload-artifact/merge@v4+ is not currently supported on GitHub Enterprise Server (GHES).
    • For most cases, downloading multiple artifacts to the same directory on a runner is more efficient. Use this action only when artifacts need to be merged from outside the runner environment (e.g., via UI or REST API).
  2. Use upload-artifact in GitHub Actions workflows

    main
    Use the actions/upload-artifact@v7 action to upload files, directories, or wildcard patterns from your workflow run as artifacts. This action is internally powered by the @actions/artifact package.
  3. Upload files and directories as artifacts

    main

    Use actions/upload-artifact@v7 to upload individual files, entire directories, or files matching wildcard patterns.

    • Individual Files: Provide the specific file path. Use archive: false to upload the file unzipped.
    • Directories: Provide the directory path. The hierarchy within the directory is preserved.
    • Wildcards: Supports glob patterns (e.g., path/**/[abc]rtifac?/*). Note that the path hierarchy is preserved after the first wildcard pattern, which may result in a flattened structure.
    • Multiple Paths: You can provide multiple paths using YAML multiline syntax. If multiple paths are provided, the least common ancestor of all search paths is used as the root directory. You can use ! to exclude specific patterns.
    • Relative vs Absolute: Relative paths are rooted against the current working directory. Absolute paths are also supported.
    ### Upload an Individual File (Zipped)
    ```yaml
    steps:
    - run: mkdir -p path/to/artifact
    - run: echo hello > path/to/artifact/world.txt
    - uses: actions/upload-artifact@v7
      with:
        name: my-artifact
        path: path/to/artifact/world.txt

    Upload an Individual File (Unzipped)

    steps:
    - run: mkdir -p path/to/artifact
    - run: echo hello > path/to/artifact/world.txt
    - uses: actions/upload-artifact@v7
      with:
        path: path/to/artifact/world.txt
        archive: false

    Upload an Entire Directory

    - uses: actions/upload-artifact@v7
      with:
        name: my-artifact
        path: path/to/artifact/ # or path/to/artifact

    Upload using a Wildcard Pattern

    - uses: actions/upload-artifact@v7
      with:
        name: my-artifact
        path: path/**/[abc]rtifac?/*

    Upload using Multiple Paths and Exclusions

    - uses: actions/upload-artifact@v7
      with:
        name: my-artifact
        path: |
          path/output/bin/
          path/output/test-results
          !path/**/*.tmp
  4. Avoid artifact name conflicts in matrix jobs

    main

    Artifact names must be unique. In v7, uploading to the same artifact name via multiple jobs is not supported and will cause errors. When using a build matrix, ensure each job uses a unique artifact name by incorporating matrix variables (e.g., OS or version) into the name input.

    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@v7
          with:
            name: binary-${{ matrix.os }}-${{ matrix.version }}
            path: my-binary
  5. Overwrite an existing Artifact in v4

    main

    Because Artifacts are immutable in v4, uploading to an existing name will fail unless you explicitly allow overwriting. Use the overwrite: true input to delete the existing Artifact before creating the new one. Note that this creates an entirely new Artifact with a different ID.

    - name: Upload Artifact
      uses: actions/upload-artifact@v4
      with:
        name: my-artifact
        path: my-file.txt
        overwrite: true
  6. Locate uploaded artifacts in GitHub Actions

    main

    Once an artifact is uploaded using upload-artifact, it can be found at the bottom of the workflow summary page in a dedicated artifacts section.

    Key details in the UI:

    • Size: Displayed in bytes. This represents the size of the ZIP file created by upload-artifact during the upload process.
    • Digest: The Digest column displays the SHA256 digest of the uploaded artifact.
    • Deletion: Users with write permissions to the repository will see a trashcan icon next to the artifact, which can be used to delete it.
  7. Migrate from v3 to v4: Handling multiple uploads to the same artifact name

    main

    In v4, Artifacts are immutable. Unlike v3, you cannot upload multiple files to the same artifact name across different jobs. To achieve the same result (collecting files from a matrix into one directory), you must:

    1. Give each upload a unique name using a suffix (e.g., name: my-artifact-${{ matrix.runs-on }}).
    2. Use actions/download-artifact@v4 with the pattern input to match the names and the merge-multiple: true input to download them into a single directory.
    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:
            pattern: my-artifact-*
            merge-multiple: true
            path: my-artifact
  8. Upgrade to upload-artifact@v4 or later

    main

    Versions v1, v2, and v3 of upload-artifact are scheduled for deprecation.

    • v1/v2 deprecation date: June 30, 2024.
    • v3 deprecation date: November 30, 2024.

    To ensure continued support and access to new features, update your GitHub Actions workflows to use actions/upload-artifact@v4 or higher.

  9. Merge multiple artifacts into one using upload-artifact/merge

    main

    To combine multiple artifacts (e.g., from a matrix) into a single archive for external use, use the actions/upload-artifact/merge@v4 action. This action downloads all artifacts matching a pattern to a temporary directory and re-uploads them as a single new artifact.

    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
      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-*
  10. Upload hidden files

    main

    By default, hidden files (files or directories starting with .) are ignored. To include them, set include-hidden-files: true. You can still exclude specific sensitive hidden files using the path input with the ! prefix.

    - uses: actions/upload-artifact@v7
      with:
        name: my-artifact
        include-hidden-files: true
        path: |
          path/output/
          !path/output/.production.env
  11. Include hidden files in uploads

    main

    By default, actions/upload-artifact ignores hidden files to prevent accidental uploads of sensitive information. To include hidden files in your artifact, set the include-hidden-files input to true (available in v4.4.0 and later).

    - name: Upload Artifact
      uses: actions/upload-artifact@v4
      with:
        path: .hidden-file.txt
        include-hidden-files: true
  12. Set artifact retention period

    main

    Artifacts are retained for 90 days by default. Use the retention-days input to specify a shorter period. The value must be between 1 and 90 inclusive.

    - uses: actions/upload-artifact@v7
      with:
        name: my-artifact
        path: my_file.txt
        retention-days: 5