|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2026 The kpt Authors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# This script generates the 'gh' commands to create the releases for KRM functions. |
| 18 | +# The single parameter filters the old releases list and bumps the patch version for |
| 19 | +# each KRM function on the list that matches the entered parameter. |
| 20 | + |
| 21 | +set -euo pipefail |
| 22 | + |
| 23 | +bump_patch() { |
| 24 | + old_ver="$1" |
| 25 | + |
| 26 | + # shellcheck disable=SC2001 |
| 27 | + ver_major_minor=$(echo "$old_ver" | sed 's/\.[0-9]*$//') |
| 28 | + # shellcheck disable=SC2001 |
| 29 | + ver_patch_old=$(echo "$old_ver" | sed 's/^v[0-9]*\.[0-9]*\.//') |
| 30 | + ver_patch_new=$((ver_patch_old+1)) |
| 31 | + echo "$ver_major_minor.$ver_patch_new" |
| 32 | +} |
| 33 | + |
| 34 | +upgrade_from() { |
| 35 | + name="$1" |
| 36 | + old_ver="$2" |
| 37 | + tag="$3" |
| 38 | + |
| 39 | + tag_prefix=$(echo "$tag" | sed 's/\/v[^/]*$//') |
| 40 | + new_ver="$(bump_patch "$old_ver")" |
| 41 | + |
| 42 | + release_tag="$tag_prefix/$new_ver" |
| 43 | + safe_release_tag=$(printf '%q' "$release_tag") |
| 44 | + title="$name $new_ver" |
| 45 | + safe_title=$(printf '%q' "$title") |
| 46 | + |
| 47 | + echo "gh release create $safe_release_tag --title $safe_title --generate-notes" |
| 48 | +} |
| 49 | + |
| 50 | +if [ -z "$1" ] |
| 51 | +then |
| 52 | + echo "Usage: $0 pattern"; |
| 53 | + echo " pattern: A pattern that filters the \"old\" revisions that we want to bump from" |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +# NOTE: This parsing assumes 'gh release list' outputs at least four space-separated columns. |
| 58 | +gh release list --limit 10000 | grep "$1" | sed 's/Latest//' | awk 'NF>=4 {printf("%s,%s,%s,%s\n", $1,$2,$3,$4)}' | \ |
| 59 | +while read -r line |
| 60 | +do |
| 61 | + IFS=',' read -r -a old_release <<< "$line" |
| 62 | + if [ "${#old_release[@]}" -lt 4 ]; then |
| 63 | + echo "Warning: unexpected format from 'gh release list', skipping line: $line" >&2 |
| 64 | + continue |
| 65 | + fi |
| 66 | + upgrade_from "${old_release[0]}" "${old_release[1]}" "${old_release[2]}" |
| 67 | +done |
0 commit comments