Skip to content

Commit 8ea5b31

Browse files
authored
Check differences in OBS branches in CI (#246)
Signed-off-by: Antonio Gamez Diaz <antonio.gamez@suse.com>
1 parent 758df6d commit 8ea5b31

3 files changed

Lines changed: 158 additions & 9 deletions

File tree

.github/scripts/helm-upgrade-helper.sh

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ banner() {
3131
printf '%s\n' "╚════════════════════════════════════════════════════════════════════════╝"
3232
}
3333

34+
# Print a separator line.
35+
separator() {
36+
printf '─%.0s' {1..72}
37+
printf '\n'
38+
}
39+
3440
# === Kubernetes Diagnostics ===
3541

3642
# Display status of all pods and highlight non-running pods.
@@ -66,22 +72,19 @@ show_events() {
6672
# Args: $1 (string, optional) - Number of log lines per pod (default: 30, 0 for all)
6773
# $2 (string, optional) - Context prefix for section header (e.g., "Recent ")
6874
# $3 (string, optional) - Whether to show previous container logs (default: false)
69-
# $4 (string, optional) - Custom separator line
7075
# Uses: TRENTO_NAMESPACE environment variable
7176
# Outputs: Pod logs for each container
7277
show_pod_logs() {
7378
local log_lines="${1:-30}"
7479
local log_context="${2:-}"
7580
local show_previous="${3:-false}"
76-
local separator="${4:-────────────────────────────────────────────────────────────────────────}"
77-
7881
section "=== ${log_context}Pod logs (last $log_lines lines each) ==="
7982
local pod
8083
for pod in $(kubectl get pods -n "$TRENTO_NAMESPACE" -o jsonpath='{.items[*].metadata.name}'); do
8184
echo ""
82-
echo "$separator"
85+
separator
8386
echo "Pod: $pod"
84-
echo "$separator"
87+
separator
8588
kubectl logs -n "$TRENTO_NAMESPACE" "$pod" --all-containers=true --tail="$log_lines" --ignore-errors=true || echo "No logs available"
8689

8790
if [ "$show_previous" = "true" ]; then
@@ -102,9 +105,9 @@ show_failed_pod_logs() {
102105
if [ -n "$failed_pods" ]; then
103106
for pod in $failed_pods; do
104107
echo ""
105-
echo "────────────────────────────────────────────────────────────────────────"
108+
separator
106109
echo "Pod: $pod (last 100 lines)"
107-
echo "────────────────────────────────────────────────────────────────────────"
110+
separator
108111
kubectl logs -n "$TRENTO_NAMESPACE" "$pod" --all-containers=true --tail=100 --ignore-errors=true || echo "No logs available"
109112
done
110113
else
@@ -150,7 +153,7 @@ compare_versions() {
150153
if [ "$chart_name" != "$current_chart" ]; then
151154
if [ -n "$current_chart" ]; then echo ""; fi
152155
echo "📦 Chart: ${chart_name}"
153-
echo "────────────────────────────────────────────────────────────────────────"
156+
separator
154157
current_chart="$chart_name"
155158
fi
156159

@@ -182,7 +185,7 @@ compare_versions() {
182185
done < "$new_images_file"
183186

184187
echo ""
185-
echo "────────────────────────────────────────────────────────────────────────"
188+
separator
186189
}
187190

188191
# Extract and compare container versions between deployed pods and Helm chart.
@@ -602,6 +605,57 @@ process_obs_package() {
602605
return 0
603606
}
604607

608+
# Compare OBS stable and main branches values.yaml
609+
# Args: $1 (string) - Path to stable branch values.yaml
610+
# $2 (string) - Path to main branch values.yaml
611+
# Returns: 0 if identical, 1 if different, 2 on error
612+
# Outputs: Formatted diff showing differences
613+
compare_obs_branches() {
614+
local stable_values="$1"
615+
local main_values="$2"
616+
617+
if [ ! -f "$stable_values" ]; then
618+
echo "ERROR: Stable values file not found: $stable_values" >&2
619+
return 2
620+
fi
621+
622+
if [ ! -f "$main_values" ]; then
623+
echo "ERROR: Main values file not found: $main_values" >&2
624+
return 2
625+
fi
626+
627+
banner " Comparing OBS stable vs main branch values.yaml "
628+
629+
local tmp_diff
630+
tmp_diff="$(mktemp)"
631+
632+
local diff_rc=0
633+
diff -u "$stable_values" "$main_values" > "$tmp_diff" || diff_rc=$?
634+
635+
if [ "$diff_rc" -eq 0 ]; then
636+
echo "✅ No differences between OBS stable and main branches"
637+
rm -f "$tmp_diff"
638+
return 0
639+
fi
640+
641+
if [ "$diff_rc" -ne 1 ]; then
642+
echo "ERROR: diff failed (exit $diff_rc) while comparing $stable_values and $main_values" >&2
643+
if [ -s "$tmp_diff" ]; then
644+
cat "$tmp_diff"
645+
fi
646+
rm -f "$tmp_diff"
647+
return 2
648+
fi
649+
650+
section "=== Differences found between OBS stable and main ==="
651+
cat "$tmp_diff"
652+
rm -f "$tmp_diff"
653+
echo ""
654+
separator
655+
echo "NOTE: These differences may indicate that stable needs to be updated"
656+
return 1
657+
}
658+
605659
main() {
606660
case "${1:-}" in
607661
post-install-diagnostics)
@@ -623,6 +677,10 @@ main() {
623677
shift
624678
process_obs_package "$@"
625679
;;
680+
compare-obs-branches)
681+
shift
682+
compare_obs_branches "$@"
683+
;;
626684
*)
627685
printf '%s\n' "Usage: upgrade-test.sh <command>" >&2
628686
printf '%s\n' "" >&2
@@ -633,6 +691,7 @@ main() {
633691
printf '%s\n' " verify-api" >&2
634692
printf '%s\n' " failure-diagnostics" >&2
635693
printf '%s\n' " process-obs-package <git-url> [workspace-dir]" >&2
694+
printf '%s\n' " compare-obs-branches <stable-values> <main-values>" >&2
636695
exit 1
637696
;;
638697
esac

.github/scripts/tests/helm-upgrade-helper.bats

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,3 +1265,71 @@ EOF
12651265
# Should trim whitespace
12661266
[[ "$output" == *"values.yaml"* ]]
12671267
}
1268+
1269+
# === OBS Branch Comparison Tests ===
1270+
1271+
@test "compare_obs_branches: returns 0 when files are identical" {
1272+
stable_values="$TEST_TMP/stable-values.yaml"
1273+
main_values="$TEST_TMP/main-values.yaml"
1274+
1275+
cat > "$stable_values" << 'EOF'
1276+
trento-web:
1277+
image:
1278+
repository: registry.suse.com/trento/trento-web
1279+
trento-wanda:
1280+
checks:
1281+
image:
1282+
repository: registry.suse.com/trento/trento-checks
1283+
EOF
1284+
1285+
cp "$stable_values" "$main_values"
1286+
1287+
run compare_obs_branches "$stable_values" "$main_values"
1288+
[ "$status" -eq 0 ]
1289+
[[ "$output" == *"No differences"* ]]
1290+
}
1291+
1292+
@test "compare_obs_branches: returns 1 when files differ" {
1293+
stable_values="$TEST_TMP/stable-values.yaml"
1294+
main_values="$TEST_TMP/main-values.yaml"
1295+
1296+
cat > "$stable_values" << 'EOF'
1297+
trento-wanda:
1298+
checks:
1299+
image:
1300+
repository: registry.suse.com/trento/checks
1301+
EOF
1302+
1303+
cat > "$main_values" << 'EOF'
1304+
trento-wanda:
1305+
checks:
1306+
image:
1307+
repository: registry.suse.com/trento/trento-checks
1308+
EOF
1309+
1310+
run compare_obs_branches "$stable_values" "$main_values"
1311+
[ "$status" -eq 1 ]
1312+
[[ "$output" == *"Differences found"* ]]
1313+
[[ "$output" == *"trento/checks"* ]]
1314+
[[ "$output" == *"trento/trento-checks"* ]]
1315+
}
1316+
1317+
@test "compare_obs_branches: returns error when stable file missing" {
1318+
main_values="$TEST_TMP/main-values.yaml"
1319+
echo "test" > "$main_values"
1320+
1321+
run compare_obs_branches "/nonexistent/file" "$main_values"
1322+
[ "$status" -eq 2 ]
1323+
[[ "$output" == *"ERROR"* ]]
1324+
[[ "$output" == *"Stable values file not found"* ]]
1325+
}
1326+
1327+
@test "compare_obs_branches: returns error when main file missing" {
1328+
stable_values="$TEST_TMP/stable-values.yaml"
1329+
echo "test" > "$stable_values"
1330+
1331+
run compare_obs_branches "$stable_values" "/nonexistent/file"
1332+
[ "$status" -eq 2 ]
1333+
[[ "$output" == *"ERROR"* ]]
1334+
[[ "$output" == *"Main values file not found"* ]]
1335+
}

.github/workflows/helm-upgrade.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ jobs:
114114
115115
echo "OBS artifacts processed successfully"
116116
117+
- name: Compare OBS stable vs main branches
118+
if: matrix.source == env.SOURCE_OBS_ARTIFACTS
119+
run: |
120+
obs_stable_dir="$(mktemp -d)"
121+
trap 'rm -rf "$obs_stable_dir"' EXIT
122+
123+
echo "Cloning OBS stable branch for comparison..."
124+
git clone --branch stable --depth 1 \
125+
https://src.opensuse.org/SAP-trento/trento-server-helm.git "$obs_stable_dir"
126+
127+
# Run comparison and capture exit code
128+
rc=0
129+
bash .github/scripts/helm-upgrade-helper.sh compare-obs-branches \
130+
"$obs_stable_dir/values.yaml" \
131+
obs-artifacts/chart/values.yaml || rc=$?
132+
133+
if [ "$rc" -eq 1 ]; then
134+
echo "::notice title=OBS Branch Drift Detected::Differences found between OBS stable and main branches. The stable branch may need to be updated with changes from main. See the comparison output above for details."
135+
elif [ "$rc" -ne 0 ]; then
136+
exit "$rc"
137+
fi
138+
117139
- name: Prepare OBS upstream chart for installation
118140
if: matrix.source == env.SOURCE_OBS_ARTIFACTS
119141
run: |

0 commit comments

Comments
 (0)