|
| 1 | +name: "Bump Project Version" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version_base: |
| 7 | + description: 'Target Version (e.g., 1.9.7)' |
| 8 | + required: true |
| 9 | + default: '1.9.7' |
| 10 | + |
| 11 | +jobs: |
| 12 | + bump-version: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Construct Version String |
| 21 | + id: get_ver |
| 22 | + run: | |
| 23 | + BASE="${{ github.event.inputs.version_base }}" |
| 24 | + RUN_NUM="${{ github.run_number }}" |
| 25 | + FULL_VER="$BASE.$RUN_NUM" |
| 26 | + |
| 27 | + echo "full_version=$FULL_VER" >> $GITHUB_OUTPUT |
| 28 | + echo "base_version=$BASE" >> $GITHUB_OUTPUT |
| 29 | + |
| 30 | + - name: Update Project Files |
| 31 | + run: | |
| 32 | + VER="${{ steps.get_ver.outputs.full_version }}" |
| 33 | + echo "Bumping all files to $VER" |
| 34 | + |
| 35 | + # 1. CMakeLists.txt (Matches 'VERSION X.Y.Z.W' or 'X.Y.Z') |
| 36 | + sed -i "s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt |
| 37 | + |
| 38 | + # 2. meson.build |
| 39 | + sed -i "s/version : '[0-9.]*'/version : '$VER'/" meson.build |
| 40 | + |
| 41 | + # 3. vcpkg.json |
| 42 | + jq ".version = \"$VER\"" vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.tmp vcpkg.json |
| 43 | + |
| 44 | + # 4. include/json/version.h |
| 45 | + # We parse the base version for the numeric macros (MAJOR.MINOR.PATCH) |
| 46 | + # while the 4-part string goes into JSONCPP_VERSION_STRING. |
| 47 | + IFS='.' read -r MAJOR MINOR PATCH <<< "${{ steps.get_ver.outputs.base_version }}" |
| 48 | + |
| 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]*/# define JSONCPP_VERSION_MAJOR $MAJOR/" include/json/version.h |
| 51 | + sed -i "s/# define JSONCPP_VERSION_MINOR [0-9]*/# define JSONCPP_VERSION_MINOR $MINOR/" include/json/version.h |
| 52 | + sed -i "s/# define JSONCPP_VERSION_PATCH [0-9]*/# define JSONCPP_VERSION_PATCH $PATCH/" include/json/version.h |
| 53 | + |
| 54 | + - name: Commit and Push |
| 55 | + run: | |
| 56 | + git config user.name "github-actions[bot]" |
| 57 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 58 | + git add . |
| 59 | + git commit -m "chore: bump version to ${{ steps.get_ver.outputs.full_version }} (Run #${{ github.run_number }})" |
| 60 | + git push |
0 commit comments