Debian Codegraph @

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

raw
1 name: "update project version"
2
3 on:
4 workflow_dispatch:
5 inputs:
6 target_version:
7 description: 'next version (e.g., 1.9.7 or 1.9.7.12)'
8 required: true
9 default: '1.9.7'
10 target_soversion:
11 description: 'next soversion (e.g., 28). leave blank to keep current.'
12 required: false
13
14 jobs:
15 bump-and-verify:
16 runs-on: ubuntu-latest
17 permissions:
18 contents: write
19 pull-requests: write
20 steps:
21 - name: checkout code
22 uses: actions/checkout@v4
23
24 - name: update project files
25 run: |
26 VER="${{ github.event.inputs.target_version }}"
27 SOVER="${{ github.event.inputs.target_soversion }}"
28 echo "bumping to $VER"
29
30 # 1. cmakelists.txt
31 if [ -f CMakeLists.txt ]; then
32 sed -i "/project.*jsoncpp/,/)/ s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt
33 if [ -n "$SOVER" ]; then
34 sed -i "s/set(PROJECT_SOVERSION [0-9]*/set(PROJECT_SOVERSION $SOVER/" CMakeLists.txt
35 fi
36 fi
37
38 # 2. meson.build
39 if [ -f meson.build ]; then
40 # targeting the version line directly
41 sed -i "s/version[[:space:]]*:[[:space:]]*['\"][0-9.]*['\"]/version : '$VER'/" meson.build
42 if [ -n "$SOVER" ]; then
43 sed -i "s/soversion[[:space:]]*:[[:space:]]*['\"][0-9]*['\"]/soversion : '$SOVER'/" meson.build
44 fi
45 fi
46
47 # 3. module.bazel
48 if [ -f MODULE.bazel ]; then
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
51 fi
52
53 # 4. vcpkg.json
54 if [ -f vcpkg.json ]; then
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"