Skip to content

Commit 4615c77

Browse files
ci: introduce osguard imageconfig verifier (microsoft#14515)
Since we are now generating osguard configurations from templates, there is a possibility the template changes get out-of-sync with what is committed. Add github action check to verify osguard config generation from templates always match the config present in the default location, otherwise fail to block PR. Signed-off-by: Chris Co <[email protected]>
1 parent 1906e17 commit 4615c77

File tree

2 files changed

+90
-6
lines changed

2 files changed

+90
-6
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Verify osguard imageconfigs are up-to-date
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
verify-osguard-imageconfigs:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: '3.x'
18+
19+
- name: Install Python dependencies for merge_yaml
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install pyyaml
23+
24+
- name: Run osguard imageconfigs test
25+
working-directory: toolkit/scripts
26+
shell: bash
27+
run: |
28+
set -euo pipefail
29+
./generate-osguard-imageconfigs.sh test

toolkit/scripts/generate-osguard-imageconfigs.sh

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
# Generates osguard image configurations by merging base + delta YAML templates.
66
# Usage:
7-
# ./generate_osguard_configs.sh
7+
# ./generate-osguard-imageconfigs.sh
8+
# ./generate-osguard-imageconfigs.sh test
9+
# test: generate into a temporary directory and compare with the default
10+
# committed file, failing if they differ (ignores the '# Sources:' header).
811
#
912
# Optional env:
1013
# PYTHON - Python executable to use (default: python3)
@@ -16,6 +19,10 @@ set -euo pipefail
1619

1720
PYTHON_BIN=${PYTHON:-python3}
1821

22+
# Default output directory (relative to this script's CWD)
23+
OUT_DIR_DEFAULT="../imageconfigs"
24+
25+
1926
# Ensure merge_yaml.py is available in the current directory
2027
if [[ ! -f ./merge_yaml.py ]]; then
2128
echo "Error: merge_yaml.py not found in the current directory." >&2
@@ -26,10 +33,58 @@ fi
2633
BASE_TPL="../imageconfigs/templates/osguard-base.yaml"
2734
DELTA_TPL="../imageconfigs/templates/osguard-no-ci-delta.yaml"
2835

29-
OUT_STD="../imageconfigs/osguard-amd64.yaml"
36+
run_generate() {
37+
local out_dir="$1"
38+
mkdir -p "$out_dir"
39+
local out_std="$out_dir/osguard-amd64.yaml"
40+
echo "Generating osguard configs..."
41+
echo "Output directory: $out_dir"
42+
"$PYTHON_BIN" ./merge_yaml.py "$BASE_TPL" "$DELTA_TPL" -o "$out_std"
43+
echo "Done. Wrote:"
44+
echo " $out_std"
45+
}
46+
47+
run_test() {
48+
echo "Running test: generate into temp dir and compare with default (ignoring '# Sources:' header)"
49+
local tmp_out_dir
50+
tmp_out_dir="$(mktemp -d)"
51+
run_generate "$tmp_out_dir"
52+
53+
local generated_file default_file
54+
generated_file="$tmp_out_dir/osguard-amd64.yaml"
55+
default_file="../imageconfigs/osguard-amd64.yaml"
56+
57+
echo "Comparing:"
58+
echo " Generated: $generated_file"
59+
echo " Default: $default_file"
60+
61+
# Filter out the variable header line that lists source paths
62+
local filt_gen filt_def
63+
filt_gen="$(mktemp)"
64+
filt_def="$(mktemp)"
65+
grep -v '^# Sources:' "$generated_file" > "$filt_gen"
66+
grep -v '^# Sources:' "$default_file" > "$filt_def"
67+
68+
if ! diff -u "$filt_gen" "$filt_def"; then
69+
echo "Error: Generated osguard imageconfig differs from the committed default." >&2
70+
exit 1
71+
fi
72+
echo "Success: Generated osguard imageconfig matches the committed default."
73+
}
3074

31-
echo "Generating osguard configs..."
32-
"$PYTHON_BIN" ./merge_yaml.py "$BASE_TPL" "$DELTA_TPL" -o "$OUT_STD"
75+
main() {
76+
case "${1:-}" in
77+
"" )
78+
run_generate "$OUT_DIR_DEFAULT"
79+
;;
80+
test|--test )
81+
run_test
82+
;;
83+
* )
84+
echo "Usage: $0 [test]" >&2
85+
exit 2
86+
;;
87+
esac
88+
}
3389

34-
echo "Done. Wrote:"
35-
echo " $OUT_STD"
90+
main "$@"

0 commit comments

Comments
 (0)