Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions definitions/http/data_type/array/http_header_map.proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
}
}
],
"genericKeys": [],
"version": null
"genericKeys": []
}
3 changes: 1 addition & 2 deletions definitions/http/flow_type/http.proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
}
48 changes: 48 additions & 0 deletions script/inject-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Usage: ./inject-version.sh <version> [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 <version> [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"