50 lines
2.4 KiB
Bash
Executable File
50 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Read and validate .dealsage/app.json, then export what later steps need:
|
|
# APP_ID the custom app this repo publishes
|
|
# MANIFEST_JSON the whole manifest, compacted (recorded with the version)
|
|
# CHECKS_JSON the checks array with defaults applied
|
|
# Validation is deliberately jq-only (no npm dependency) so a broken manifest
|
|
# fails fast, before install. The schema of record is ../manifest.schema.json.
|
|
set -euo pipefail
|
|
. "$(dirname "$0")/lib.sh"
|
|
|
|
MANIFEST_PATH="${MANIFEST_PATH:-.dealsage/app.json}"
|
|
[ -f "$MANIFEST_PATH" ] || die "Manifest not found at $MANIFEST_PATH"
|
|
jq -e . "$MANIFEST_PATH" >/dev/null 2>&1 || die "$MANIFEST_PATH is not valid JSON"
|
|
|
|
app_id="$(jq -r '.appId // empty' "$MANIFEST_PATH")"
|
|
[[ "$app_id" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]] \
|
|
|| die "$MANIFEST_PATH: appId is missing or not a UUID (got '${app_id:-<empty>}'). Provisioning stamps it; do not edit by hand."
|
|
|
|
# Normalise checks: fill defaults, reject malformed entries with a clear message.
|
|
checks="$(jq -c '
|
|
def bad(msg): error("checks: " + msg);
|
|
(.checks // [])
|
|
| if type != "array" then bad("must be an array") else . end
|
|
| map(
|
|
if type != "object" then bad("each check must be an object") else . end
|
|
| if (.id|type) != "string" or ((.id|test("^[a-z][a-z0-9-]{0,39}$"))|not)
|
|
then bad("id must match ^[a-z][a-z0-9-]{0,39}$ (got " + (.id|tostring) + ")") else . end
|
|
| if ((.run|type) == "string") == ((.uses|type) == "string")
|
|
then bad("check " + .id + " needs exactly one of run or uses") else . end
|
|
| if (.uses? // "") != "" and ((.uses|IN("conventions"))|not)
|
|
then bad("check " + .id + " uses an unknown platform check " + .uses) else . end
|
|
| {
|
|
id: .id,
|
|
name: (.name // .id),
|
|
run: (.run // null),
|
|
uses: (.uses // null),
|
|
required: (if .required == null then true else .required end),
|
|
timeoutMinutes: (.timeoutMinutes // 15)
|
|
}
|
|
)
|
|
| if (map(.id) | unique | length) != length then bad("ids must be unique") else . end
|
|
' "$MANIFEST_PATH")" || exit 1
|
|
|
|
manifest="$(jq -c . "$MANIFEST_PATH")"
|
|
persist_env APP_ID "$app_id"
|
|
persist_env MANIFEST_JSON "$manifest"
|
|
persist_env CHECKS_JSON "$checks"
|
|
log "Manifest: app $app_id, $(jq 'length' <<<"$checks") check(s)"
|
|
jq -r '.[] | " - \(.id) (\(if .required then "required" else "advisory" end)): \(.run // ("platform:" + .uses))"' <<<"$checks"
|