Skip to content

Commit f3dd2cb

Browse files
authored
Refactor version update script for clarity and efficiency
1 parent ec2387b commit f3dd2cb

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

.github/workflows/update-project-version.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ jobs:
2525
run: |
2626
VER="${{ github.event.inputs.target_version }}"
2727
SOVER="${{ github.event.inputs.target_soversion }}"
28-
echo "bumping version to $VER"
28+
echo "bumping to $VER"
2929
3030
# 1. cmakelists.txt
3131
if [ -f CMakeLists.txt ]; then
32-
echo "updating cmakelists.txt"
3332
sed -i "/project.*jsoncpp/,/)/ s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt
3433
if [ -n "$SOVER" ]; then
3534
sed -i "s/set(PROJECT_SOVERSION [0-9]*/set(PROJECT_SOVERSION $SOVER/" CMakeLists.txt
@@ -38,8 +37,7 @@ jobs:
3837
3938
# 2. meson.build
4039
if [ -f meson.build ]; then
41-
echo "updating meson.build"
42-
# match the version line directly
40+
# targeting the version line directly
4341
sed -i "s/version[[:space:]]*:[[:space:]]*['\"][0-9.]*['\"]/version : '$VER'/" meson.build
4442
if [ -n "$SOVER" ]; then
4543
sed -i "s/soversion[[:space:]]*:[[:space:]]*['\"][0-9]*['\"]/soversion : '$SOVER'/" meson.build
@@ -48,20 +46,17 @@ jobs:
4846
4947
# 3. module.bazel
5048
if [ -f MODULE.bazel ]; then
51-
echo "updating module.bazel"
52-
# surgical update only for the module() version
53-
sed -i "/module(/,/)/ s/version[[:space:]]*=[[:space:]]*['\"][0-9.]*['\"]/version = \"$VER\"/" MODULE.bazel
49+
# match only the first 'version' occurrence in the file (the module version)
50+
sed -i "0,/version[[:space:]]*=[[:space:]]*['\"][0-9.]*['\"]/s//version = \"$VER\"/" MODULE.bazel
5451
fi
5552
5653
# 4. vcpkg.json
5754
if [ -f vcpkg.json ]; then
58-
echo "updating vcpkg.json"
59-
jq --arg ver "$VER" '.version = $ver' vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.tmp vcpkg.json
55+
jq --arg ver "$VER" '.version = $ver' vcpkg.json > tmp.json && mv tmp.json vcpkg.json
6056
fi
6157
6258
# 5. include/json/version.h
6359
if [ -f include/json/version.h ]; then
64-
echo "updating version.h"
6560
MAJOR=$(echo "$VER" | cut -d. -f1)
6661
MINOR=$(echo "$VER" | cut -d. -f2)
6762
PATCH=$(echo "$VER" | cut -d. -f3)
@@ -84,33 +79,32 @@ jobs:
8479
run: |
8580
FILE="include/json/version.h"
8681
if [ -f "$FILE" ]; then
87-
# stricter extraction to avoid catching comments or artifacts
82+
# extract clean values by stripping everything except digits and dots
8883
V_STR=$(grep "JSONCPP_VERSION_STRING" "$FILE" | head -n 1 | cut -d '"' -f 2)
8984
V_MAJ=$(grep "JSONCPP_VERSION_MAJOR" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
9085
V_MIN=$(grep "JSONCPP_VERSION_MINOR" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
9186
V_PAT=$(grep "JSONCPP_VERSION_PATCH" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
9287
V_QUA=$(grep "JSONCPP_VERSION_QUALIFIER" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
9388
94-
# build table safely
95-
echo "report<<EOF" >> $GITHUB_OUTPUT
89+
# create a unique delimiter for the multi-line output
90+
DELIM=$(dd if=/dev/urandom bs=15 count=1 2>/dev/null | base64)
91+
echo "report<<$DELIM" >> $GITHUB_OUTPUT
9692
echo "| Macro | Value |" >> $GITHUB_OUTPUT
9793
echo "| :--- | :--- |" >> $GITHUB_OUTPUT
9894
echo "| STRING | \`$V_STR\` |" >> $GITHUB_OUTPUT
9995
echo "| MAJOR | \`$V_MAJ\` |" >> $GITHUB_OUTPUT
10096
echo "| MINOR | \`$V_MIN\` |" >> $GITHUB_OUTPUT
10197
echo "| PATCH | \`$V_PAT\` |" >> $GITHUB_OUTPUT
10298
echo "| QUALIFIER | \`${V_QUA:-empty}\` |" >> $GITHUB_OUTPUT
103-
echo "EOF" >> $GITHUB_OUTPUT
99+
echo "$DELIM" >> $GITHUB_OUTPUT
104100
fi
105101
106102
- name: sanity check (cmake configure)
107103
run: |
108104
if [ -f CMakeLists.txt ]; then
109-
mkdir build_check
110-
cd build_check
105+
mkdir build_check && cd build_check
111106
cmake .. -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF
112-
cd ..
113-
rm -rf build_check
107+
cd .. && rm -rf build_check
114108
fi
115109
116110
- name: create pull request

0 commit comments

Comments
 (0)