update project version #14
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "update project version" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| target_version: | |
| description: 'next version (e.g., 1.9.7 or 1.9.7.12)' | |
| required: true | |
| default: '1.9.7' | |
| target_soversion: | |
| description: 'next soversion (e.g., 28). leave blank to keep current.' | |
| required: false | |
| jobs: | |
| bump-and-verify: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: checkout code | |
| uses: actions/checkout@v4 | |
| - name: update project files | |
| id: update_files | |
| run: | | |
| VER="${{ github.event.inputs.target_version }}" | |
| SOVER="${{ github.event.inputs.target_soversion }}" | |
| echo "bumping version to $VER" | |
| # 1. cmakelists.txt: surgical update inside project() block | |
| if [ -f CMakeLists.txt ]; then | |
| echo "updating cmakelists.txt" | |
| sed -i "/project[[:space:]]*([[:space:]]*jsoncpp/,/)/ s/VERSION [0-9.]*/VERSION $VER/" CMakeLists.txt | |
| if [ -n "$SOVER" ]; then | |
| sed -i "s/set(PROJECT_SOVERSION [0-9]*/set(PROJECT_SOVERSION $SOVER/" CMakeLists.txt | |
| fi | |
| fi | |
| # 2. meson.build: targeting keys directly | |
| if [ -f meson.build ]; then | |
| echo "updating meson.build" | |
| sed -i "s/version[[:space:]]*:[[:space:]]*['][0-9.]*[']/version : '$VER'/" meson.build | |
| if [ -n "$SOVER" ]; then | |
| sed -i "s/soversion[[:space:]]*:[[:space:]]*['][0-9]*[']/soversion : '$SOVER'/" meson.build | |
| fi | |
| fi | |
| # 3. module.bazel: surgical update inside module() block | |
| if [ -f MODULE.bazel ]; then | |
| echo "updating module.bazel" | |
| sed -i "/module(/,/)/ s/version[[:space:]]*=[[:space:]]*['\"][0-9.]*['\"]/version = \"$VER\"/" MODULE.bazel | |
| fi | |
| # 4. vcpkg.json | |
| if [ -f vcpkg.json ]; then | |
| echo "updating vcpkg.json" | |
| jq --arg ver "$VER" '.version = $ver' vcpkg.json > vcpkg.json.tmp && mv vcpkg.json.tmp vcpkg.json | |
| fi | |
| # 5. include/json/version.h | |
| if [ -f include/json/version.h ]; then | |
| echo "updating version.h" | |
| MAJOR=$(echo "$VER" | cut -d. -f1) | |
| MINOR=$(echo "$VER" | cut -d. -f2) | |
| PATCH=$(echo "$VER" | cut -d. -f3) | |
| QUALIFIER=$(echo "$VER" | cut -d. -f4 -s) | |
| sed -i "s/#define JSONCPP_VERSION_STRING \".*\"/#define JSONCPP_VERSION_STRING \"$VER\"/" include/json/version.h | |
| sed -i "s/#define JSONCPP_VERSION_MAJOR [0-9]*/#define JSONCPP_VERSION_MAJOR $MAJOR/" include/json/version.h | |
| sed -i "s/#define JSONCPP_VERSION_MINOR [0-9]*/#define JSONCPP_VERSION_MINOR $MINOR/" include/json/version.h | |
| sed -i "s/#define JSONCPP_VERSION_PATCH [0-9]*/#define JSONCPP_VERSION_PATCH $PATCH/" include/json/version.h | |
| if [ -n "$QUALIFIER" ]; then | |
| sed -i "s/#define JSONCPP_VERSION_QUALIFIER.*/#define JSONCPP_VERSION_QUALIFIER $QUALIFIER/" include/json/version.h | |
| else | |
| sed -i "s/#define JSONCPP_VERSION_QUALIFIER.*/#define JSONCPP_VERSION_QUALIFIER/" include/json/version.h | |
| fi | |
| fi | |
| - name: verify version macros | |
| id: verify | |
| run: | | |
| FILE="include/json/version.h" | |
| if [ -f "$FILE" ]; then | |
| V_STR=$(grep "JSONCPP_VERSION_STRING" $FILE | awk -F'"' '{print $2}') | |
| V_MAJ=$(grep "JSONCPP_VERSION_MAJOR" $FILE | awk '{print $3}') | |
| V_MIN=$(grep "JSONCPP_VERSION_MINOR" $FILE | awk '{print $3}') | |
| V_PAT=$(grep "JSONCPP_VERSION_PATCH" $FILE | awk '{print $3}') | |
| V_QUA=$(grep "JSONCPP_VERSION_QUALIFIER" $FILE | awk '{print $3}') | |
| echo "### version.h verification" >> $GITHUB_STEP_SUMMARY | |
| echo "| macro | value |" >> $GITHUB_STEP_SUMMARY | |
| echo "| :--- | :--- |" >> $GITHUB_STEP_SUMMARY | |
| echo "| string | $V_STR |" >> $GITHUB_STEP_SUMMARY | |
| echo "| major | $V_MAJ |" >> $GITHUB_STEP_SUMMARY | |
| echo "| minor | $V_MIN |" >> $GITHUB_STEP_SUMMARY | |
| echo "| patch | $V_PAT |" >> $GITHUB_STEP_SUMMARY | |
| echo "| qualifier | ${V_QUA:-*(empty)*} |" >> $GITHUB_STEP_SUMMARY | |
| # pass values to the pr body | |
| { | |
| echo "header_report<<EOF" | |
| echo "| Macro | Value |" | |
| echo "| :--- | :--- |" | |
| echo "| STRING | \`$V_STR\` |" | |
| echo "| MAJOR | \`$V_MAJ\` |" | |
| echo "| MINOR | \`$V_MIN\` |" | |
| echo "| PATCH | \`$V_PAT\` |" | |
| echo "| QUALIFIER | \`${V_QUA:-empty}\` |" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| fi | |
| - name: sanity check (cmake configure) | |
| run: | | |
| if [ -f CMakeLists.txt ]; then | |
| mkdir build_check | |
| cd build_check | |
| cmake .. -DJSONCPP_WITH_TESTS=OFF -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF | |
| cd .. | |
| rm -rf build_check | |
| fi | |
| - name: create pull request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "chore: bump version to ${{ github.event.inputs.target_version }}" | |
| branch: "bump-to-${{ github.event.inputs.target_version }}" | |
| title: "chore: bump version to ${{ github.event.inputs.target_version }}" | |
| body: | | |
| automated version bump. | |
| - new version: `${{ github.event.inputs.target_version }}` | |
| - new soversion: `${{ github.event.inputs.target_soversion || 'no change' }}` | |
| ### header verification | |
| ${{ steps.verify.outputs.header_report }} | |
| labels: "maintenance" |