gruntwork-io / fetch

Download files, folders, and release assets from a specific git commit, branch, or tag of public and private GitHub repos.
https://www.gruntwork.io/
MIT License
587 stars 90 forks source link
downloader git github

Maintained by Gruntwork.io

fetch

fetch makes it easy to download files, folders, or release assets from a specific commit, branch, or tag of a public or private GitHub repo.

Motivation

Gruntwork helps software teams get up and running on AWS with DevOps best practices and world-class infrastructure in about a day. Sometimes we publish scripts and binaries that clients use in their infrastructure, and we want an easy way to install a specific version of one of those scripts and binaries. While this is fairly straightforward to do with public GitHub repos, as you can usually curl or wget a public URL, it's much trickier to do with private GitHub repos, as you have to make multiple API calls, parse JSON responses, and handle authentication. Fetch makes it possible to handle all of these cases with a one-liner.

Features

Quick examples

Download folder /baz from tag 0.1.3 of a GitHub repo and save it to /tmp/baz:

fetch --repo="https://github.com/foo/bar" --tag="0.1.3" --source-path="/baz" /tmp/baz

Download a release asset matching named foo.exe from release 0.1.5 and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" /tmp

Download all release assets matching the regular expression, foo_linux-.* from release 0.1.5 and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo_linux-.*" /tmp

See more examples in the Examples section.

Installation

Download from releases page

Download the fetch binary from the GitHub Releases tab.

Install via package manager

Note that package managers are third party. The third party fetch packages may not be updated with the latest version, but are often close. Please check your version against the latest available on the releases page. If you want the latest version, the recommended installation option is to download from the releases page.

Usage

Assumptions

fetch assumes that a repo's tags are in the format vX.Y.Z or X.Y.Z to support Semantic Versioning parsing. This allows you to specify a Tag Constraint Expression to do things like "get the latest non-breaking version" of this repo. Note that fetch also allows downloading a specific tag not in SemVer format.

General Usage

fetch [OPTIONS] <local-download-path>

The supported options are:

The supported arguments are:

Run fetch --help to see more information about the flags.

Tag Constraint Expressions

The value of --tag can be expressed using any operators defined in hashicorp/go-version.

Specifically, this includes:

Tag Constraint Pattern Meaning
1.0.7 Exactly version 1.0.7
=1.0.7 Exactly version 1.0.7
!=1.0.7 The latest version as long as that version is not 1.0.7
>1.0.7 The latest version greater than 1.0.7
<1.0.7 The latest version that's less than 1.0.7
>=1.0.7 The latest version greater than or equal to 1.0.7
<=1.0.7 The latest version that's less than or equal to 1.0.7
~>1.0.7 The latest version that is greater than 1.0.7 and less than 1.1.0
~>1.0 The latest version that is greater than 1.0 and less than 2.0

Examples

Usage Example 1

Download /modules/foo/bar.sh from a GitHub release where the tag is the latest version of 0.1.x but at least 0.1.5, and save it to /tmp/bar:

fetch --repo="https://github.com/foo/bar" --tag="~>0.1.5" --source-path="/modules/foo/bar.sh" /tmp/bar

Usage Example 2

Download all files in /modules/foo from a GitHub release where the tag is exactly 0.1.5, and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="0.1.5" --source-path="/modules/foo" /tmp

Usage Example 3

Download all files from a private GitHub repo using the GitHUb oAuth Token 123. Get the release whose tag is exactly 0.1.5, and save the files to /tmp:

GITHUB_OAUTH_TOKEN=123

fetch --repo="https://github.com/foo/bar" --ref="0.1.5" /tmp

Usage Example 4

Download all files from the latest commit on the sample-branch branch, and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="sample-branch" /tmp/josh1

Usage Example 5

Download all files from the git commit f32a08313e30f116a1f5617b8b68c11f1c1dbb61, and save them to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="f32a08313e30f116a1f5617b8b68c11f1c1dbb61" /tmp

Usage Example 6

Download the release asset foo.exe from a GitHub release where the tag is exactly 0.1.5, and save it to /tmp:

fetch --repo="https://github.com/foo/bar" --ref="0.1.5" --release-asset="foo.exe" /tmp

Usage Example 7

Download the release asset foo.exe from a GitHub release hosted on a GitHub Enterprise instance running at ghe.mycompany.com where the tag is exactly 0.1.5, and save it to /tmp:

fetch --repo="https://ghe.mycompany.com/foo/bar" --ref="0.1.5" --release-asset="foo.exe" /tmp
Release Instructions

To release a new version of fetch, go to the Releases page and "Draft a new release". On the following page, bump the "Tag version" appropriately, and set the "Release title" to be the same. In the "Describe this release" section, log the changes of this release, linking back to issues that were addressed. Click the "Publish release" button. CircleCI will pick this up, generate the assets, and attach them to the release.

License

This code is released under the MIT License. See LICENSE.txt.

TODO