获取Github项目最新Release
使用GitHub的API可以很方便的获取开源项目的制品,可以帮助我们构建docker镜像,或者编写安装、更新软件的脚本。
获取最新的版本
使用GET访问https://api.github.com/repos/OWNER/REPO/releases/latest
需要将链接中的OWNER
更换为项目的所有者,REPO
更换为项目仓库名
响应结果中tag_name
表示发布的版本号,browser_download_url
表示下载路径
以frp项目为例:
curl -L https://api.github.com/repos/fatedier/frp/releases/latest
响应结果如下:
{
"url": "https://api.github.com/repos/fatedier/frp/releases/170802325",
"assets_url": "https://api.github.com/repos/fatedier/frp/releases/170802325/assets",
"upload_url": "https://uploads.github.com/repos/fatedier/frp/releases/170802325/assets{?name,label}",
"html_url": "https://github.com/fatedier/frp/releases/tag/v0.60.0",
"id": 170802325,
"author": {
"login": "fatedier",
"id": 7346661,
"node_id": "MDQ6VXNlcjczNDY2NjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/7346661?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fatedier",
"html_url": "https://github.com/fatedier",
"followers_url": "https://api.github.com/users/fatedier/followers",
"following_url": "https://api.github.com/users/fatedier/following{/other_user}",
"gists_url": "https://api.github.com/users/fatedier/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fatedier/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fatedier/subscriptions",
"organizations_url": "https://api.github.com/users/fatedier/orgs",
"repos_url": "https://api.github.com/users/fatedier/repos",
"events_url": "https://api.github.com/users/fatedier/events{/privacy}",
"received_events_url": "https://api.github.com/users/fatedier/received_events",
"type": "User",
"site_admin": false
},
"node_id": "RE_kwDOAuI0Q84KLjyV",
"tag_name": "v0.60.0",
"target_commitish": "dev",
"name": "v0.60.0",
"draft": false,
"prerelease": false,
"created_at": "2024-08-19T05:48:17Z",
"published_at": "2024-08-19T05:54:34Z",
"assets": [
{
"url": "https://api.github.com/repos/fatedier/frp/releases/assets/186829017",
"id": 186829017,
"node_id": "RA_kwDOAuI0Q84LIsjZ",
"name": "frp_0.60.0_android_arm64.tar.gz",
"label": "",
"uploader": {
"login": "fatedier",
"id": 7346661,
"node_id": "MDQ6VXNlcjczNDY2NjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/7346661?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fatedier",
"html_url": "https://github.com/fatedier",
"followers_url": "https://api.github.com/users/fatedier/followers",
"following_url": "https://api.github.com/users/fatedier/following{/other_user}",
"gists_url": "https://api.github.com/users/fatedier/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fatedier/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fatedier/subscriptions",
"organizations_url": "https://api.github.com/users/fatedier/orgs",
"repos_url": "https://api.github.com/users/fatedier/repos",
"events_url": "https://api.github.com/users/fatedier/events{/privacy}",
"received_events_url": "https://api.github.com/users/fatedier/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/gzip",
"state": "uploaded",
"size": 11821266,
"download_count": 677,
"created_at": "2024-08-19T05:54:33Z",
"updated_at": "2024-08-19T05:54:33Z",
"browser_download_url": "https://github.com/fatedier/frp/releases/download/v0.60.0/frp_0.60.0_android_arm64.tar.gz"
},
...
{
"url": "https://api.github.com/repos/fatedier/frp/releases/assets/186829000",
"id": 186829000,
"node_id": "RA_kwDOAuI0Q84LIsjI",
"name": "frp_sha256_checksums.txt",
"label": "",
"uploader": {
"login": "fatedier",
"id": 7346661,
"node_id": "MDQ6VXNlcjczNDY2NjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/7346661?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fatedier",
"html_url": "https://github.com/fatedier",
"followers_url": "https://api.github.com/users/fatedier/followers",
"following_url": "https://api.github.com/users/fatedier/following{/other_user}",
"gists_url": "https://api.github.com/users/fatedier/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fatedier/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fatedier/subscriptions",
"organizations_url": "https://api.github.com/users/fatedier/orgs",
"repos_url": "https://api.github.com/users/fatedier/repos",
"events_url": "https://api.github.com/users/fatedier/events{/privacy}",
"received_events_url": "https://api.github.com/users/fatedier/received_events",
"type": "User",
"site_admin": false
},
"content_type": "text/plain; charset=utf-8",
"state": "uploaded",
"size": 1547,
"download_count": 262,
"created_at": "2024-08-19T05:54:30Z",
"updated_at": "2024-08-19T05:54:31Z",
"browser_download_url": "https://github.com/fatedier/frp/releases/download/v0.60.0/frp_sha256_checksums.txt"
}
],
"tarball_url": "https://api.github.com/repos/fatedier/frp/tarball/v0.60.0",
"zipball_url": "https://api.github.com/repos/fatedier/frp/zipball/v0.60.0",
"body": "### Features\n\n* Added a new plugin `tls2raw`: Enables TLS termination and forwarding of decrypted raw traffic to local service.\n* Added a default timeout of 30 seconds for the frpc subcommands to prevent commands from being stuck for a long time due to network issues.\n\n### Fixes\n\n* Fixed the issue that when `loginFailExit = false`, the frpc stop command cannot be stopped correctly if the server is not successfully connected after startup.\n\n",
"reactions": {
"url": "https://api.github.com/repos/fatedier/frp/releases/170802325/reactions",
"total_count": 28,
"+1": 26,
"-1": 0,
"laugh": 0,
"hooray": 2,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
}
}