Skip to content

Commit 8c16fc0

Browse files
authored
Merge branch 'master' into Add-project-status-to-README-to-set-expectations
2 parents e62f3f4 + b52dce4 commit 8c16fc0

1 file changed

Lines changed: 62 additions & 24 deletions

File tree

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

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,94 @@ on:
44
workflow_dispatch:
55
inputs:
66
target_version:
7-
description: 'Next Version (e.g., 1.9.7)'
7+
description: 'next version (e.g., 1.9.7 or 1.9.7.12)'
88
required: true
99
default: '1.9.7'
10+
target_soversion:
11+
description: 'next soversion (e.g., 28). leave blank to keep current.'
12+
required: false
1013

1114
jobs:
12-
create-bump-pr:
15+
bump-and-verify:
1316
runs-on: ubuntu-latest
1417
permissions:
1518
contents: write
1619
pull-requests: write
1720
steps:
18-
- name: Checkout code
21+
- name: checkout code
1922
uses: actions/checkout@v4
2023

21-
- name: Update Project Files
24+
- name: update project files
2225
id: update_files
2326
run: |
2427
VER="${{ github.event.inputs.target_version }}"
25-
echo "Updating files to $VER"
28+
SOVER="${{ github.event.inputs.target_soversion }}"
29+
echo "bumping version to $VER"
2630
2731
# 1. CMakeLists.txt
28-
sed -i "s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt
32+
if [ -f CMakeLists.txt ]; then
33+
echo "updating cmakelists.txt"
34+
# match VERSION only within the project block
35+
sed -i "/project[[:space:]]*([[:space:]]*jsoncpp/,/)/ s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt
36+
if [ -n "$SOVER" ]; then
37+
sed -i "s/set(PROJECT_SOVERSION [0-9]*/set(PROJECT_SOVERSION $SOVER/" CMakeLists.txt
38+
fi
39+
fi
2940
3041
# 2. meson.build
31-
sed -i "s/version : '[0-9.]*'/version : '$VER'/" meson.build
42+
if [ -f meson.build ]; then
43+
echo "updating meson.build"
44+
# match version : 'x.y.z' with flexible quotes and spacing
45+
sed -i "s/version[[:space:]]*:[[:space:]]*['\"][0-9.]*['\"]/version : '$VER'/" meson.build
46+
if [ -n "$SOVER" ]; then
47+
# matches soversion : '26'
48+
sed -i "s/soversion[[:space:]]*:[[:space:]]*['\"][0-9]*['\"]/soversion : '$SOVER'/" meson.build
49+
fi
50+
fi
3251
33-
# 3. vcpkg.json (Using jq for safety)
34-
jq ".version = \"$VER\"" vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.tmp vcpkg.json
52+
# 3. vcpkg.json
53+
if [ -f vcpkg.json ]; then
54+
echo "updating vcpkg.json"
55+
jq ".version = \"$VER\"" vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.tmp vcpkg.json
56+
fi
3557
3658
# 4. include/json/version.h
37-
# Parse X.Y.Z into separate variables
38-
IFS='.' read -r MAJOR MINOR PATCH <<< "$VER"
39-
sed -i "s/# define JSONCPP_VERSION_STRING \"[^\"]*\"/# define JSONCPP_VERSION_STRING \"$VER\"/" include/json/version.h
40-
sed -i "s/# define JSONCPP_VERSION_MAJOR [0-9]*/# define JSONCPP_VERSION_MAJOR $MAJOR/" include/json/version.h
41-
sed -i "s/# define JSONCPP_VERSION_MINOR [0-9]*/# define JSONCPP_VERSION_MINOR $MINOR/" include/json/version.h
42-
sed -i "s/# define JSONCPP_VERSION_PATCH [0-9]*/# define JSONCPP_VERSION_PATCH $PATCH/" include/json/version.h
43-
44-
- name: Create Pull Request
59+
if [ -f include/json/version.h ]; then
60+
echo "updating version.h"
61+
# 1.9.7.12 -> MAJOR=1, MINOR=9, PATCH=7, QUALIFIER=12
62+
IFS='.' read -r MAJOR MINOR PATCH QUALIFIER <<< "$VER"
63+
64+
sed -i "s|#define JSONCPP_VERSION_STRING \"[^\"]*\"|#define JSONCPP_VERSION_STRING \"$VER\"|" include/json/version.h
65+
sed -i "s|#define JSONCPP_VERSION_MAJOR [0-9]*|#define JSONCPP_VERSION_MAJOR $MAJOR|" include/json/version.h
66+
sed -i "s|#define JSONCPP_VERSION_MINOR [0-9]*|#define JSONCPP_VERSION_MINOR $MINOR|" include/json/version.h
67+
sed -i "s|#define JSONCPP_VERSION_PATCH [0-9]*|#define JSONCPP_VERSION_PATCH $PATCH|" include/json/version.h
68+
69+
if [ -n "$QUALIFIER" ]; then
70+
sed -i "s|#define JSONCPP_VERSION_QUALIFIER.*|#define JSONCPP_VERSION_QUALIFIER $QUALIFIER|" include/json/version.h
71+
else
72+
sed -i "s|#define JSONCPP_VERSION_QUALIFIER.*|#define JSONCPP_VERSION_QUALIFIER|" include/json/version.h
73+
fi
74+
fi
75+
76+
- name: sanity check (cmake configure)
77+
run: |
78+
if [ -f CMakeLists.txt ]; then
79+
mkdir build_check
80+
cd build_check
81+
cmake .. -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF
82+
cd ..
83+
rm -rf build_check
84+
fi
85+
86+
- name: create pull request
4587
uses: peter-evans/create-pull-request@v7
4688
with:
4789
token: ${{ secrets.GITHUB_TOKEN }}
4890
commit-message: "chore: bump version to ${{ github.event.inputs.target_version }}"
4991
branch: "bump-to-${{ github.event.inputs.target_version }}"
5092
title: "chore: bump version to ${{ github.event.inputs.target_version }}"
5193
body: |
52-
Manual version bump to `${{ github.event.inputs.target_version }}` to start the next development cycle.
53-
54-
**Files updated:**
55-
- `CMakeLists.txt`
56-
- `meson.build`
57-
- `vcpkg.json`
58-
- `include/json/version.h`
94+
automated version bump.
95+
- new version: `${{ github.event.inputs.target_version }}`
96+
- new soversion: `${{ github.event.inputs.target_soversion || 'no change' }}`
5997
labels: "maintenance"

0 commit comments

Comments
 (0)