Skip to content

Commit 3b55871

Browse files
authored
Enhance version update workflow with input validation
Updated descriptions for workflow inputs and added checks for file existence before updating version files.
1 parent e732415 commit 3b55871

1 file changed

Lines changed: 52 additions & 18 deletions

File tree

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

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ 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)'
88
required: true
99
default: '1.9.7'
1010
target_soversion:
11-
description: 'next SOVERSION (e.g., 28) - leave blank to keep current.'
11+
description: 'Next SOVERSION (e.g., 28). Leave blank to keep current.'
1212
required: false
1313

1414
jobs:
@@ -28,23 +28,57 @@ jobs:
2828
SOVER="${{ github.event.inputs.target_soversion }}"
2929
echo "Bumping version to $VER"
3030
31-
# 1. CMakeLists.txt: Match only the project declaration
32-
# This prevents touching comments, policies, or SOVERSION
33-
sed -i "s/project(jsoncpp VERSION [0-9.]*/project(jsoncpp VERSION $VER/" CMakeLists.txt
34-
35-
# Only update SOVERSION if provided
36-
if [ -n "$SOVER" ]; then
37-
echo "Bumping SOVERSION to $SOVER"
38-
sed -i "s/set(PROJECT_SOVERSION [0-9]*/set(PROJECT_SOVERSION $SOVER/" CMakeLists.txt
31+
# 1. CMakeLists.txt
32+
if [ -f CMakeLists.txt ]; then
33+
echo "updating cmakelists.txt"
34+
sed -i "s/project(jsoncpp VERSION [0-9.]*/project(jsoncpp VERSION $VER/" CMakeLists.txt
35+
if [ -n "$SOVER" ]; then
36+
sed -i "s/set(PROJECT_SOVERSION [0-9]*/set(PROJECT_SOVERSION $SOVER/" CMakeLists.txt
37+
fi
3938
fi
4039
41-
# 2. meson.build: Match the project line specifically
42-
sed -i "s/project('jsoncpp', 'cpp', version : '[0-9.]*'/project('jsoncpp', 'cpp', version : '$VER'/" meson.build
40+
# 2. meson.build
41+
if [ -f meson.build ]; then
42+
echo "updating meson.build"
43+
sed -i "s/project('jsoncpp', 'cpp', version : '[0-9.]*'/project('jsoncpp', 'cpp', version : '$VER'/" meson.build
44+
fi
45+
46+
# 3. vcpkg.json
47+
if [ -f vcpkg.json ]; then
48+
echo "updating vcpkg.json"
49+
jq ".version = \"$VER\"" vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.tmp vcpkg.json
50+
else
51+
echo "vcpkg.json not found, skipping"
52+
fi
4353
44-
# 3. vcpkg.json: Using jq for syntax safety
45-
jq ".version = \"$VER\"" vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.tmp vcpkg.json
54+
# 4. include/json/version.h
55+
if [ -f include/json/version.h ]; then
56+
echo "updating version.h"
57+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VER"
58+
# Using '|' as delimiter to prevent shell escaping issues
59+
sed -i "s|#define JSONCPP_VERSION_STRING \"[^\"]*\"|#define JSONCPP_VERSION_STRING \"$VER\"|" include/json/version.h
60+
sed -i "s|#define JSONCPP_VERSION_MAJOR [0-9]*|#define JSONCPP_VERSION_MAJOR $MAJOR|" include/json/version.h
61+
sed -i "s|#define JSONCPP_VERSION_MINOR [0-9]*|#define JSONCPP_VERSION_MINOR $MINOR|" include/json/version.h
62+
sed -i "s|#define JSONCPP_VERSION_PATCH [0-9]*|#define JSONCPP_VERSION_PATCH $PATCH|" include/json/version.h
63+
fi
64+
65+
- name: sanity check (cmake configure)
66+
run: |
67+
if [ -f CMakeLists.txt ]; then
68+
mkdir build_check
69+
cd build_check
70+
cmake .. -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF
71+
fi
4672
47-
# 4. include/json/version.h: Match specific #define macros
48-
IFS='.' read -r MAJOR MINOR PATCH <<< "$VER"
49-
sed -i "s/#define JSONCPP_VERSION_STRING \"[^\"]*\"/#define JSONCPP_VERSION_STRING \"$VER\"/" include/json/version.h
50-
sed -i "s/#define JSONCPP_VERSION_MAJOR [0-9]*/
73+
- name: create pull request
74+
uses: peter-evans/create-pull-request@v7
75+
with:
76+
token: ${{ secrets.GITHUB_TOKEN }}
77+
commit-message: "chore: bump version to ${{ github.event.inputs.target_version }}"
78+
branch: "bump-to-${{ github.event.inputs.target_version }}"
79+
title: "chore: bump version to ${{ github.event.inputs.target_version }}"
80+
body: |
81+
automated version bump.
82+
- new version: `${{ github.event.inputs.target_version }}`
83+
- new soversion: `${{ github.event.inputs.target_soversion || 'no change' }}`
84+
labels: "maintenance"

0 commit comments

Comments
 (0)