DO_NOT_RUN_auto_version_dev.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # -----------------------------------------------------------------------------
  2. # Workflow: Bump Dev Version
  3. #
  4. # Description:
  5. # This GitHub Actions workflow automatically increments the version number
  6. # defined in `Config.xcconfig` on every push to the `dev` branch.
  7. #
  8. # Versioning Logic:
  9. # - Reads the `APP_VERSION` from `Config.xcconfig`.
  10. # - If the version is in `MAJOR.MINOR.PATCH.BUILD` format (4 digits),
  11. # the `BUILD` number is incremented by 1.
  12. # - If the version is in `MAJOR.MINOR.PATCH` format (3 digits),
  13. # a `.1` is appended to start a `BUILD` count.
  14. #
  15. # Example:
  16. # - `0.5.0` → `0.5.0.1`
  17. # - `0.5.0.3` → `0.5.0.4`
  18. #
  19. # The updated version is then committed and pushed back to the `dev` branch.
  20. #
  21. # Prerequisites:
  22. # - `APP_VERSION` must exist and be defined using the format:
  23. # APP_VERSION = x.y.z or x.y.z.w
  24. # - GitHub Actions bot must have workflow permission to push to `dev`.
  25. # -----------------------------------------------------------------------------
  26. name: Bump Dev Version
  27. on:
  28. push:
  29. branches:
  30. - dev
  31. jobs:
  32. bump-version:
  33. if: github.repository_owner == 'nightscout'
  34. runs-on: ubuntu-latest
  35. steps:
  36. - name: Checkout repository
  37. uses: actions/checkout@v4
  38. - name: Set up Git
  39. run: |
  40. git config --global user.name "github-actions[bot]"
  41. git config --global user.email "github-actions[bot]@users.noreply.github.com"
  42. - name: Bump dev version number in Config.xcconfig
  43. run: |
  44. FILE=Config.xcconfig
  45. # Find the line with APP_VERSION and extract the value
  46. VERSION_LINE=$(grep -E '^APP_VERSION *= *[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?' "$FILE")
  47. CURRENT_VERSION=$(echo "$VERSION_LINE" | sed -E 's/^APP_VERSION *= *//')
  48. # Split version into components (up to 4)
  49. IFS='.' read -r MAJOR MINOR FIX BUILD <<< "$CURRENT_VERSION"
  50. # If 4th digit not present, start at 1; else increment
  51. if [ -z "$BUILD" ]; then
  52. BUILD=1
  53. else
  54. BUILD=$((BUILD + 1))
  55. fi
  56. # Construct new version
  57. NEW_VERSION="$MAJOR.$MINOR.$FIX.$BUILD"
  58. echo "New version: $NEW_VERSION"
  59. # Escape dots in current version for sed replacement
  60. ESCAPED_CURRENT_VERSION=$(echo "$CURRENT_VERSION" | sed 's/\./\\./g')
  61. # Replace the APP_VERSION line in-place with new version
  62. if [[ "$OSTYPE" == "darwin"* ]]; then
  63. sed -i '' -E "s/APP_VERSION *= *$ESCAPED_CURRENT_VERSION/APP_VERSION = $NEW_VERSION/" "$FILE"
  64. else
  65. sed -i -E "s/APP_VERSION *= *$ESCAPED_CURRENT_VERSION/APP_VERSION = $NEW_VERSION/" "$FILE"
  66. fi
  67. # Export version so it's available in the next step
  68. echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
  69. - name: Commit and push changes
  70. run: |
  71. git add Config.xcconfig
  72. git commit -m "CI: Bump dev version to $NEW_VERSION"
  73. git push