dawidd6/action-download-artifact

repository·master·Indexed 21 days ago

https://github.com/dawidd6/action-download-artifact

A GitHub Action to download and extract artifacts from workflows other than the current one. It overcomes limitations of the official actions/download-artifact by allowing users to identify target artifacts using criteria such as commit, pr, branch, ref, or run_id. Supports regex-based artifact selection, custom extraction paths, and filtering by workflow conclusion.

Tokens
2K
Snippets
2
Records
10
Agent score
24%

What's inside action-download-artifact

  1. Download workflow artifacts from different workflows

    master

    The dawidd6/action-download-artifact action allows you to download and extract artifacts uploaded by a different workflow run. This is useful when the official actions/download-artifact cannot access artifacts from previous or separate workflow executions. You can identify the target artifact using criteria such as commit, pr, branch, ref, or run_id.

    Important Constraint: Do not specify pr, commit, branch, ref, run_id together, or workflow_conclusion and run_id together. You must pick only one identifier from each group to avoid conflicts.

    - name: Download artifact
      id: download-artifact
      uses: dawidd6/action-download-artifact@<REF>
      with:
        github_token: ${{secrets.GITHUB_TOKEN}}
        workflow: workflow_name.yml
        name: artifact_name
        path: extract_here
  2. Identify artifacts using name and regex

    master

    You can target specific artifacts by providing a name. If you want to download multiple artifacts that follow a pattern, set name_is_regexp to true and provide a regular expression in the name input.

    If merge_multiple is also set to true, all matching artifacts will be extracted into the base path directory. Otherwise, each artifact will be extracted into its own subdirectory named after the artifact within the path.

  3. Configure the download-artifact GitHub Action

    master

    The action-download-artifact action allows you to download workflow artifacts from GitHub Actions. It supports downloading from the current workflow, specific workflows, or searching for runs based on various criteria like branch, commit, PR, or event type.

    Required Inputs

    • github_token: A GitHub token. Use a Personal Access Token (PAT) with repo scope if the repository is private or if you need to access artifacts from a different repository. A PAT with public_repo scope is required for public repositories.
    • repo: The owner/repository in owner/repo format.
    • path: The local directory where artifacts should be downloaded and/or unpacked.

    Key Optional Inputs

    • name: The name of the artifact to download. Supports exact matches or Regular Expressions if name_is_regexp is set to true.
    • workflow: The workflow name or ID to search in.
    • workflow_search: If true, the action will search for the most recent workflow matching the criteria if workflow is not specified.
    • workflow_conclusion: Filter runs by their conclusion (e.g., success, failure, cancelled).
    • run_id: The specific GitHub Run ID to target.
    • skip_unpack: If true, the action downloads the .zip file but does not extract it.
    • use_unzip: If true, uses the system unzip command instead of the internal adm-zip library for extraction.
    • merge_multiple: If true and multiple artifacts match the name (via regex), they will all be extracted into the same directory specified by path instead of individual subdirectories.
  4. Troubleshoot GLIBC_2.28 not found error

    master

    If you encounter a GLIBC_2.28 not found error, it is because the action's v3 release (and newer) uses node20 as the runtime, which requires glibc>=2.28.

    Solution: If your self-hosted runner has an older version of glibc, pin your workflow to use the v2 release of the action. Note that v2 will not receive further updates.

  5. Handle missing artifacts with if_no_artifact_found

    master

    The if_no_artifact_found input determines the action's behavior when no matching artifacts are located. It accepts the following values:

    • fail: The action will fail the workflow step.
    • warn: The action will issue a warning but continue the workflow.
    • ignore (default): The action will simply log an info message and continue.
  6. Configure the download-artifact action

    master

    Use the following inputs to configure how the action searches for and downloads artifacts:

    Authentication

    • github_token: (Required if downloading from a different repo or a private repo) A GitHub token or Personal Access Token. For private repos, a token with repo scope is required. For jobs with actions scope set to read, a standard GitHub token may suffice.

    Workflow Selection

    • workflow: (Optional) The workflow file name or ID. If not specified, it is inferred from run_id or defaults to the current workflow.
    • workflow_search: (Optional) If true, and no workflow is set, the action searches for the most recent workflow matching other criteria.
    • workflow_conclusion: (Optional) Search for a specific workflow conclusion (e.g., success, failure, neutral, cancelled, skipped, timed_out, action_required) or status (completed, in_progress, queued). Use an empty string "" to ignore status/conclusion.
    • run_id: (Optional) The specific workflow run ID. Use ${{ github.event.workflow_run.id }} when running in a workflow_run event to download from the triggering run.
    • run_number: (Optional) The run number from the workflow.

    Reference Criteria (Pick ONE group)

    • pr: (Optional) Pull request number.
    • commit: (Optional) Commit SHA.
    • branch: (Optional) Branch name. Defaults to all branches.
    • ref: (Optional) Branch/tag/commit ID. Supersedes branch and commit.
    • event: (Optional) The event type (e.g., push).

    Artifact Selection

    • name: (Optional) The name of the uploaded artifact. If not specified, all artifacts are downloaded and extracted into subdirectories.
    • name_is_regexp: (Optional) If true, name is treated as a JavaScript regular expression.
    • search_artifacts: (Optional) If true, searches for the last workflow run that stored an artifact matching name. Defaults to false.
    • check_artifacts: (Optional) If true, checks if the workflow run has an artifact before attempting download. Defaults to false.

    Output and Behavior

    • path: (Optional) Directory to extract artifacts into. Defaults to the current directory.
    • repo: (Optional) The repository to search in. Defaults to the current repo.
    • skip_unpack: (Optional) If true, skips unpacking the downloaded artifact(s). Defaults to false.
    • use_unzip: (Optional) If true, uses the unzip system utility to unpack. Defaults to false.
    • merge_multiple: (Optional) If true and name_is_regexp is true, multiple found artifacts are merged into one directory. Defaults to false.
    • if_no_artifact_found: (Optional) Action exit behavior if no artifact is found. Options: fail (default), warn, ignore.
    • allow_forks: (Optional) Includes forks when searching. Defaults to true.
    # Example configuration
    with:
      github_token: ${{secrets.GITHUB_TOKEN}}
      workflow: main.yml
      workflow_conclusion: success
      name: my-artifact*
      name_is_regexp: true
      path: ./downloads
      if_no_artifact_found: warn
  7. Reference: Action Outputs

    master

    The action provides the following outputs:

    • found_artifact: true if at least one matching artifact was found and processed; false otherwise.
    • artifacts: An array of artifact objects found (if not in dry_run or if search_artifacts is used).
    • dry_run: true if the action was executed in dry-run mode.
    • error_message: The error message if the action fails.
  8. Reference: Input constraints and compatibility

    master

    The following inputs are mutually exclusive and cannot be used together in a single execution. Providing more than one will cause the action to fail:

    • pr (Pull Request number)
    • commit (SHA)
    • branch (Branch name)
    • ref (Git ref)
    • run_id (Specific Run ID)