我正在使用AppVeyor为GitHub存储库设置CI,并将构建工件上载到名为CI构建的草稿中。该文件是例如位于
下https://github.com/an_organisation/a_project/releases/tag/untagged-1111aaaacccc0000dddd/filename.tar.gz
并且可以从浏览器访问和下载。
现在,我想从另一个AppVeyor项目(即appveyor.yml脚本)访问那些上传的工件。我尝试使用以下命令通过AppVeyor DownloadFile
命令,curl
和wget
下载没有成功
set DOWNLOAD_FILENAME=filename.tar.gz
set DOWNLOAD_ADDRESS=https://github.com/an_organisation/a_project/releases/download/untagged-1111aaaacccc0000dddd/$DOWNLOAD_FILENAME
wget --header "Authorization: token $GH_AUTH_TOKEN" --output-document=$DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS
wget --auth-no-challenge --header "Accept:application/octet-stream" --output-document=$DOWNLOAD_FILENAME "$DOWNLOAD_ADDRESS?access_token:$GH_AUTH_TOKEN"
curl -fsSL -G --user "$APPVEYOR_ACCOUNT_NAME:$GH_AUTH_TOKEN" -o $DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS
curl -fsSL -G -H "Authorization: token $GH_AUTH_TOKEN" -H "Accept: application/octet-stream" -o $DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS
curl -fsSL -G -H "Authorization: token $GH_AUTH_TOKEN" -H "Accept: application/octet-stream" -o $DOWNLOAD_FILENAME https://api.github.com/repos/an_organisation/a_project/releases/download/untagged-1111aaaacccc0000dddd/
慢慢地,我感觉无法通过GitHub API从草稿下载文件或下载链接。
下载这样的文件的正确命令是什么?
TLDR使用带有标题Get Release asset API的Accept: application/octet-stream
:
curl -OJ -L -H "Accept: application/octet-stream" \
-H "Authorization: Token $YOUR_TOKEN" \
"https://api.github.com/repos/$REPO/releases/assets/$ASSET_ID"
您需要拥有assetID。为了获得它,如果您还没有此信息,则需要releaseID,请使用GET /repos/:user/:repo/releases
:
GET /repos/:user/:repo/releases
然后使用curl -s -H "Authorization: Token $YOUR_TOKEN" \
"https://api.github.com/repos/$REPO/releases" | jq '.[] | {(.name): .id}'
获得资产ID:
GET /repos/:user/:repo/releases/:release_id
然后,一旦拥有assetID(也许已经拥有了它),您最终可以将GET /repos/:user/:repo/releases/:release_id
与标头curl -s -H "Authorization: Token $YOUR_TOKEN" \
"https://api.github.com/repos/$REPO/releases/$RELEASE_ID" | \
jq -r '.assets[] | {(.id |tostring): .name}'
一起使用。从GET /repos/:user/:repo/releases/assets/:asset_id
:
要下载资产的二进制内容,请设置请求到应用程序/八位字节流。该API将重定向客户到该位置,或在可能的情况下直接将其流式传输。 API客户端应该处理200或302响应。
以下内容在本地下载文件:
GET /repos/:user/:repo/releases/assets/:asset_id