auto_version_dev.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # -----------------------------------------------------------------------------
  2. # Workflow: `auto_version_dev.yml`
  3. #
  4. # Description:
  5. # This GitHub Actions workflow automatically manages and increments the
  6. # `APP_DEV_VERSION` defined in `Config.xcconfig` on every push to `dev` branch.
  7. # This version is used for internal tracking and diagnostics (e.g. in
  8. # Crashlytics) and follows a 4-digit semantic versioning format:
  9. # `MAJOR.MINOR.PATCH.FEATURE`.
  10. #
  11. # Versioning Logic:
  12. # - Reads the base version from `APP_VERSION = x.y.z`
  13. # - Reads the last internal dev version from `APP_DEV_VERSION`
  14. #
  15. # Behavior:
  16. # - If `APP_DEV_VERSION` matches `APP_VERSION` (e.g. both are `0.5.0`),
  17. # it assumes the first dev push after a release and sets `APP_DEV_VERSION`
  18. # to `APP_VERSION.1` (e.g. `0.5.0.1`)
  19. # - If `APP_DEV_VERSION` is already in 4-digit form (e.g. `0.5.0.3`),
  20. # it increments the fourth digit (e.g. → `0.5.0.4`)
  21. #
  22. # Example Progression:
  23. # - Release sets `APP_VERSION = 0.5.0`, `APP_DEV_VERSION = 0.5.0`
  24. # - First push to `dev`: → `APP_DEV_VERSION = 0.5.0.1`
  25. # - Second push to `dev`: → `APP_DEV_VERSION = 0.5.0.2`
  26. # - ...
  27. #
  28. # Commit Handling:
  29. # The updated value is committed and pushed back to the `dev` branch.
  30. # - The bump commit includes the `[skip ci]` tag in its message
  31. # - This prevents the workflow from re-triggering itself in a loop
  32. #
  33. #
  34. # Prerequisites:
  35. # - `APP_VERSION` must be present in `Config.xcconfig` in the form `x.y.z`
  36. # - `APP_DEV_VERSION` must either match `APP_VERSION` or be `x.y.z.w`
  37. # - GitHub Actions must have write permission to push to `dev`
  38. # - This workflow only runs when the repository owner is `nightscout`
  39. # -----------------------------------------------------------------------------
  40. name: zzz [DO NOT RUN] Bump APP_DEV_VERSION on dev push
  41. on:
  42. push:
  43. branches:
  44. - dev
  45. jobs:
  46. bump-dev-version:
  47. if: github.repository_owner == 'nightscout'
  48. runs-on: ubuntu-latest
  49. steps:
  50. - name: Checkout repo
  51. uses: actions/checkout@v5
  52. with:
  53. token: ${{ secrets.TRIO_TOKEN_AUTOBUMP }}
  54. - name: Set up Git
  55. run: |
  56. git config --global user.name "github-actions[bot]"
  57. git config --global user.email "github-actions[bot]@users.noreply.github.com"
  58. - name: Bump APP_DEV_VERSION
  59. run: |
  60. FILE=Config.xcconfig
  61. # Read current APP_VERSION
  62. BASE_VERSION=$(grep '^APP_VERSION' "$FILE" | cut -d '=' -f2 | xargs)
  63. # Read existing APP_DEV_VERSION, if any
  64. DEV_LINE=$(grep '^APP_DEV_VERSION' "$FILE" || echo "")
  65. if [ -z "$DEV_LINE" ]; then
  66. CURRENT_DEV_VERSION="$BASE_VERSION"
  67. else
  68. CURRENT_DEV_VERSION=$(echo "$DEV_LINE" | cut -d '=' -f2 | xargs)
  69. fi
  70. echo "APP_VERSION = $BASE_VERSION"
  71. echo "APP_DEV_VERSION = $CURRENT_DEV_VERSION"
  72. # Decide next dev version
  73. if [ "$CURRENT_DEV_VERSION" = "$BASE_VERSION" ]; then
  74. # First post-release commit to dev → bump to .1
  75. NEW_DEV_VERSION="${BASE_VERSION}.1"
  76. if [ -z "$DEV_LINE" ]; then
  77. echo "APP_DEV_VERSION = $NEW_DEV_VERSION" >> "$FILE"
  78. else
  79. sed -i -E "s|^APP_DEV_VERSION *= *.*|APP_DEV_VERSION = $NEW_DEV_VERSION|" "$FILE"
  80. fi
  81. else
  82. # Already in .X form → bump last digit
  83. IFS='.' read -r MAJOR MINOR PATCH FEATURE <<< "$CURRENT_DEV_VERSION"
  84. FEATURE=$((FEATURE + 1))
  85. NEW_DEV_VERSION="$MAJOR.$MINOR.$PATCH.$FEATURE"
  86. sed -i -E "s|^APP_DEV_VERSION *= *.*|APP_DEV_VERSION = $NEW_DEV_VERSION|" "$FILE"
  87. fi
  88. echo "NEW APP_DEV_VERSION = $NEW_DEV_VERSION"
  89. echo "NEW_DEV_VERSION=$NEW_DEV_VERSION" >> $GITHUB_ENV
  90. - name: Commit and push updated dev version
  91. run: |
  92. git add Config.xcconfig
  93. git commit -m "CI: Bump APP_DEV_VERSION to $NEW_DEV_VERSION [skip ci]"
  94. git push