actions/download-artifact

repository·main·Indexed 23 days ago

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

A GitHub Action for downloading artifacts from workflow runs. It supports downloading by name, ID, or glob pattern, and can fetch artifacts from different repositories or runs. Version 8.0.1 allows for flexible destination paths, decompression control, and the ability to merge multiple artifacts into a single directory.

Tokens
3.7K
Snippets
11
Records
14
Agent score
79%

What's inside actions/download-artifact

  1. Download all artifacts and manage directory structure

    main

    If name is not provided, all artifacts for the run are downloaded. By default, each artifact is extracted into its own subdirectory named after the artifact. Use merge-multiple: true to extract all artifacts into the same directory specified by path.

    # Download all to current working directory (creates subdirectories per artifact)
    - uses: actions/download-artifact@v8
    
    # Download all to a specific directory (creates subdirectories per artifact)
    - uses: actions/download-artifact@v8
      with:
        path: path/to/artifacts
    
    # Download all to the SAME directory (no subdirectories)
    - uses: actions/download-artifact@v8
      with:
        path: path/to/artifacts
        merge-multiple: true
  2. Use actions/download-artifact@v8

    main

    The actions/download-artifact action allows you to download Actions Artifacts from your workflow runs. It is internally powered by the @actions/artifact package. You can download specific artifacts by name or ID, or download all artifacts from the current run.

    - uses: actions/download-artifact@v8
      with:
        name: my-artifact
  3. How to preserve file permissions during artifact transfer

    main

    Standard artifact uploading (zipping) removes file permissions, resetting directories to 755 and files to 644. To preserve exact permissions (like executable bits), you should tar your files before uploading and use archive: false in actions/upload-artifact@v7. Then, download the .tar file and unpack it manually.

    # 1. Tar and upload without archiving
    - name: 'Tar files'
      run: tar -cvf my_files.tar /path/to/my/directory
    
    - name: 'Upload Artifact'
      uses: actions/upload-artifact@v7
      with:
        path: my_files.tar
        archive: false
    
    # 2. Later, download the file
    - name: 'Download Artifact'
      uses: actions/download-artifact@v8
      with:
        name: my_files.tar
  4. Download artifacts by ID for improved security

    main

    In v4, every upload generates a unique artifact ID. To prevent TOCTOU (Time-of-check to time-of-use) issues where an artifact might be replaced by a different one with the same name, you can download specifically by ID using the artifact-ids input in actions/download-artifact@v4.

    jobs:
      upload:
        runs-on: ubuntu-latest
        outputs:
          artifact-id: ${{ steps.upload-step.outputs.artifact-id }}
        steps:
          - name: Create a file
            run: echo "hello world" > my-file.txt
          - name: Upload Artifact
            id: upload-step
            uses: actions/upload-artifact@v4
            with:
              name: my-artifact
              path: my-file.txt
    
      download:
        needs: upload
        runs-on: ubuntu-latest
        steps:
          - name: Download Artifact by ID
            uses: actions/download-artifact@v4
            with:
              artifact-ids: ${{ needs.upload.outputs.artifact-id }}
  5. Merge multiple artifacts into a single archive in v4

    main

    In v4, because artifacts are immutable, you cannot simply upload to the same name to create a single archive. Instead, use actions/upload-artifact/merge@v4. 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:
        needs: upload
        runs-on: ubuntu-latest
        steps:
          - name: Merge Artifacts
            uses: actions/upload-artifact/merge@v4
            with:
              name: all-my-files
              pattern: my-artifact-*
  6. Migrate from v3 to v4: Handling multiple uploads to the same name

    main

    In v3, artifacts were mutable, allowing multiple jobs to upload to the same artifact name, which would merge files into a single artifact.

    In v4, artifacts are immutable. To achieve the same result (uploading files from a matrix into a single directory), you must:

    1. Give each upload a unique name using a pattern (e.g., my-artifact-${{ matrix.runs-on }}).
    2. Use actions/download-artifact@v4 with the pattern input to filter names.
    3. Use the merge-multiple: true input to download those multiple artifacts into the same 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:
            path: my-artifact
            pattern: my-artifact-*
            merge-multiple: true
        - run: ls -R my-artifact
  7. Migrate from v3 to v4: Overwriting an Artifact

    main

    In v3, uploading to an existing artifact name would overwrite the contents.

    In v4, artifacts are immutable. To simulate overwriting, use the overwrite: true input in actions/upload-artifact@v4. This deletes the existing artifact before creating a new one. Note that this creates an entirely new artifact with a different ID.

    jobs:
      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
              path: my-file.txt
              overwrite: true
  8. Download multiple filtered artifacts using a pattern

    main

    You can use the pattern input with a glob pattern to match multiple artifacts. When combined with merge-multiple: true, all matching artifacts will be extracted into the same directory.

    - name: Download All Artifacts
      uses: actions/download-artifact@v8
      with:
        path: my-artifact
        pattern: my-artifact-*
        merge-multiple: true
  9. Download a single artifact by name or ID

    main

    To download a single artifact, provide either the name or the artifact-ids. When downloading a single artifact, the contents are extracted directly to the specified path without creating an additional subdirectory.

    # By name
    - uses: actions/download-artifact@v8
      with:
        name: my-artifact
    
    # By ID
    - uses: actions/download-artifact@v8
      with:
        artifact-ids: 12345
    
    # By ID to a specific directory
    - uses: actions/download-artifact@v8
      with:
        artifact-ids: 12345
        path: your/destination/dir
  10. Download artifacts from other workflow runs or repositories

    main

    To download artifacts from a different repository or a different workflow run, you must provide a github-token with appropriate permissions (e.g., actions:read), the target repository, and the target run-id.

    - uses: actions/download-artifact@v8
      with:
        name: my-other-artifact
        github-token: ${{ secrets.GH_PAT }}
        repository: actions/toolkit
        run-id: 1234
  11. Reference the inputs for actions/download-artifact@v8

    main

    The following inputs are available for configuring the download behavior:

    InputDescription
    nameName of the artifact to download. If unspecified, all artifacts for the run are downloaded. (Optional)
    artifact-idsIDs of the artifacts to download, comma-separated. Either artifact-ids or name can be used, but not both. (Optional)
    pathDestination path. Supports basic tilde expansion. Default is $GITHUB_WORKSPACE. (Optional)
    patternA glob pattern for artifacts to download. Ignored if name is specified. (Optional)
    merge-multipleIf true, downloaded artifacts are placed in the same directory specified by path. If false, they are extracted into individual named directories within path. Default is false. (Optional)
    github-tokenThe GitHub token used to authenticate. Required when downloading from a different repository or workflow run. (Optional)
    repositoryThe repository owner and name joined by "/". Default is ${{ github.repository }}. (Optional)
    run-idThe ID of the workflow run where the artifact was uploaded. Default is ${{ github.run_id }}. (Optional)
    skip-decompressIf true, the downloaded artifact will not be automatically extracted. Default is false. (Optional)
    digest-mismatchAction to take if a hash mismatch is detected. Options: ignore, info, warn, error. Default is error. (Optional)
    - uses: actions/download-artifact@v8
      with:
        name:
        artifact-ids:
        path:
        pattern:
        merge-multiple:
        github-token:
        repository:
        run-id:
        skip-decompress:
        digest-mismatch: