-
Notifications
You must be signed in to change notification settings - Fork 263
Expand file tree
/
Copy pathcompute-rancher-versions.sh
More file actions
executable file
·74 lines (63 loc) · 2.68 KB
/
compute-rancher-versions.sh
File metadata and controls
executable file
·74 lines (63 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# Compute the Fleet and Rancher versions needed to open a release PR.
#
# Environment variables:
# FLEET_BRANCH Fleet branch to release (e.g. release/v0.15 or main)
# GH_TOKEN GitHub token for API calls
# FLEET_REPO_DIR Path to the fleet checkout (default: ./fleet)
# GITHUB_OUTPUT Path to the GitHub Actions output file
set -euo pipefail
FLEET_REPO_DIR="${FLEET_REPO_DIR:-./fleet}"
# Derive the Fleet minor version from the branch name.
# For main, compute it as (highest release branch minor) + 1.
if [ "$FLEET_BRANCH" = "main" ]; then
highest_minor=$(git -C "$FLEET_REPO_DIR" ls-remote --heads origin 'refs/heads/release/v0.*' \
| grep -oE 'v0\.[0-9]+' | cut -d. -f2 | sort -n | tail -1)
if [ -z "$highest_minor" ]; then
printf 'ERROR: No release/v0.* branches found in fleet repo\n' >&2
exit 1
fi
fleet_minor=$((highest_minor + 1))
else
fleet_minor=$(printf '%s' "$FLEET_BRANCH" | grep -oE '[0-9]+$')
fi
rancher_minor=$((fleet_minor - 1))
charts_branch="dev-v2.${rancher_minor}"
# Fetch the Fleet chart directory listing from the rancher/charts dev branch.
chart_response=$(curl -fsSL \
-H "Authorization: Bearer ${GH_TOKEN}" \
"https://api.github.com/repos/rancher/charts/contents/charts/fleet?ref=${charts_branch}") || {
printf 'ERROR: Could not list Fleet charts in rancher/charts branch %s\n' "$charts_branch" >&2
exit 1
}
latest_chart=$(printf '%s' "$chart_response" \
| jq -r '.[] | select(.type == "dir") | .name' \
| sort -V | tail -1)
if [ -z "$latest_chart" ]; then
printf 'ERROR: No Fleet chart directories found in rancher/charts branch %s\n' "$charts_branch" >&2
exit 1
fi
# Chart directory names follow the pattern <chart-version>+up<fleet-version>,
# e.g. 110.0.1+up0.15.1.
new_fleet="${latest_chart##*+up}"
new_chart="${latest_chart%%+*}"
# Target the Rancher release branch when it exists; fall back to main.
rancher_ref="release/v2.${rancher_minor}"
http_status=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: Bearer ${GH_TOKEN}" \
"https://api.github.com/repos/rancher/rancher/branches/release%2Fv2.${rancher_minor}")
case "$http_status" in
200) ;;
404) rancher_ref="main" ;;
*) printf 'ERROR: GitHub API returned HTTP %s while checking Rancher branch\n' "$http_status" >&2; exit 1 ;;
esac
printf 'Charts branch: %s\n' "$charts_branch"
printf 'New Fleet version: %s\n' "$new_fleet"
printf 'New chart version: %s\n' "$new_chart"
printf 'Rancher ref: %s\n' "$rancher_ref"
{
printf 'new_fleet=%s\n' "$new_fleet"
printf 'new_chart=%s\n' "$new_chart"
printf 'rancher_ref=%s\n' "$rancher_ref"
} >> "${GITHUB_OUTPUT:?GITHUB_OUTPUT is not set}"