@@ -22,39 +22,103 @@ jobs:
2222 uses : actions/checkout@v4
2323
2424 - name : update project files
25- id : update_files
2625 run : |
2726 VER="${{ github.event.inputs.target_version }}"
2827 SOVER="${{ github.event.inputs.target_soversion }}"
29- echo "bumping version to $VER"
28+ echo "bumping to $VER"
3029
31- # 1. CMakeLists .txt: Only update version inside the project() block
30+ # 1. cmakelists .txt
3231 if [ -f CMakeLists.txt ]; then
33- echo "updating cmakelists.txt"
34- sed -i "/project[[:space:]]*([[:space:]]*jsoncpp/,/)/ s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt
32+ sed -i "/project.*jsoncpp/,/)/ s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt
3533 if [ -n "$SOVER" ]; then
3634 sed -i "s/set(PROJECT_SOVERSION [0-9]*/set(PROJECT_SOVERSION $SOVER/" CMakeLists.txt
3735 fi
3836 fi
3937
40- # 2. meson.build: Only update version inside the project() block
38+ # 2. meson.build
4139 if [ -f meson.build ]; then
42- echo "updating meson.build"
43- sed -i "/project('jsoncpp'/,/)/ s/version[[:space:]]*:[[:space:]]*['\"][0-9.]*['\"]/version : '$VER'/" meson.build
40+ # targeting the version line directly
41+ sed -i "s/version[[:space:]]*:[[:space:]]*['\"][0-9.]*['\"]/version : '$VER'/" meson.build
4442 if [ -n "$SOVER" ]; then
45- # update soversion only within the library() or where defined
4643 sed -i "s/soversion[[:space:]]*:[[:space:]]*['\"][0-9]*['\"]/soversion : '$SOVER'/" meson.build
4744 fi
4845 fi
4946
50- # 3. MODULE .bazel: Only update version inside the module() block
47+ # 3. module .bazel
5148 if [ -f MODULE.bazel ]; then
52- echo "updating MODULE.bazel"
53- # match range from 'module(' to the first ')'
54- 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
5551 fi
5652
57- # 4. vcpkg.json: jq is inherently surgical
53+ # 4. vcpkg.json
5854 if [ -f vcpkg.json ]; then
59- echo "updating vcpkg.json"
60- jq ".version = \"$VER\"" vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.
55+ jq --arg ver "$VER" '.version = $ver' vcpkg.json > tmp.json && mv tmp.json vcpkg.json
56+ fi
57+
58+ # 5. include/json/version.h
59+ if [ -f include/json/version.h ]; then
60+ MAJOR=$(echo "$VER" | cut -d. -f1)
61+ MINOR=$(echo "$VER" | cut -d. -f2)
62+ PATCH=$(echo "$VER" | cut -d. -f3)
63+ QUALIFIER=$(echo "$VER" | cut -d. -f4 -s)
64+
65+ sed -i "s/#define JSONCPP_VERSION_STRING \".*\"/#define JSONCPP_VERSION_STRING \"$VER\"/" include/json/version.h
66+ sed -i "s/#define JSONCPP_VERSION_MAJOR [0-9]*/#define JSONCPP_VERSION_MAJOR $MAJOR/" include/json/version.h
67+ sed -i "s/#define JSONCPP_VERSION_MINOR [0-9]*/#define JSONCPP_VERSION_MINOR $MINOR/" include/json/version.h
68+ sed -i "s/#define JSONCPP_VERSION_PATCH [0-9]*/#define JSONCPP_VERSION_PATCH $PATCH/" include/json/version.h
69+
70+ if [ -n "$QUALIFIER" ]; then
71+ sed -i "s/#define JSONCPP_VERSION_QUALIFIER.*/#define JSONCPP_VERSION_QUALIFIER $QUALIFIER/" include/json/version.h
72+ else
73+ sed -i "s/#define JSONCPP_VERSION_QUALIFIER.*/#define JSONCPP_VERSION_QUALIFIER/" include/json/version.h
74+ fi
75+ fi
76+
77+ - name : verify version macros
78+ id : verify
79+ run : |
80+ FILE="include/json/version.h"
81+ if [ -f "$FILE" ]; then
82+ # extract clean values by stripping everything except digits and dots
83+ V_STR=$(grep "JSONCPP_VERSION_STRING" "$FILE" | head -n 1 | cut -d '"' -f 2)
84+ V_MAJ=$(grep "JSONCPP_VERSION_MAJOR" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
85+ V_MIN=$(grep "JSONCPP_VERSION_MINOR" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
86+ V_PAT=$(grep "JSONCPP_VERSION_PATCH" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
87+ V_QUA=$(grep "JSONCPP_VERSION_QUALIFIER" "$FILE" | head -n 1 | awk '{print $3}' | tr -cd '0-9')
88+
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
92+ echo "| Macro | Value |" >> $GITHUB_OUTPUT
93+ echo "| :--- | :--- |" >> $GITHUB_OUTPUT
94+ echo "| STRING | \`$V_STR\` |" >> $GITHUB_OUTPUT
95+ echo "| MAJOR | \`$V_MAJ\` |" >> $GITHUB_OUTPUT
96+ echo "| MINOR | \`$V_MIN\` |" >> $GITHUB_OUTPUT
97+ echo "| PATCH | \`$V_PAT\` |" >> $GITHUB_OUTPUT
98+ echo "| QUALIFIER | \`${V_QUA:-empty}\` |" >> $GITHUB_OUTPUT
99+ echo "$DELIM" >> $GITHUB_OUTPUT
100+ fi
101+
102+ - name : sanity check (cmake configure)
103+ run : |
104+ if [ -f CMakeLists.txt ]; then
105+ mkdir build_check && cd build_check
106+ cmake .. -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF
107+ cd .. && rm -rf build_check
108+ fi
109+
110+ - name : create pull request
111+ uses : peter-evans/create-pull-request@v7
112+ with :
113+ token : ${{ secrets.GITHUB_TOKEN }}
114+ commit-message : " chore: bump version to ${{ github.event.inputs.target_version }}"
115+ branch : " bump-to-${{ github.event.inputs.target_version }}"
116+ title : " chore: bump version to ${{ github.event.inputs.target_version }}"
117+ body : |
118+ automated version bump.
119+ - new version: `${{ github.event.inputs.target_version }}`
120+ - new soversion: `${{ github.event.inputs.target_soversion || 'no change' }}`
121+
122+ ### header verification
123+ ${{ steps.verify.outputs.report }}
124+ labels : " maintenance"
0 commit comments