release-downloader GitHub Action

repository·main·Indexed 42 days ago

https://github.com/robinraju/release-downloader

A GitHub Action (v1.0.0) to download assets from public and private GitHub releases. It supports targeting the latest release, specific tags, or release IDs, and features wildcard filename matching and automatic extraction of .zip, .tar, and .tar.gz archives.

Tokens
3.7K
Snippets
11
Records
18
Agent score
45%

What's inside release-downloader

  1. Use Github Release Downloader in GitHub Actions

    main

    The robinraju/release-downloader action allows you to download assets from GitHub releases, including files from both private and public repositories. You can target specific tags, release IDs, or the latest release, and support wildcard patterns for filenames. It also supports downloading and automatically extracting archives like .zip, .tar, or .tar.gz.

    - uses: robinraju/release-downloader@v1
      with:
        repository: 'owner/repo'
        latest: true
        fileName: 'foo.zip'
  2. Validate repository path format

    main

    The repository input must follow the exact format {owner}/{repo}. If the input does not contain exactly two parts separated by a forward slash, or if either the owner or the repository name is empty, the action will fail with a ConfigError.

    Example of valid format: owner/repository-name

  3. Configure release-downloader inputs

    main

    The following inputs are available for the robinraju/release-downloader@v1 action:

    InputDescription
    repositoryThe source repository in {owner}/{repo} format. Defaults to ${{ github.repository }}.
    latestSet to true to target the latest release. Defaults to false.
    preReleaseSet to true to include pre-releases. Must be combined with latest: true. Defaults to false.
    tagThe specific GitHub tag to download from (e.g., v1.0.1).
    releaseIdThe specific release ID to download files from.
    fileNameThe name of the file to download. Supports wildcard patterns (e.g., *, *.deb, *.zip). Use this for specific files other than tarballs/zipballs.
    tarBallSet to true to download the attached *.tar.gz archive. Defaults to true (implied by usage).
    zipBallSet to true to download the attached *.zip archive. Defaults to true (implied by usage).
    out-file-pathRelative path under $GITHUB_WORKSPACE to place files. Creates directory if missing. Defaults to root.
    extractSet to true to extract downloaded archives (zip, tar, tar.gz). Defaults to false.
    extract-pathRelative path under $GITHUB_WORKSPACE to extract files. If not set, defaults to out-file-path.
    tokenGitHub access token required for private repositories. e.g., ${{ secrets.MY_TOKEN }}.
    github-api-urlThe URL of the GitHub API. Use http(s)://[hostname]/api/v3 for GitHub Enterprise Server. Defaults to https://api.github.com.
  4. Download assets from specific release scenarios

    main

    Common usage patterns for the release downloader:

    Download from latest release in current repository

    - uses: robinraju/release-downloader@v1
      with:
        latest: true
        fileName: 'foo.zip'

    Download from a specific tag

    - uses: robinraju/release-downloader@v1
      with:
        repository: 'owner/repo'
        tag: 'v1.0.0'
        fileName: 'foo.zip'

    Download and extract archives

    - uses: robinraju/release-downloader@v1
      with:
        fileName: 'foo.zip'
        latest: true
        extract: true

    Download using wildcard patterns (e.g., all .deb files)

    - uses: robinraju/release-downloader@v1
      with:
        repository: 'owner/repo'
        latest: true
        fileName: '*.deb'

    Download latest pre-release

    - uses: robinraju/release-downloader@v1
      with:
        repository: 'owner/repo'
        fileName: 'foo.zip'
        latest: true
        preRelease: true
  5. Access output variables from release-downloader

    main

    The action provides several outputs that can be used by subsequent steps in your workflow:

    • tag_name: The tag used to download the release.
    • release_name: The name/title of the release.
    • downloaded_files: An array of the paths to the downloaded files.

    To use these in subsequent steps, use the following syntax:

    # Access tag_name
    ${{ steps.<step-id>.outputs.tag_name }}
    
    # Access release_name
    ${{ steps.<step-id>.outputs.release_name }}
    
    # Access the first file in the downloaded_files array
    ${{ fromJson(steps.<step-id>.outputs.downloaded_files)[0] }}
  6. Map HTTP status codes to error reasons

    main

    The getHttpErrorReason function converts GitHub HTTP status codes into human-readable error messages. This is useful for troubleshooting network or permission issues during the download process.

    import { getHttpErrorReason } from './errors';
    
    const reason = getHttpErrorReason(404);
    // returns 'Not found - verify the repository/tag/release exists'
  7. Execute the release downloader via the entrypoint

    main

    The package provides a top-level run() function that serves as the main entrypoint to initiate the release downloading process. When called, it executes the core logic of the downloader based on the provided configuration or environment settings.

    import { run } from './main.js';
    
    run();
  8. Run the Release Downloader via GitHub Action

    main

    The run() function serves as the main entrypoint for this GitHub Action. It orchestrates the downloading of assets from a GitHub release based on provided inputs.

    To use this action, you must provide the following inputs in your workflow file:

    • token: A GitHub authentication token (required for private repositories or to avoid rate limits).
    • github-api-url: The base URL for the GitHub API.

    The execution flow is:

    1. Retrieves download settings from inputs.
    2. Initializes an authenticated HttpClient using the provided token.
    3. Uses ReleaseDownloader to download assets.
    4. If extractAssets is enabled in the settings, it automatically unarchives the downloaded files to the specified extractPath.
    // This is the main entrypoint called by the GitHub Action runner
    export async function run(): Promise<void> {}
  9. Handle Release Downloader errors

    main

    The downloader throws specific error types that provide actionable hints when a workflow fails. If you are debugging a failed run, look for these error categories in the logs:

    • HttpError: Occurs during API communication.
      • 401 or 403: Verify the token input has appropriate scopes.
      • 404: Check that the repository, tag, or release ID exists.
    • FileNotFoundError: Occurs when a local file operation fails. Check the provided hint in the logs.
    • AssetNotFoundError: Occurs when the requested asset is not in the release. The error log will list Available assets to help you correct the name.
    • ConfigError: Occurs when the provided inputs are invalid or missing.
    HttpError (401/403) -> Hint: Verify the 'token' input has appropriate scopes
    HttpError (404)     -> Hint: Check that the repository, tag, or release ID exists
    AssetNotFoundError   -> Lists 'Available assets'
    FileNotFoundError   -> Provides a 'hint'
    ConfigError         -> Indicates invalid configuration
  10. Reference the IReleaseDownloadSettings properties

    main

    The following properties are available in the IReleaseDownloadSettings interface:

    PropertyTypeDescription
    sourceRepoPathstringThe source repository path in {owner}/{repo} format.
    isLatestbooleanFlag to choose between the latest release and remaining releases.
    preReleasebooleanFlag to enable downloading from a pre-release. (Should be combined with isLatest).
    tagstringThe specific GitHub release tag (e.g., v1.0.1).
    idstringThe specific release ID to download files from.
    fileNamestringThe name of the specific file/asset to download.
    tarBallbooleanWhether to download the release as a tarball.
    zipBallbooleanWhether to download the release as a zipball.
    outFilePathstringThe target local path where the file will be saved.
    extractAssetsbooleanWhether to extract the downloaded files.
    extractPathstringThe local directory path where files should be extracted.
  11. Reference: HTTP Status Code Mappings

    main

    The following mappings are used by getHttpErrorReason to provide context for HTTP failures:

    400: Bad request - the request was malformed
    401: Authentication failed - check your token is valid
    403: Access denied - check your token has the required permissions
    404: Not found - verify the repository/tag/release exists
    422: Unprocessable entity - the request was valid but could not be processed
    429: Rate limited - too many requests, try again later
    500: GitHub server error - this is likely temporary, try again
    502: Bad gateway - GitHub may be experiencing issues
    503: Service unavailable - GitHub may be experiencing issues
  12. GitHub Release and Download Metadata Data Structures

    main

    The project uses the following TypeScript interfaces to represent data retrieved from the GitHub API and processed for downloads:

    • GithubRelease: Represents a full GitHub release object, including its name, ID, tag name, prerelease status, and associated assets.
    • GhAsset: Represents an individual asset attached to a GitHub release.
    • DownloadMetaData: Represents the processed information required to perform a download, identifying the filename, the direct download URL, and whether the target is a tarball or zipball.
    interface GhAsset {
      name: string
      url: string
    }
    
    export interface GithubRelease {
      name: string
      id: number
      tag_name: string
      prerelease: boolean
      assets: GhAsset[]
      tarball_url: string
      zipball_url: string
    }
    
    export interface DownloadMetaData {
      fileName: string
      url: string
      isTarBallOrZipBall: boolean
    }