从公共和私有 GitHub 仓库的特定 git 提交、分支或标签下载文件、文件夹和发布资产。
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.
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.
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/bazDownload 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" /tmpDownload 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-.*" /tmpSee more examples in the Examples section.
Download the fetch binary from the GitHub Releases tab.
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.
macOS: You can install fetch using Homebrew: brew install fetch.
Linux: Most Linux users can use Homebrew: brew install fetch.
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.
fetch [OPTIONS] The supported options are:
--repo (Required): The fully qualified URL of the GitHub repo to download from (e.g. https://github.com/foo/bar).--ref (Optional): The git reference to download. If specified, will override --commit, --branch, and --tag.--tag (Optional): The git tag to download. Can be a specific tag or a Tag Constraint
Expression.--branch (Optional): The git branch from which to download; the latest commit in the branch will be used. If
specified, will override --tag.--commit (Optional): The SHA of a git commit to download. If specified, will override --branch and --tag.--source-path (Optional): The source path to download from the repo (e.g. --source-path=/folder will download
the /folder path and all files below it). By default, all files are downloaded from the repo unless --source-path
or --release-asset is specified. This option can be specified more than once.--release-asset (Optional): A regular expression matching release assets--these are binary files uploaded to a GitHub
Release--to download. It only works with the --tag option.--release-asset-checksum (Optional): The checksum that a release asset should have. Fetch will fail if this value
is non-empty and does not match the checksum computed by Fetch, or if more than 1 assets are matched by the release-asset
regular expression.--release-asset-checksum-algo (Optional): The algorithm fetch will use to compute a checksum of the release asset.
Supported values are sha256 and sha512.--github-oauth-token (Optional): A GitHub Personal Access
Token. Required if you're
downloading from private GitHub repos. NOTE: fetch will also look for this token using the GITHUB_OAUTH_TOKEN
environment variable, which we recommend using instead of the command line option to ensure the token doesn't get
saved in bash history.--github-api-version (Optional): Used when fetching an artifact from a GitHub Enterprise instance.
Defaults to v3. This is ignored when fetching from GitHub.com.--progress (Optional): Used when fetching a big file and want to see progress on the fetch.The supported arguments are:
/tmp).Run fetch --help to see more information about the flags.
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 greater 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 |
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/barDownload 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" /tmpDownload 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" /tmpDownload 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/josh1Download all files from the git commit f32a08313e30f116a1f5617b8b68c11f1c1dbb61, and save them to /tmp:
fetch --repo="https://github.com/foo/bar" --ref="f32a08313e30f116a1f5617b8b68c11f1c1dbb61" /tmpDownload 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" /tmpDownload 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" /tmpFetch supports GitLab repositories in addition to GitHub. GitLab is auto-detected for gitlab.com URLs.
Download a release asset from GitLab Runner (a well-known public GitLab project):
fetch --repo="https://gitlab.com/gitlab-org/gitlab-runner" --tag="v17.0.0" --release-asset="gitlab-runner-linux-amd64" /tmpDownload from a public GitLab repository:
fetch --repo="https://gitlab.com/group/project" --tag="v1.0.0" /tmpFor private GitLab repositories, provide a Personal Access Token with read_api scope:
export GITLAB_TOKEN=your_token
fetch --repo="https://gitlab.com/group/project" --tag="v1.0.0" /tmpOr use the --gitlab-token flag:
fetch --repo="https://gitlab.com/group/project" --gitlab-token="your_token" --tag="v1.0.0" /tmpFor self-hosted GitLab instances with custom domains, use the --source gitlab flag:
fetch --repo="https://git.company.com/group/project" --source=gitlab --gitlab-token="$GITLAB_TOKEN" --tag="v1.0.0" /tmpGitLab supports nested groups. Fetch handles these automatically:
fetch --repo="https://gitlab.com/org/team/subteam/project" --tag="v1.0.0" /tmp--source (Optional): Force source type. Values: github, gitlab, auto (default). Use gitlab for self-hosted GitLab with custom domains.--gitlab-token (Optional): GitLab Personal Access Token. Also available via GITLAB_TOKEN environment variable.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.
This code is released under the MIT License. See LICENSE.txt.
暂无开放 Issues,或尚未同步最近议题。