DO_NOT_RUN_auto_version_dev.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # -----------------------------------------------------------------------------
  2. # Workflow: Bump Dev Version
  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. # The updated value is committed and pushed back to the `dev` branch.
  29. #
  30. # Prerequisites:
  31. # - `APP_VERSION` must be present in `Config.xcconfig` in the form `x.y.z`
  32. # - `APP_DEV_VERSION` must either match `APP_VERSION` or be `x.y.z.w`
  33. # - GitHub Actions must have write permission to push to `dev`
  34. # - This workflow only runs when the repository owner is `nightscout`
  35. # -----------------------------------------------------------------------------
  36. name: Bump APP_DEV_VERSION on dev push
  37. on:
  38. push:
  39. branches:
  40. - dev
  41. jobs:
  42. bump-dev-version:
  43. if: github.repository.owner == 'nightscout'
  44. runs-on: ubuntu-latest
  45. steps:
  46. - name: Checkout repo
  47. uses: actions/checkout@v4
  48. - name: Set up Git
  49. run: |
  50. git config --global user.name "github-actions[bot]"
  51. git config --global user.email "github-actions[bot]@users.noreply.github.com"
  52. - name: Bump APP_DEV_VERSION
  53. run: |
  54. FILE=Config.xcconfig
  55. # Read current APP_VERSION
  56. BASE_VERSION=$(grep '^APP_VERSION' "$FILE" | cut -d '=' -f2 | xargs)
  57. # Read existing APP_DEV_VERSION, if any
  58. DEV_LINE=$(grep '^APP_DEV_VERSION' "$FILE" || echo "")
  59. if [ -z "$DEV_LINE" ]; then
  60. CURRENT_DEV_VERSION="$BASE_VERSION"
  61. else
  62. CURRENT_DEV_VERSION=$(echo "$DEV_LINE" | cut -d '=' -f2 | xargs)
  63. fi
  64. echo "APP_VERSION = $BASE_VERSION"
  65. echo "APP_DEV_VERSION = $CURRENT_DEV_VERSION"
  66. # Decide next dev version
  67. if [ "$CURRENT_DEV_VERSION" = "$BASE_VERSION" ]; then
  68. # First post-release commit to dev → bump to .1
  69. NEW_DEV_VERSION="${BASE_VERSION}.1"
  70. if [ -z "$DEV_LINE" ]; then
  71. echo "APP_DEV_VERSION = $NEW_DEV_VERSION" >> "$FILE"
  72. else
  73. sed -i -E "s|^APP_DEV_VERSION *= *.*|APP_DEV_VERSION = $NEW_DEV_VERSION|" "$FILE"
  74. fi
  75. else
  76. # Already in .X form → bump last digit
  77. IFS='.' read -r MAJOR MINOR PATCH FEATURE <<< "$CURRENT_DEV_VERSION"
  78. FEATURE=$((FEATURE + 1))
  79. NEW_DEV_VERSION="$MAJOR.$MINOR.$PATCH.$FEATURE"
  80. sed -i -E "s|^APP_DEV_VERSION *= *.*|APP_DEV_VERSION = $NEW_DEV_VERSION|" "$FILE"
  81. fi
  82. echo "NEW APP_DEV_VERSION = $NEW_DEV_VERSION"
  83. echo "NEW_DEV_VERSION=$NEW_DEV_VERSION" >> $GITHUB_ENV
  84. - name: Commit and push updated dev version
  85. run: |
  86. git add Config.xcconfig
  87. git commit -m "CI: Bump APP_DEV_VERSION to $NEW_DEV_VERSION"
  88. git push