Skip to content

Commit 819ca2f

Browse files
committed
fix(bootstrap): support -N package-release suffix in Salt version strings
Salt patch releases now publish a -N package-release suffix (e.g. 3008.1-1) across every artifact type: RPM, APT, onedir tarballs, macOS pkgs, and GitHub release tags. Version-argument validation was unanchored and only tolerated the suffix by accident, then a blind hyphen-to-dot substitution corrupted it when building RPM package names and APT pins. Onedir/macOS/GitHub paths had no notion of the suffix at all. - Anchor version-argument validation into a shared __validate_salt_version_arg, accepting an rcN or -N suffix (not both) instead of the previous unanchored prefix match. - Replace the hyphen-to-dot mangling with __salt_version_string, a single verbatim-render helper used everywhere a validated version becomes a package name, apt pin, .repo section, tarball URL, or GitHub tag. - Treat -N as a real GA build rather than a prerelease: extend __salt_onedir_filter_ga_version_dirs (bootstrap-salt.sh) and Test-SaltOnedirVersionIsGA (bootstrap-salt.ps1) to accept it, and teach Compare-SaltCalVer to rank a -N build above the bare version it replaces, so latest/major-series resolution converges with what yum/apt already do natively. - Fix the GitHub tag_name regex in install_arch_linux_onedir, which previously matched nothing for a -N suffixed tag. RC handling (e.g. 3008.0rc1) is unchanged and was re-verified alongside the new -N cases.
1 parent e25bc06 commit 819ca2f

2 files changed

Lines changed: 87 additions & 43 deletions

File tree

bootstrap-salt.ps1

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,57 @@ function Get-MajorVersion {
158158
}
159159

160160
function Test-SaltOnedirVersionIsGA {
161-
# True if the onedir directory name is a GA CalVer (digits and dots only).
162-
# Prerelease dirs (e.g. 3008.0rc1) are not GA; install those only via exact
163-
# -Version matching the directory name.
161+
# True if the onedir directory name is a GA CalVer, optionally with a -N
162+
# package-release suffix (e.g. 3008.1 or 3008.1-1). Prerelease dirs (e.g.
163+
# 3008.0rc1) are not GA; install those only via exact -Version matching
164+
# the directory name. A -N suffix is a repackage of the same version, not
165+
# a prerelease, so it counts as GA and participates in latest/major-series
166+
# selection via Compare-SaltCalVer.
164167
[CmdletBinding()]
165168
param(
166169
[Parameter(Mandatory=$true)]
167170
[String] $Version
168171
)
169-
return [bool]( $Version -match '^\d+\.\d+(\.\d+)*$' )
172+
return [bool]( $Version -match '^\d+\.\d+(\.\d+)*(-\d+)?$' )
170173
}
171174

172175
function Compare-SaltCalVer {
173-
# Compare two GA numeric CalVer strings (e.g. 3006.24 vs 3007.0). Returns 1
174-
# if Left is greater than Right, -1 if less, 0 if equal.
176+
# Compare two GA CalVer strings, each optionally carrying a -N
177+
# package-release suffix (e.g. 3006.24, 3008.1-1). Returns 1 if Left is
178+
# greater than Right, -1 if less, 0 if equal. The dotted version is
179+
# compared first; a missing -N suffix is treated as release 0, so
180+
# 3008.1-1 compares greater than 3008.1.
175181
[CmdletBinding()]
176182
param(
177183
[Parameter(Mandatory=$true)]
178184
[String] $Left,
179185
[Parameter(Mandatory=$true)]
180186
[String] $Right
181187
)
182-
$left_parts = @( ($Left -split '\.') | ForEach-Object { [int]$_ } )
183-
$right_parts = @( ($Right -split '\.') | ForEach-Object { [int]$_ } )
184-
$max_len = [Math]::Max($left_parts.Count, $right_parts.Count)
188+
function Get-CalVerParts {
189+
param([String] $Version)
190+
$release = 0
191+
$dotted = $Version
192+
if ( $Version -match '^(.+)-(\d+)$' ) {
193+
$dotted = $Matches[1]
194+
$release = [int]$Matches[2]
195+
}
196+
return @{
197+
Dotted = @( ($dotted -split '\.') | ForEach-Object { [int]$_ } )
198+
Release = $release
199+
}
200+
}
201+
$left_parts = Get-CalVerParts $Left
202+
$right_parts = Get-CalVerParts $Right
203+
$max_len = [Math]::Max($left_parts.Dotted.Count, $right_parts.Dotted.Count)
185204
for ( $i = 0; $i -lt $max_len; $i++ ) {
186-
$a = if ( $i -lt $left_parts.Count ) { $left_parts[$i] } else { 0 }
187-
$b = if ( $i -lt $right_parts.Count ) { $right_parts[$i] } else { 0 }
205+
$a = if ( $i -lt $left_parts.Dotted.Count ) { $left_parts.Dotted[$i] } else { 0 }
206+
$b = if ( $i -lt $right_parts.Dotted.Count ) { $right_parts.Dotted[$i] } else { 0 }
188207
if ( $a -gt $b ) { return 1 }
189208
if ( $a -lt $b ) { return -1 }
190209
}
210+
if ( $left_parts.Release -gt $right_parts.Release ) { return 1 }
211+
if ( $left_parts.Release -lt $right_parts.Release ) { return -1 }
191212
return 0
192213
}
193214

bootstrap-salt.sh

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,33 @@ ONEDIR_REV="latest"
617617
_ONEDIR_REV="latest"
618618
YUM_REPO_FILE="/etc/yum.repos.d/salt.repo"
619619

620+
#--- FUNCTION -------------------------------------------------------------------------------------------------------
621+
# NAME: __validate_salt_version_arg
622+
# DESCRIPTION: True (status 0) if $1 is a valid Salt version argument:
623+
# latest, a bare 4-digit major version, or MAJOR.MINOR[.MICRO]
624+
# with at most one of an rcN prerelease suffix or a -N
625+
# package-release suffix (e.g. 3006, 3008.1, 3008.0rc1, 3008.1-1).
626+
#----------------------------------------------------------------------------------------------------------------------
627+
__validate_salt_version_arg() {
628+
echo "$1" | grep -qE '^(latest|[0-9]{4}(\.[0-9]+(\.[0-9]+)*(rc[0-9]+|-[0-9]+)?)?)$'
629+
}
630+
631+
#--- FUNCTION -------------------------------------------------------------------------------------------------------
632+
# NAME: __salt_version_string
633+
# DESCRIPTION: Render a validated Salt version string verbatim for use in
634+
# an RPM package name, an APT pin, a .repo section name, an
635+
# onedir/macOS tarball URL, or a GitHub release tag. A -N
636+
# package-release suffix (e.g. 3008.1-1) is a real, published
637+
# repackage of the same version across every artifact type
638+
# (RPM, APT, onedir, macOS, GitHub releases), so it must be
639+
# preserved verbatim everywhere rather than stripped or
640+
# rejected; rcN prerelease suffixes never contain a hyphen so
641+
# they pass through unchanged too.
642+
#----------------------------------------------------------------------------------------------------------------------
643+
__salt_version_string() {
644+
echo "$1"
645+
}
646+
620647
# check if systemd is functional
621648
__check_services_systemd_functional
622649

@@ -664,13 +691,7 @@ elif [ "$ITYPE" = "stable" ]; then
664691
_ONEDIR_REV="latest"
665692
ITYPE="onedir"
666693
else
667-
if [ "$(echo "$1" | grep -E '^(latest|[0-9]{4})$')" != "" ]; then
668-
STABLE_REV="$1"
669-
ONEDIR_REV="$1"
670-
_ONEDIR_REV="$1"
671-
ITYPE="onedir"
672-
shift
673-
elif [ "$(echo "$1" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
694+
if __validate_salt_version_arg "$1"; then
674695
STABLE_REV="$1"
675696
ONEDIR_REV="$1"
676697
_ONEDIR_REV="$1"
@@ -687,11 +708,7 @@ elif [ "$ITYPE" = "onedir" ]; then
687708
ONEDIR_REV="latest"
688709
STABLE_REV="latest"
689710
else
690-
if [ "$(echo "$1" | grep -E '^(latest|[0-9]{4})$')" != "" ]; then
691-
ONEDIR_REV="$1"
692-
STABLE_REV="$1"
693-
shift
694-
elif [ "$(echo "$1" | grep -E '^([3-9][0-9]{3}(\.[0-9]*)?)')" != "" ]; then
711+
if __validate_salt_version_arg "$1"; then
695712
ONEDIR_REV="$1"
696713
STABLE_REV="$1"
697714
shift
@@ -3067,7 +3084,7 @@ __install_saltstack_ubuntu_onedir_repository() {
30673084
echo "Pin: version $ONEDIR_REV.*" >> /etc/apt/preferences.d/salt-pin-1001
30683085
echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/salt-pin-1001
30693086
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
3070-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
3087+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
30713088
echo "Package: salt-*" > /etc/apt/preferences.d/salt-pin-1001
30723089
echo "Pin: version $ONEDIR_REV_DOT" >> /etc/apt/preferences.d/salt-pin-1001
30733090
echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/salt-pin-1001
@@ -3519,7 +3536,7 @@ __install_saltstack_debian_repository() {
35193536
echo "Pin: version $STABLE_REV.*" >> /etc/apt/preferences.d/salt-pin-1001
35203537
echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/salt-pin-1001
35213538
elif [ "$(echo "$STABLE_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
3522-
STABLE_REV_DOT=$(echo "$STABLE_REV" | sed 's/-/\./')
3539+
STABLE_REV_DOT=$(__salt_version_string "$STABLE_REV")
35233540
MINOR_VER_STRG="-$STABLE_REV_DOT"
35243541
echo "Package: salt-*" > /etc/apt/preferences.d/salt-pin-1001
35253542
echo "Pin: version $STABLE_REV_DOT" >> /etc/apt/preferences.d/salt-pin-1001
@@ -3565,7 +3582,7 @@ __install_saltstack_debian_onedir_repository() {
35653582
echo "Pin: version $ONEDIR_REV.*" >> /etc/apt/preferences.d/salt-pin-1001
35663583
echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/salt-pin-1001
35673584
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
3568-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
3585+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
35693586
echo "Package: salt-*" > /etc/apt/preferences.d/salt-pin-1001
35703587
echo "Pin: version $ONEDIR_REV_DOT" >> /etc/apt/preferences.d/salt-pin-1001
35713588
echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/salt-pin-1001
@@ -3915,7 +3932,7 @@ __install_saltstack_fedora_onedir_repository() {
39153932
fi
39163933
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
39173934
# using minor version
3918-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
3935+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
39193936
echo "[salt-repo-${ONEDIR_REV_DOT}-lts]" > "${YUM_REPO_FILE}"
39203937
# shellcheck disable=SC2129
39213938
echo "name=Salt Repo for Salt v${ONEDIR_REV_DOT} LTS" >> "${YUM_REPO_FILE}"
@@ -4152,7 +4169,7 @@ install_fedora_onedir() {
41524169
MINOR_VER_STRG=""
41534170
elif [ "$(echo "$STABLE_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
41544171
# Minor version Salt, need to add specific minor version
4155-
STABLE_REV_DOT=$(echo "$STABLE_REV" | sed 's/-/\./')
4172+
STABLE_REV_DOT=$(__salt_version_string "$STABLE_REV")
41564173
MINOR_VER_STRG="-$STABLE_REV_DOT"
41574174
else
41584175
MINOR_VER_STRG=""
@@ -4245,7 +4262,7 @@ __install_saltstack_rhel_onedir_repository() {
42454262
fi
42464263
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
42474264
# using minor version
4248-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
4265+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
42494266
echo "[salt-repo-${ONEDIR_REV_DOT}-lts]" > "${YUM_REPO_FILE}"
42504267
# shellcheck disable=SC2129
42514268
echo "name=Salt Repo for Salt v${ONEDIR_REV_DOT} LTS" >> "${YUM_REPO_FILE}"
@@ -4317,7 +4334,7 @@ install_centos_stable() {
43174334
MINOR_VER_STRG=""
43184335
elif [ "$(echo "$STABLE_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
43194336
# Minor version Salt, need to add specific minor version
4320-
STABLE_REV_DOT=$(echo "$STABLE_REV" | sed 's/-/\./')
4337+
STABLE_REV_DOT=$(__salt_version_string "$STABLE_REV")
43214338
MINOR_VER_STRG="-$STABLE_REV_DOT"
43224339
else
43234340
MINOR_VER_STRG=""
@@ -4537,7 +4554,7 @@ install_centos_onedir() {
45374554
MINOR_VER_STRG=""
45384555
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
45394556
# Minor version Salt, need to add specific minor version
4540-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
4557+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
45414558
MINOR_VER_STRG="-$ONEDIR_REV_DOT"
45424559
else
45434560
MINOR_VER_STRG=""
@@ -5697,7 +5714,7 @@ install_amazon_linux_ami_2_deps() {
56975714
fi
56985715
elif [ "$(echo "$STABLE_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
56995716
# using minor version
5700-
STABLE_REV_DOT=$(echo "$STABLE_REV" | sed 's/-/\./')
5717+
STABLE_REV_DOT=$(__salt_version_string "$STABLE_REV")
57015718
echo "[salt-repo-${STABLE_REV_DOT}-lts]" > "${YUM_REPO_FILE}"
57025719
echo "name=Salt Repo for Salt v${STABLE_REV_DOT} LTS" >> "${YUM_REPO_FILE}"
57035720
echo "baseurl=https://${_REPO_URL}/saltproject-rpm/" >> "${YUM_REPO_FILE}"
@@ -5798,7 +5815,7 @@ install_amazon_linux_ami_2_onedir_deps() {
57985815
fi
57995816
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
58005817
# using minor version
5801-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
5818+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
58025819
echo "[salt-repo-${ONEDIR_REV_DOT}-lts]" > "${YUM_REPO_FILE}"
58035820
echo "name=Salt Repo for Salt v${ONEDIR_REV_DOT} LTS" >> "${YUM_REPO_FILE}"
58045821
echo "baseurl=https://${_REPO_URL}/saltproject-rpm/" >> "${YUM_REPO_FILE}"
@@ -5991,7 +6008,7 @@ install_amazon_linux_ami_2023_onedir_deps() {
59916008
fi
59926009
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
59936010
# using minor version
5994-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
6011+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
59956012
echo "[salt-repo-${ONEDIR_REV_DOT}-lts]" > "${YUM_REPO_FILE}"
59966013
echo "name=Salt Repo for Salt v${ONEDIR_REV_DOT} LTS" >> "${YUM_REPO_FILE}"
59976014
echo "baseurl=https://${_REPO_URL}/saltproject-rpm/" >> "${YUM_REPO_FILE}"
@@ -6217,10 +6234,12 @@ install_arch_linux_onedir() {
62176234
# Resolve "latest" to actual version
62186235
if [ "$version" = "latest" ]; then
62196236
version=$(wget -qO- https://api.github.com/repos/saltstack/salt/releases/latest \
6220-
| grep -Eo '"tag_name": *"v[0-9.]+"' \
6237+
| grep -Eo '"tag_name": *"v[0-9.]+(-[0-9]+)?"' \
62216238
| sed 's/"tag_name": *"v//;s/"//') || return 1
62226239
fi
62236240

6241+
version=$(__salt_version_string "$version")
6242+
62246243
tarball="salt-${version}-onedir-linux-${arch}.tar.xz"
62256244
url="https://github.com/saltstack/salt/releases/download/v${version}/${tarball}"
62266245
extractdir="/tmp/salt-${version}-onedir-linux-${arch}"
@@ -6439,11 +6458,15 @@ EOF
64396458

64406459
#--- FUNCTION -------------------------------------------------------------------------------------------------------
64416460
# NAME: __salt_onedir_filter_ga_version_dirs
6442-
# DESCRIPTION: From stdin: keep only GA CalVer-style directory names (digits and dots;
6443-
# prerelease dirs like 3008.0rc1 are excluded).
6461+
# DESCRIPTION: From stdin: keep only GA CalVer-style directory names (digits
6462+
# and dots, with an optional -N package-release suffix, e.g.
6463+
# 3008.1 or 3008.1-1). Prerelease dirs like 3008.0rc1 are
6464+
# excluded; sort -V already orders 3008.1-1 after 3008.1, so
6465+
# "latest"/major-only resolution naturally prefers a -N
6466+
# repackage over the bare version it replaces.
64446467
#----------------------------------------------------------------------------------------------------------------------
64456468
__salt_onedir_filter_ga_version_dirs() {
6446-
grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)*$'
6469+
grep -E '^[0-9]+\.[0-9]+(\.[0-9]+)*(-[0-9]+)?$'
64476470
}
64486471

64496472
#--- FUNCTION -------------------------------------------------------------------------------------------------------
@@ -6544,7 +6567,7 @@ __install_saltstack_vmware_photon_os_onedir_repository() {
65446567
fi
65456568
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
65466569
# using minor version
6547-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
6570+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
65486571
echo "[salt-repo-${ONEDIR_REV_DOT}-lts]" > "${YUM_REPO_FILE}"
65496572
echo "name=Salt Repo for Salt v${ONEDIR_REV_DOT} LTS" >> "${YUM_REPO_FILE}"
65506573
echo "baseurl=https://${_REPO_URL}/saltproject-rpm/" >> "${YUM_REPO_FILE}"
@@ -6837,7 +6860,7 @@ install_vmware_photon_os_onedir() {
68376860
MINOR_VER_STRG="-$_GENERIC_PKG_VERSION"
68386861
elif [ "$(echo "$STABLE_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
68396862
# Minor version Salt, need to add specific minor version
6840-
STABLE_REV_DOT=$(echo "$STABLE_REV" | sed 's/-/\./')
6863+
STABLE_REV_DOT=$(__salt_version_string "$STABLE_REV")
68416864
MINOR_VER_STRG="-$STABLE_REV_DOT"
68426865
else
68436866
# default to latest version Salt, config and repo already setup
@@ -6945,7 +6968,7 @@ __check_and_refresh_suse_pkg_repo() {
69456968
fi
69466969
elif [ "$(echo "$ONEDIR_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
69476970
# using minor version
6948-
ONEDIR_REV_DOT=$(echo "$ONEDIR_REV" | sed 's/-/\./')
6971+
ONEDIR_REV_DOT=$(__salt_version_string "$ONEDIR_REV")
69496972
echo "[salt-repo-${ONEDIR_REV_DOT}-lts]" > "${ZYPPER_REPO_FILE}"
69506973
echo "name=Salt Repo for Salt v${ONEDIR_REV_DOT} LTS" >> "${ZYPPER_REPO_FILE}"
69516974
echo "baseurl=https://${_REPO_URL}/saltproject-rpm/" >> "${ZYPPER_REPO_FILE}"
@@ -7109,7 +7132,7 @@ install_opensuse_stable() {
71097132
MINOR_VER_STRG=""
71107133
elif [ "$(echo "$STABLE_REV" | grep -E '^([3-9][0-5]{2}[6-9](\.[0-9]*)?)')" != "" ]; then
71117134
# Minor version Salt, need to add specific minor version
7112-
STABLE_REV_DOT=$(echo "$STABLE_REV" | sed 's/-/\./')
7135+
STABLE_REV_DOT=$(__salt_version_string "$STABLE_REV")
71137136
MINOR_VER_STRG="-$STABLE_REV_DOT"
71147137
else
71157138
MINOR_VER_STRG=""
@@ -7978,7 +8001,7 @@ __macosx_get_packagesite_onedir() {
79788001
# need to get latest for major version
79798002
__macosx_get_packagesite_onedir_latest "$_ONEDIR_REV" || return 1
79808003
elif [ "$(echo "$_ONEDIR_REV" | grep -E '^([3-9][0-9]{3}(\.[0-9]*)?)')" != "" ]; then
7981-
_PKG_VERSION=$_ONEDIR_REV
8004+
_PKG_VERSION=$(__salt_version_string "$_ONEDIR_REV")
79828005
else
79838006
# default to getting latest
79848007
__macosx_get_packagesite_onedir_latest || return 1

0 commit comments

Comments
 (0)