Skip to content

Commit 903a6e8

Browse files
authored
Merge pull request #219 from nginx/areste-integration-test-update
Add manifest validation to integration test
2 parents 787314a + 91a568a commit 903a6e8

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

.github/scripts/verify-manifest.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Exit codes:
5+
# 0 - success
6+
# 3 - missing dependency (jq)
7+
# 4 - manifest.json not found
8+
# 5 - manifest.json exists but is not a regular file
9+
# 6 - manifest.json is not valid JSON
10+
# 7 - missing required JSON keys
11+
# 8 - missing files in the supportpkg
12+
# 9 - missing files in the manifest
13+
14+
if [[ ${#} -ne 1 ]]; then
15+
usage
16+
fi
17+
18+
dir="$1"
19+
manifest="$dir/manifest.json"
20+
21+
if ! command -v jq >/dev/null 2>&1; then
22+
echo "ERROR: jq is required but not found in PATH" >&2
23+
exit 3
24+
fi
25+
26+
if [[ ! -e "$manifest" ]]; then
27+
echo "ERROR: manifest.json not found in directory: $dir" >&2
28+
exit 4
29+
fi
30+
31+
if [[ ! -f "$manifest" ]]; then
32+
echo "ERROR: $manifest exists but is not a regular file" >&2
33+
exit 5
34+
fi
35+
36+
# Validate JSON
37+
if ! jq empty "$manifest" >/dev/null 2>&1; then
38+
echo "ERROR: $manifest is not valid JSON" >&2
39+
# show where jq fails (best-effort)
40+
jq . "$manifest" 2>/dev/null || true
41+
exit 6
42+
fi
43+
44+
required=(
45+
"version"
46+
"ts.start"
47+
"ts.stop"
48+
"package_type"
49+
"root_dir"
50+
"commands"
51+
"platform_info.platform_type"
52+
"platform_info.hostname"
53+
"platform_info.serial_number"
54+
"product_info.product"
55+
"product_info.version"
56+
"product_info.build"
57+
)
58+
59+
missing=()
60+
for p in "${required[@]}"; do
61+
# Test presence: use getpath(split(".")) and check that it exists and is not null
62+
if ! jq -e --arg p "$p" 'getpath($p | split(".")) != null' "$manifest" >/dev/null 2>&1; then
63+
missing+=("$p")
64+
fi
65+
done
66+
67+
if [[ ${#missing[@]} -ne 0 ]]; then
68+
echo "ERROR: manifest.json is missing required keys:" >&2
69+
for m in "${missing[@]}"; do
70+
echo " - $m" >&2
71+
done
72+
exit 7
73+
fi
74+
75+
# Check that there is a 1:1 correspondence between manifest and tarball content
76+
77+
find "${dir}" -type f -mindepth 1 | cut -c "$(( ${#dir} + 1 ))"- > find-output.txt
78+
jq -r '.commands[].output' "${dir}"/manifest.json > manifest-output.txt
79+
printf "/manifest.json\n/supportpkg.log" >> manifest-output.txt
80+
if grep -vxFf find-output.txt manifest-output.txt >/dev/null; then
81+
echo "ERROR: Manifest contains files not present in the supportpkg:"
82+
grep -vxFf find-output.txt manifest-output.txt
83+
exit 8
84+
fi
85+
if grep -vxFf manifest-output.txt find-output.txt >/dev/null; then
86+
echo "ERROR: Supportpkg contains files not present in the manifest:"
87+
grep -vxFf manifest-output.txt find-output.txt
88+
exit 9
89+
fi
90+
91+
# All good if we reached this point
92+
93+
echo "OK: $manifest is valid and consistent with the supportpkg contents"
94+
exit 0

.github/workflows/integration-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ jobs:
106106
# Verify expected files exist
107107
bash .github/scripts/verify-contents.sh extracted_test
108108
109+
- name: Validate manifest file
110+
run: |
111+
bash .github/scripts/verify-manifest.sh extracted_test
112+
109113
- name: Upload test artifacts
110114
if: always()
111115
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)