|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +# core-tags.sh: print NVIDIA/OpenShell release tags newer than the pin, |
| 5 | +# oldest first. |
| 6 | +# |
| 7 | +# Usage: core-tags.sh [--all] [--pin <tag>] |
| 8 | +# |
| 9 | +# Release tags are vX.Y.Z and vX.Y.Z-pre.N; a pre-release sorts below its |
| 10 | +# stable version. By default every newer stable tag is printed, plus the |
| 11 | +# newest pre-release when it is newer than all of them: one proposal for the |
| 12 | +# current release train instead of one per pre-release. --all prints every |
| 13 | +# newer tag. --pin overrides the pin, OPENSHELL_CORE_REF in mise.toml. |
| 14 | +set -euo pipefail |
| 15 | + |
| 16 | +repo=${CORE_REPO:-NVIDIA/OpenShell} |
| 17 | +all=0 |
| 18 | +pin= |
| 19 | + |
| 20 | +while [ $# -gt 0 ]; do |
| 21 | + case $1 in |
| 22 | + --all) all=1; shift ;; |
| 23 | + --pin) pin=${2:?--pin needs a tag}; shift 2 ;; |
| 24 | + *) echo "usage: $0 [--all] [--pin <tag>]" >&2; exit 2 ;; |
| 25 | + esac |
| 26 | +done |
| 27 | + |
| 28 | +[ -n "$pin" ] || pin=$(sed -n 's/^OPENSHELL_CORE_REF = "\(.*\)"$/\1/p' mise.toml) |
| 29 | +[ -n "$pin" ] || { echo "ERROR: no OPENSHELL_CORE_REF in mise.toml" >&2; exit 1; } |
| 30 | + |
| 31 | +# key <tag>: "major minor patch rank pre" with rank 1 for stable, 0 for pre. |
| 32 | +key() { |
| 33 | + awk -v t="$1" 'BEGIN { |
| 34 | + s = t; sub(/^v/, "", s) |
| 35 | + pre = ""; rank = 1 |
| 36 | + if (index(s, "-pre.")) { pre = substr(s, index(s, "-pre.") + 5); s = substr(s, 1, index(s, "-pre.") - 1); rank = 0 } |
| 37 | + split(s, v, ".") |
| 38 | + printf "%d %d %d %d %d\n", v[1], v[2], v[3], rank, (pre == "" ? 0 : pre) |
| 39 | + }' |
| 40 | +} |
| 41 | + |
| 42 | +newer=$( |
| 43 | + gh api --paginate "repos/$repo/git/matching-refs/tags/v" --jq '.[].ref' | |
| 44 | + sed 's#^refs/tags/##' | |
| 45 | + { grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-pre\.[0-9]+)?$' || true; } | |
| 46 | + while read -r t; do echo "$(key "$t") $t"; done | |
| 47 | + awk -v p="$(key "$pin")" ' |
| 48 | + BEGIN { split(p, k, " ") } |
| 49 | + { |
| 50 | + for (i = 1; i <= 5; i++) { |
| 51 | + if ($i + 0 > k[i] + 0) { print; next } |
| 52 | + if ($i + 0 < k[i] + 0) next |
| 53 | + } |
| 54 | + }' | |
| 55 | + sort -n -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 | |
| 56 | + awk '{ print $6 }' |
| 57 | +) |
| 58 | + |
| 59 | +[ -n "$newer" ] || exit 0 |
| 60 | +if [ "$all" -eq 1 ]; then |
| 61 | + echo "$newer" |
| 62 | + exit 0 |
| 63 | +fi |
| 64 | + |
| 65 | +# Stable tags, then the last tag if it is a pre-release (newer than every stable). |
| 66 | +grep -v -- '-pre\.' <<<"$newer" || true |
| 67 | +last=$(tail -1 <<<"$newer") |
| 68 | +case $last in *-pre.*) echo "$last" ;; esac |
0 commit comments