DO_NOT_RUN_auto_version_dev.yml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. runs-on: ubuntu-latest
  34. steps:
  35. - name: Checkout repository
  36. uses: actions/checkout@v3
  37. - name: Set up Git
  38. run: |
  39. git config --global user.name "github-actions[bot]"
  40. git config --global user.email "github-actions[bot]@users.noreply.github.com"
  41. - name: Bump dev version number in Config.xcconfig
  42. run: |
  43. FILE=Config.xcconfig
  44. # Find the line with APP_VERSION and extract the value
  45. VERSION_LINE=$(grep -E '^APP_VERSION *= *[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?' "$FILE")
  46. CURRENT_VERSION=$(echo "$VERSION_LINE" | sed -E 's/^APP_VERSION *= *//')
  47. # Split version into components (up to 4)
  48. IFS='.' read -r MAJOR MINOR FIX BUILD <<< "$CURRENT_VERSION"
  49. # If 4th digit not present, start at 1; else increment
  50. if [ -z "$BUILD" ]; then
  51. BUILD=1
  52. else
  53. BUILD=$((BUILD + 1))
  54. fi
  55. # Construct new version
  56. NEW_VERSION="$MAJOR.$MINOR.$FIX.$BUILD"
  57. echo "New version: $NEW_VERSION"
  58. # Escape dots in current version for sed replacement
  59. ESCAPED_CURRENT_VERSION=$(echo "$CURRENT_VERSION" | sed 's/\./\\./g')
  60. # Replace the APP_VERSION line in-place with new version
  61. sed -i '' -E "s/APP_VERSION *= *$ESCAPED_CURRENT_VERSION/APP_VERSION = $NEW_VERSION/" "$FILE"
  62. # Export version so it's available in the next step
  63. echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
  64. - name: Commit and push changes
  65. run: |
  66. git add Config.xcconfig
  67. git commit -m "CI: Bump dev version to $NEW_VERSION"
  68. git push