@marcel91200 / caddy Mirror · read-only
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

master
sh 41 lines 1.72 KB
Raw
1 #!/usr/bin/env bash
2 # Prints the tag of the highest published (non-draft) GitHub release whose
3 # version is lower than the given one, or nothing if there is none.
4 #
5 # Usage: previous-release.sh <version>
6 #
7 # Release changelogs should cover everything since the last release users
8 # actually received. "The last tag" is not good enough:
9 #
10 # - When a release attempt is abandoned after tagging, the Go module proxy
11 # has usually cached the tag, so it can't be deleted and reused, and the
12 # next attempt gets a new patch number. Those abandoned tags never get a
13 # published release, so they are skipped here.
14 # - Releases can be cut from maintenance branches (e.g. 2.11), so the
15 # previous release isn't necessarily an ancestor of the new one. Picking
16 # by version means 2.12.0 compares against the latest 2.11.x, and a 2.11.x
17 # released after 2.12.0 compares against the previous 2.11.x.
18 #
19 # Requires GH_TOKEN and GITHUB_REPOSITORY in the environment.
20 set -euo pipefail
21
22 version=${1:?usage: $0 <version>}
23
24 # sort -V orders "2.12.0-beta.1" after "2.12.0", but with the prerelease
25 # separator replaced by "~" (which sorts before everything, even the end of
26 # the string) it orders like semver.
27 sort_key() {
28 printf '%s' "${1#v}" | sed 's/-/~/'
29 }
30
31 tags=$(gh api --paginate "repos/${GITHUB_REPOSITORY}/releases" --jq '.[] | select(.draft | not) | .tag_name')
32
33 {
34 # The new version itself, marked by an empty tag column.
35 printf '%s\t\n' "$(sort_key "$version")"
36 grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$' <<< "$tags" | while IFS= read -r tag; do
37 if [ "$tag" != "$version" ]; then
38 printf '%s\t%s\n' "$(sort_key "$tag")" "$tag"
39 fi
40 done
41 } | sort -t $'\t' -k1,1V | awk -F '\t' '$2 == "" { print prev; exit } { prev = $2 }'