-
Notifications
You must be signed in to change notification settings - Fork 2
Add manifest validation to integration test #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2dab5f8
feat: add manifest validation to integration test
dareste f3b256c
Update .github/scripts/verify-manifest.sh
dareste a73b9c3
Update .github/scripts/verify-manifest.sh
dareste 91a568a
feat: check correspondence between files in supportpkg and manifest
dareste File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# Exit codes: | ||
# 0 - success | ||
# 3 - missing dependency (jq) | ||
# 4 - manifest.json not found | ||
# 5 - manifest.json exists but is not a regular file | ||
# 6 - manifest.json is not valid JSON | ||
# 7 - missing required JSON keys | ||
# 8 - missing files in the supportpkg | ||
# 9 - missing files in the manifest | ||
|
||
if [[ ${#} -ne 1 ]]; then | ||
usage | ||
fi | ||
|
||
dir="$1" | ||
manifest="$dir/manifest.json" | ||
|
||
if ! command -v jq >/dev/null 2>&1; then | ||
echo "ERROR: jq is required but not found in PATH" >&2 | ||
exit 3 | ||
fi | ||
|
||
if [[ ! -e "$manifest" ]]; then | ||
echo "ERROR: manifest.json not found in directory: $dir" >&2 | ||
exit 4 | ||
fi | ||
|
||
if [[ ! -f "$manifest" ]]; then | ||
echo "ERROR: $manifest exists but is not a regular file" >&2 | ||
exit 5 | ||
fi | ||
|
||
# Validate JSON | ||
if ! jq empty "$manifest" >/dev/null 2>&1; then | ||
echo "ERROR: $manifest is not valid JSON" >&2 | ||
# show where jq fails (best-effort) | ||
jq . "$manifest" 2>/dev/null || true | ||
exit 6 | ||
fi | ||
|
||
required=( | ||
"version" | ||
"ts.start" | ||
"ts.stop" | ||
"package_type" | ||
"root_dir" | ||
"commands" | ||
"platform_info.platform_type" | ||
"platform_info.hostname" | ||
"platform_info.serial_number" | ||
"product_info.product" | ||
"product_info.version" | ||
"product_info.build" | ||
) | ||
|
||
missing=() | ||
for p in "${required[@]}"; do | ||
# Test presence: use getpath(split(".")) and check that it exists and is not null | ||
if ! jq -e --arg p "$p" 'getpath($p | split(".")) != null' "$manifest" >/dev/null 2>&1; then | ||
missing+=("$p") | ||
fi | ||
done | ||
|
||
if [[ ${#missing[@]} -ne 0 ]]; then | ||
echo "ERROR: manifest.json is missing required keys:" >&2 | ||
for m in "${missing[@]}"; do | ||
echo " - $m" >&2 | ||
done | ||
exit 7 | ||
fi | ||
|
||
# Check that there is a 1:1 correspondence between manifest and tarball content | ||
|
||
find "${dir}" -type f -mindepth 1 | cut -c "$(( ${#dir} + 1 ))"- > find-output.txt | ||
jq -r '.commands[].output' "${dir}"/manifest.json > manifest-output.txt | ||
printf "/manifest.json\n/supportpkg.log" >> manifest-output.txt | ||
if grep -vxFf find-output.txt manifest-output.txt >/dev/null; then | ||
echo "ERROR: Manifest contains files not present in the supportpkg:" | ||
grep -vxFf find-output.txt manifest-output.txt | ||
exit 8 | ||
fi | ||
if grep -vxFf manifest-output.txt find-output.txt >/dev/null; then | ||
echo "ERROR: Supportpkg contains files not present in the manifest:" | ||
grep -vxFf manifest-output.txt find-output.txt | ||
exit 9 | ||
fi | ||
|
||
# All good if we reached this point | ||
|
||
echo "OK: $manifest is valid and consistent with the supportpkg contents" | ||
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.