11#! /bin/bash
22#
3- # Submit new Fleet version against rancher/rancher
3+ # Submit new Fleet version against rancher/rancher.
44
5- set -ue
5+ set -euo pipefail
66
7- NEW_FLEET_VERSION=" $1 " # e.g. 0.6.0-rc.3
8- NEW_CHART_VERSION=" $2 " # e.g. 101.1.0
9- BUMP_API=" $3 " # bump api if `true`
7+ NEW_FLEET_VERSION=" $1 " # e.g. 0.15.1
8+ NEW_CHART_VERSION=" $2 " # e.g. 110.0.1
109
1110bump_fleet_api () {
12- COMMIT=$1
13-
14- go get -u " github.com/rancher/fleet/pkg/apis@v${NEW_FLEET_VERSION} " || go get -u " github.com/rancher/fleet/pkg/apis@${COMMIT} "
11+ go get -u " github.com/rancher/fleet/pkg/apis@v${NEW_FLEET_VERSION} "
1512 go mod tidy
1613}
1714
18- RANCHER_DIR=${RANCHER_DIR-" $( dirname -- " $0 " ) /../../../rancher" }
15+ RANCHER_DIR=" ${RANCHER_DIR: -" $( dirname -- " $0 " ) /../../../rancher" } "
1916
2017pushd " ${RANCHER_DIR} " > /dev/null
2118
@@ -24,35 +21,60 @@ if [ ! -e ~/.gitconfig ]; then
2421 git config --global user.email fleet@suse.de
2522fi
2623
27- # Check if version is available online
28- CHART_DEFAULT_BRANCH=$( grep " ARG CHART_DEFAULT_BRANCH=" package/Dockerfile | cut -d' =' -f2)
29- if ! curl -s --head --fail " https://github.com/rancher/charts/raw/${CHART_DEFAULT_BRANCH} /assets/fleet/fleet-${NEW_CHART_VERSION} +up${NEW_FLEET_VERSION} .tgz" > /dev/null; then
30- echo " Version ${NEW_CHART_VERSION} +up${NEW_FLEET_VERSION} does not exist in the branch ${CHART_DEFAULT_BRANCH} in rancher/charts"
24+ # Guard: error if rancher/rancher already has this version or a newer one.
25+ if [ ! -f build.yaml ]; then
26+ printf ' ERROR: build.yaml not found in %s\n' " $( pwd) " >&2
3127 exit 1
3228fi
3329
34- if [ -e build.yaml ]; then
35- sed -i -e " s/fleetVersion: .*$/fleetVersion: ${NEW_CHART_VERSION} +up${NEW_FLEET_VERSION} /" build.yaml
36- go generate
37- git add build.yaml pkg/buildconfig/constants.go
38- else
39- sed -i -e " s/ENV CATTLE_FLEET_VERSION=.*$/ENV CATTLE_FLEET_VERSION=${NEW_CHART_VERSION} +up${NEW_FLEET_VERSION} /" package/Dockerfile
40- sed -i -e " s/ENV CATTLE_FLEET_MIN_VERSION=.*$/ENV CATTLE_FLEET_MIN_VERSION=${NEW_CHART_VERSION} +up${NEW_FLEET_VERSION} /" package/Dockerfile
41- git add package/Dockerfile
30+ TARGET_VERSION=" ${NEW_CHART_VERSION} +up${NEW_FLEET_VERSION} "
31+ CURRENT_VERSION=$( grep ' fleetVersion:' build.yaml | awk ' {print $2}' )
32+
33+ if [ -z " $CURRENT_VERSION " ]; then
34+ printf ' ERROR: fleetVersion not found in build.yaml\n' >&2
35+ exit 1
4236fi
4337
44- if [ " ${BUMP_API} " == " true" ]; then
45- pushd ../fleet > /dev/null
46- COMMIT=$( git rev-list -n 1 " v${NEW_FLEET_VERSION} " )
47- popd > /dev/null
38+ if [ " $CURRENT_VERSION " = " $TARGET_VERSION " ]; then
39+ printf ' ERROR: rancher/rancher already contains Fleet %s\n' " $TARGET_VERSION " >&2
40+ exit 1
41+ fi
42+
43+ # Compare only the chart version numbers (before the '+') to detect downgrades.
44+ current_chart=" ${CURRENT_VERSION%% +* } "
45+ target_chart=" ${TARGET_VERSION%% +* } "
46+ if [ " $( printf ' %s\n%s\n' " $current_chart " " $target_chart " | sort -V | tail -1) " = " $current_chart " ] \
47+ && [ " $current_chart " != " $target_chart " ]; then
48+ printf ' ERROR: rancher/rancher already has a newer Fleet version: %s\n' " $CURRENT_VERSION " >&2
49+ exit 1
50+ fi
51+
52+ # Guard against replacing a final release with a pre-release of the same or older base.
53+ # sort -V treats "0.11.12-rc.3" > "0.11.12" (lexicographic suffix), so pre-release
54+ # vs final requires an explicit check.
55+ current_fleet=" ${CURRENT_VERSION##* +up} "
56+ if ! printf ' %s' " $current_fleet " | grep -q ' -' && printf ' %s' " $NEW_FLEET_VERSION " | grep -q ' -' ; then
57+ target_fleet_base=" ${NEW_FLEET_VERSION%% -* } "
58+ if [ " $( printf ' %s\n%s\n' " $current_fleet " " $target_fleet_base " | sort -V | tail -1) " = " $current_fleet " ]; then
59+ printf ' ERROR: rancher/rancher has final Fleet %s; refusing pre-release %s\n' \
60+ " $current_fleet " " $NEW_FLEET_VERSION " >&2
61+ exit 1
62+ fi
63+ fi
64+
65+ sed -i " s/fleetVersion: .*$/fleetVersion: ${TARGET_VERSION} /" build.yaml
66+ go generate
67+ git add build.yaml pkg/buildconfig/constants.go
4868
49- bump_fleet_api " ${COMMIT} "
69+ # Bump the Fleet API when a pkg/apis tag for this exact version exists in the fleet repo.
70+ if git -C ../fleet tag -l " pkg/apis/v${NEW_FLEET_VERSION} " | grep -q . ; then
71+ bump_fleet_api
5072
5173 pushd pkg/apis > /dev/null
52- bump_fleet_api " ${COMMIT} "
74+ bump_fleet_api
5375 popd > /dev/null
5476
55- git add go.* pkg/apis/go.*
77+ git add go.mod go.sum pkg/apis/go.mod pkg/apis/go.sum
5678fi
5779
5880git commit -m " Updating to Fleet v${NEW_FLEET_VERSION} "
0 commit comments