Skip to content

Commit 830d792

Browse files
Merge pull request #125 from code0-tech/75-add-version-tag
Definition Version-Tag
2 parents 70f162b + a473585 commit 830d792

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

.github/workflows/release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ jobs:
5353
- name: Checkout Code
5454
uses: actions/checkout@v5
5555

56+
- name: Set script permissions
57+
run: chmod +x ./scripts/inject-version.sh
58+
59+
- name: Inject version
60+
run: |
61+
VERSION="${{ github.ref_name }}"
62+
VERSION="${VERSION#*-}" # removes everything up to the first dash
63+
./scripts/inject-version.sh "$VERSION"
64+
5665
- name: Archive definitions folder
5766
run: |
5867
zip -r definitions.zip definitions

definitions/http/data_type/array/http_header_map.proto.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@
2929
}
3030
}
3131
],
32-
"genericKeys": [],
33-
"version": null
32+
"genericKeys": []
3433
}

definitions/http/flow_type/http.proto.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,5 @@
7676
"code": "en-US",
7777
"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."
7878
}
79-
],
80-
"version": null
79+
]
8180
}

script/inject-version.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Usage: ./inject-version.sh <version> [dir]
3+
# Example: ./inject-version.sh 0.4.2 # defaults to ./definitions
4+
# ./inject-version.sh 0.4.2 ./defs
5+
6+
set -euo pipefail
7+
IFS=$'\n\t'
8+
9+
# ---- args & checks ----
10+
[ $# -ge 1 ] || { echo "Usage: $0 <version> [dir]" >&2; exit 1; }
11+
V="$1"
12+
DIR="${2:-definitions}"
13+
14+
command -v jq >/dev/null 2>&1 || { echo "jq is required" >&2; exit 1; }
15+
[[ "$V" =~ ^[0-9]+(\.[0-9]+)*$ ]] || { echo "Invalid version: $V" >&2; exit 1; }
16+
[ -d "$DIR" ] || { echo "Folder not found: $DIR" >&2; exit 1; }
17+
18+
# ---- process ----
19+
updated=0
20+
skipped=0
21+
while IFS= read -r -d '' f; do
22+
# Validate JSON first
23+
if ! jq -e . "$f" >/dev/null 2>&1; then
24+
echo "INVALID JSON (skipped): $f" >&2
25+
((skipped++))
26+
continue
27+
fi
28+
29+
# Only modify if top-level is an object
30+
if jq -e 'type=="object"' "$f" >/dev/null 2>&1; then
31+
tmp="$(mktemp --tmpdir="$(dirname "$f")" .inject.XXXXXX)"
32+
# Write to temp first; only replace on success
33+
if jq --arg v "$V" '.version=$v' "$f" >"$tmp"; then
34+
mv -f "$tmp" "$f"
35+
echo "updated: $f"
36+
((updated++))
37+
else
38+
echo "ERROR processing: $f" >&2
39+
rm -f "$tmp"
40+
((skipped++))
41+
fi
42+
else
43+
echo "skipped (non-object): $f"
44+
((skipped++))
45+
fi
46+
done < <(find "$DIR" -type f -name '*.json' -print0)
47+
48+
echo "Done. Updated: $updated Skipped: $skipped"

0 commit comments

Comments
 (0)