diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f09139c..363c750 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,6 +53,15 @@ jobs: - name: Checkout Code uses: actions/checkout@v5 + - name: Set script permissions + run: chmod +x ./scripts/inject-version.sh + + - name: Inject version + run: | + VERSION="${{ github.ref_name }}" + VERSION="${VERSION#*-}" # removes everything up to the first dash + ./scripts/inject-version.sh "$VERSION" + - name: Archive definitions folder run: | zip -r definitions.zip definitions diff --git a/definitions/http/data_type/array/http_header_map.proto.json b/definitions/http/data_type/array/http_header_map.proto.json index b490ba3..d533410 100644 --- a/definitions/http/data_type/array/http_header_map.proto.json +++ b/definitions/http/data_type/array/http_header_map.proto.json @@ -29,6 +29,5 @@ } } ], - "genericKeys": [], - "version": null + "genericKeys": [] } \ No newline at end of file diff --git a/definitions/http/flow_type/http.proto.json b/definitions/http/flow_type/http.proto.json index 23faf37..abdd3d3 100644 --- a/definitions/http/flow_type/http.proto.json +++ b/definitions/http/flow_type/http.proto.json @@ -76,6 +76,5 @@ "code": "en-US", "content": "A REST API is a web service that lets clients interact with data on a server using standard HTTP methods like GET, POST, PUT, and DELETE usually returning results in JSON format." } - ], - "version": null + ] } \ No newline at end of file diff --git a/script/inject-version.sh b/script/inject-version.sh new file mode 100644 index 0000000..46b9419 --- /dev/null +++ b/script/inject-version.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Usage: ./inject-version.sh [dir] +# Example: ./inject-version.sh 0.4.2 # defaults to ./definitions +# ./inject-version.sh 0.4.2 ./defs + +set -euo pipefail +IFS=$'\n\t' + +# ---- args & checks ---- +[ $# -ge 1 ] || { echo "Usage: $0 [dir]" >&2; exit 1; } +V="$1" +DIR="${2:-definitions}" + +command -v jq >/dev/null 2>&1 || { echo "jq is required" >&2; exit 1; } +[[ "$V" =~ ^[0-9]+(\.[0-9]+)*$ ]] || { echo "Invalid version: $V" >&2; exit 1; } +[ -d "$DIR" ] || { echo "Folder not found: $DIR" >&2; exit 1; } + +# ---- process ---- +updated=0 +skipped=0 +while IFS= read -r -d '' f; do + # Validate JSON first + if ! jq -e . "$f" >/dev/null 2>&1; then + echo "INVALID JSON (skipped): $f" >&2 + ((skipped++)) + continue + fi + + # Only modify if top-level is an object + if jq -e 'type=="object"' "$f" >/dev/null 2>&1; then + tmp="$(mktemp --tmpdir="$(dirname "$f")" .inject.XXXXXX)" + # Write to temp first; only replace on success + if jq --arg v "$V" '.version=$v' "$f" >"$tmp"; then + mv -f "$tmp" "$f" + echo "updated: $f" + ((updated++)) + else + echo "ERROR processing: $f" >&2 + rm -f "$tmp" + ((skipped++)) + fi + else + echo "skipped (non-object): $f" + ((skipped++)) + fi +done < <(find "$DIR" -type f -name '*.json' -print0) + +echo "Done. Updated: $updated Skipped: $skipped"