review: code simplification and cleanup
This commit is contained in:
@@ -20,15 +20,25 @@ if [[ -n "${FRAG_FILE:-}" && -f "${FRAG_FILE}" ]]; then
|
|||||||
checksum="$(sha256sum "$FRAG_FILE" | cut -d' ' -f1)"
|
checksum="$(sha256sum "$FRAG_FILE" | cut -d' ' -f1)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
json_escape() {
|
||||||
|
local s="$1"
|
||||||
|
s="${s//\\/\\\\}"
|
||||||
|
s="${s//\"/\\\"}"
|
||||||
|
s="${s//$'\n'/\\n}"
|
||||||
|
s="${s//$'\r'/\\r}"
|
||||||
|
s="${s//$'\t'/\\t}"
|
||||||
|
printf '%s' "$s"
|
||||||
|
}
|
||||||
|
|
||||||
cat > "$out" <<JSON
|
cat > "$out" <<JSON
|
||||||
{
|
{
|
||||||
"repo": "$FRAG_REPO",
|
"repo": "$(json_escape "$FRAG_REPO")",
|
||||||
"sha": "$FRAG_SHA",
|
"sha": "$(json_escape "$FRAG_SHA")",
|
||||||
"artifact": "$FRAG_ARTIFACT",
|
"artifact": "$(json_escape "$FRAG_ARTIFACT")",
|
||||||
"digest": "${FRAG_DIGEST:-}",
|
"digest": "$(json_escape "${FRAG_DIGEST:-}")",
|
||||||
"sha256": "$checksum",
|
"sha256": "$checksum",
|
||||||
"publish_url": "${FRAG_URL:-}",
|
"publish_url": "$(json_escape "${FRAG_URL:-}")",
|
||||||
"run_id": "${FRAG_RUN_ID:-}"
|
"run_id": "$(json_escape "${FRAG_RUN_ID:-}")"
|
||||||
}
|
}
|
||||||
JSON
|
JSON
|
||||||
echo "emit-release-fragment: wrote $out"
|
echo "emit-release-fragment: wrote $out"
|
||||||
|
|||||||
Executable
+20
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
tmp="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
|
|
||||||
|
cd "$repo_root"
|
||||||
|
FRAG_REPO='sow-tools' \
|
||||||
|
FRAG_SHA='abc123' \
|
||||||
|
FRAG_ARTIFACT='registry.example/sow/sow-tools:"quoted"' \
|
||||||
|
FRAG_URL=$'https://example.invalid/releases\nnext' \
|
||||||
|
FRAG_RUN_ID='run-1' \
|
||||||
|
FRAG_OUT="$tmp/fragment.json" \
|
||||||
|
./scripts/emit-release-fragment.sh
|
||||||
|
|
||||||
|
jq -e '.repo == "sow-tools" and .artifact == "registry.example/sow/sow-tools:\"quoted\"" and (.publish_url | contains("next"))' \
|
||||||
|
"$tmp/fragment.json" >/dev/null
|
||||||
|
|
||||||
|
echo "release-fragment-contract: JSON escapes env values"
|
||||||
Reference in New Issue
Block a user