github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/scripts/get-releases.sh (about) 1 #!/bin/bash 2 set -euo pipefail 3 4 get_last_page() { 5 local url="$1" 6 curl -sSf -I -H "Authorization: Bearer $GITHUB_TOKEN" \ 7 "$url" | 8 grep -E '^link: ' | 9 sed -e 's/^link:.*page=//g' -e 's/>.*$//g' || echo "1" 10 } 11 12 generate() { 13 local url="$1" 14 local file="$2" 15 last_page="$(get_last_page "$url")" 16 tmp="$(mktemp -d)" 17 18 for i in $(seq 1 "$last_page"); do 19 echo "page: $i" 20 curl -H "Authorization: Bearer $GITHUB_TOKEN" -sSf "$url?page=$i" >"$tmp/$i.json" 21 done 22 23 if test "$last_page" -eq "1"; then 24 jq --compact-output 'map({tag_name: .tag_name})' "$tmp"/1.json >"$file" 25 else 26 jq --compact-output '[inputs] | add | map({tag_name: .tag_name})' "$tmp"/*.json >"$file" 27 fi 28 du -hs "$file" 29 } 30 31 generate "https://api.github.com/repos/goreleaser/goreleaser/releases" "www/docs/static/releases.json" 32 generate "https://api.github.com/repos/goreleaser/goreleaser-pro/releases" "www/docs/static/releases-pro.json"