auto_version_dev.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 `LOOP_FOLLOW_MARKETING_VERSION` from `Config.xcconfig`.
  10. # - The version is `MAJOR.MINOR.PATCH` format (3 digits)
  11. # where PATCH is 0 for main branch, each update to dev increments by 1
  12. #
  13. # Example:
  14. # - `2.4.0` for main
  15. # for dev → `2.4.1`, then → `2.4.2`
  16. # - next release (main) will be `2.5.0`
  17. #
  18. # Commit Handling:
  19. # The updated version is then committed and pushed back to the `dev` branch.
  20. # - The bump commit includes the `[skip ci]` tag in its message
  21. # - This prevents the workflow from re-triggering itself in a loop
  22. #
  23. # Prerequisites:
  24. # - `LOOP_FOLLOW_MARKETING_VERSION` must exist and be defined using the format:
  25. # LOOP_FOLLOW_MARKETING_VERSION = x.y.z
  26. # - GitHub Actions bot must have workflow permission to push to `dev`.
  27. # -----------------------------------------------------------------------------
  28. name: zzz [DO NOT RUN] Bump LOOP_FOLLOW_MARKETING_VERSION on dev push
  29. on:
  30. push:
  31. branches:
  32. - dev
  33. jobs:
  34. bump-version:
  35. if: ${{ !github.event.repository.fork }}
  36. runs-on: ubuntu-latest
  37. steps:
  38. - name: Checkout repository
  39. uses: actions/checkout@v5
  40. with:
  41. token: ${{ secrets.LOOPFOLLOW_TOKEN_AUTOBUMP }}
  42. fetch-depth: 0
  43. - name: Skip if Config.xcconfig was changed in this push
  44. id: check
  45. run: |
  46. BEFORE="${{ github.event.before }}"
  47. if [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then
  48. echo "skip=false" >> "$GITHUB_OUTPUT"
  49. echo "No previous SHA on this push; not skipping."
  50. exit 0
  51. fi
  52. if git diff "$BEFORE..HEAD" -- Config.xcconfig | grep -qE '^\+LOOP_FOLLOW_MARKETING_VERSION'; then
  53. echo "skip=true" >> "$GITHUB_OUTPUT"
  54. echo "LOOP_FOLLOW_MARKETING_VERSION was set in this push (likely a release sync); skipping auto-bump."
  55. else
  56. echo "skip=false" >> "$GITHUB_OUTPUT"
  57. fi
  58. - name: Set up Git
  59. if: steps.check.outputs.skip != 'true'
  60. run: |
  61. git config --global user.name "github-actions[bot]"
  62. git config --global user.email "github-actions[bot]@users.noreply.github.com"
  63. - name: Bump dev version number in Config.xcconfig
  64. if: steps.check.outputs.skip != 'true'
  65. run: |
  66. FILE=Config.xcconfig
  67. # Find the line with LOOP_FOLLOW_MARKETING_VERSION and extract the value
  68. VERSION_LINE=$(grep -E '^LOOP_FOLLOW_MARKETING_VERSION *= *[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?' "$FILE")
  69. CURRENT_VERSION=$(echo "$VERSION_LINE" | sed -E 's/^LOOP_FOLLOW_MARKETING_VERSION *= *//')
  70. # Split version into components (up to 3)
  71. IFS='.' read -r MAJOR MINOR FIX <<< "$CURRENT_VERSION"
  72. # Increment FIX
  73. if [ -z "$FIX" ]; then
  74. echo "Error, FIX not found"
  75. else
  76. FIX=$((FIX + 1))
  77. fi
  78. # Construct new version
  79. NEW_VERSION="$MAJOR.$MINOR.$FIX"
  80. echo "New version: $NEW_VERSION"
  81. # Escape dots in current version for sed replacement
  82. ESCAPED_CURRENT_VERSION=$(echo "$CURRENT_VERSION" | sed 's/\./\\./g')
  83. # Replace the LOOP_FOLLOW_MARKETING_VERSION line in-place with new version
  84. if [[ "$OSTYPE" == "darwin"* ]]; then
  85. sed -i '' -E "s/LOOP_FOLLOW_MARKETING_VERSION *= *$ESCAPED_CURRENT_VERSION/LOOP_FOLLOW_MARKETING_VERSION = $NEW_VERSION/" "$FILE"
  86. else
  87. sed -i -E "s/LOOP_FOLLOW_MARKETING_VERSION *= *$ESCAPED_CURRENT_VERSION/LOOP_FOLLOW_MARKETING_VERSION = $NEW_VERSION/" "$FILE"
  88. fi
  89. # Export version so it's available in the next step
  90. echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
  91. - name: Commit and push changes
  92. if: steps.check.outputs.skip != 'true'
  93. run: |
  94. git add Config.xcconfig
  95. git commit -m "CI: Bump dev version to $NEW_VERSION [skip ci]"
  96. git push