问题
I have a repo with binary files in it that I need.
I can
git checkout tags/thetagoftherelease
which seems to checkout the correct tag, but does not pull down the binary files. How can I pull down the binary files that were added to the release (the green boxes on the release)?
Added picture of binary files in a release.

回答1:
I've tried for days trying to find the proper answer to this, and finally I figured out how to do this via the curl command. It's a 3-step process.
First, to get a list of the assets for the latest release:
curl -H "Authorization: token YOURGITHUBTOKEN" \
https://api.github.com/repos/NAME/REPO/releases/latest
Then in the JSON, look up the url of the asset you want. For example it would look like:
"url": "https://api.github.com/repos/NAME/REPO/releases/assets/1275759"
Then you pass this to another curl command to retrieve the actual URL, which is actually a link to an Amazon S3 file.
curl -H "Authorization: token YOURGITHUBTOKEN" \
-H "Accept:application/octet-stream" \
-i https://api.github.com/repos/NAME/REPO/releases/assets/1275759
The URL will be in the "location" field of the HTTP response, and then use curl to get the file like this:
curl "https://github-cloud.s3.amazonaws.com...." -i -o FILENAME
回答2:
Binary release assets exist outside of Git, and cannot be managed using the standard tools.
They should be available via GitHub's API, though.
List the repository's release assets:
GET /repos/:owner/:repo/releases/:id/assets
This will send back a JSON document listing the release assets for the repository, e.g.
[ { "url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1", "browser_download_url": "https://github.com/octocat/Hello-World/releases/download/v1.0.0/example.zip", "id": 1, "name": "example.zip", "label": "short description", "state": "uploaded", "content_type": "application/zip", "size": 1024, "download_count": 42, "created_at": "2013-02-27T19:35:32Z", "updated_at": "2013-02-27T19:35:32Z", "uploader": { "login": "octocat", ... } } ]
Retrieve the assts from the release you want, as defined by its
id
from above:GET /repos/:owner/:repo/releases/assets/:id
If you want to download the asset's binary content, pass a media type of
"application/octet-stream"
. The API will either redirect the client to the location, or stream it directly if possible. API clients should handle both a200
or302
response.
As documented, these requests are all relative to https://api.github.com
.
回答3:
For Ansible, you can use this tasklist (same steps as @ted):
- name: Get latest version
uri:
url: "https://api.github.com/repos/{{github_user}}/{{github_repo}}/releases/latest"
return_content: yes
headers:
Authorization: "token {{ vault_github_deploying_token }}"
register: github_response
- set_fact:
binary_asset_url: "{{ github_response.json.assets|json_query(query) }}"
vars:
query: "[?name=='{{your_github_binary_filename}}'].url | [0]"
- name: Get Binary asset's location
uri:
url: "{{ binary_asset_url }}"
return_content: no
follow_redirects: none
status_code: 302
headers:
Authorization: "token {{ vault_github_deploying_token }}"
Accept: "application/octet-stream"
register: assets
- name: Download binary
get_url:
url: "{{ assets.location }}"
dest: "/tmp/{{ your_github_binary_filename }}"
mode: 0755
回答4:
Note that wget
cat get it directly by following download link as a browser do.
Rewrite $URL
as you need. My convention is to upload with a suffix for binary version.
A sample script:
#!/bin/bash
#
# You can fetch some binary directly from release on github
#
# We encourage to build your own version from source.
#
GIT_USER=me
GIT_PROJECT=project_name
BASE_URL=https://github.com/$GIT_USER/$GIT_PROJECT/releases/download
RELEASE=v0.6.3-alpha1
BINARY=bin_file_on_release
if [[ -e $BINARY ]]
then
echo "file in the way: '$BINARY' remove it."
exit 1
fi
if [[ $(getconf LONG_BIT) == "64" ]]
then
echo "I'm 64-bits"
URL="$BASE_URL/$RELEASE/$BINARY"
else
echo "I'm 32-bits"
URL="$BASE_URL/$RELEASE/${BINARY}-32bits"
fi
set -e
echo "Fetching from: $URL"
wget -q -O $BINARY "$URL"
file $BINARY
chmod a+x $BINARY
来源:https://stackoverflow.com/questions/25923939/how-do-i-download-binary-files-of-a-github-release