1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/scripts/get-releases.sh
Carlos Alexandro Becker 232c982fb0
docs: improve build (#3674)
- generate releases.json et al on our github actions workflow
- use those when building and also on our `run` script
- new releases will dispatch the workflow so it re-generates the needed
files

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2022-12-29 14:55:45 -03:00

38 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
get_last_page() {
local url="$1"
curl -sSf -I -H "Authorization: Bearer $GITHUB_TOKEN" \
"$url" |
grep -E '^link: ' |
sed -e 's/^link:.*page=//g' -e 's/>.*$//g' || echo "1"
}
generate() {
local url="$1"
local file="$2"
last_page="$(get_last_page "$url")"
tmp="$(mktemp -d)"
for i in $(seq -w 1 "$last_page"); do
echo "page: $i"
curl -H "Authorization: Bearer $GITHUB_TOKEN" -sSf "$url?page=$i" | jq 'map({tag_name: .tag_name})' >"$tmp/$i.json"
done
jq -s 'add' "$tmp"/*.json >"$file"
du -hs "$file"
}
latest() {
local url="$1"
local file="$2"
curl -sfL "$url/latest" | jq -r ".tag_name" >"$file"
du -hs "$file"
}
latest "https://api.github.com/repos/goreleaser/goreleaser/releases" "www/docs/static/latest"
latest "https://api.github.com/repos/goreleaser/goreleaser-pro/releases" "www/docs/static/latest-pro"
generate "https://api.github.com/repos/goreleaser/goreleaser/releases" "www/docs/static/releases.json"
generate "https://api.github.com/repos/goreleaser/goreleaser-pro/releases" "www/docs/static/releases-pro.json"