|
4 | 4 | push: |
5 | 5 | tags: |
6 | 6 | - 'v*' |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - 'config.gradle' |
7 | 11 | workflow_dispatch: |
8 | 12 | inputs: |
9 | 13 | version: |
@@ -39,33 +43,102 @@ jobs: |
39 | 43 | outputs: |
40 | 44 | version: ${{ steps.version.outputs.version }} |
41 | 45 | version_code: ${{ steps.version_info.outputs.version_code }} |
| 46 | + should_release: ${{ steps.check_version.outputs.should_release }} |
42 | 47 |
|
43 | 48 | steps: |
44 | 49 | - name: Checkout code |
45 | 50 | uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + fetch-depth: 2 # Need history for version comparison |
46 | 53 |
|
| 54 | + - name: Check if version changed (for config.gradle trigger) |
| 55 | + id: check_version |
| 56 | + if: github.event_name == 'push' && contains(github.event.head_commit.modified, 'config.gradle') |
| 57 | + run: | |
| 58 | + # Get current version from config.gradle |
| 59 | + CURRENT_VERSION=$(grep versionName config.gradle | sed -E 's/.*versionName:\s*"([^"]+)".*/\1/') |
| 60 | + CURRENT_CODE=$(grep versionCode config.gradle | sed -E 's/.*versionCode:\s*([0-9]+).*/\1/') |
| 61 | + |
| 62 | + # Get previous version - handle first commit case |
| 63 | + if git rev-parse HEAD~1 >/dev/null 2>&1; then |
| 64 | + git show HEAD~1:config.gradle > prev_config.gradle 2>/dev/null || echo "No previous config.gradle" |
| 65 | + if [ -f prev_config.gradle ]; then |
| 66 | + PREV_VERSION=$(grep versionName prev_config.gradle | sed -E 's/.*versionName:\s*"([^"]+)".*/\1/' || echo "") |
| 67 | + PREV_CODE=$(grep versionCode prev_config.gradle | sed -E 's/.*versionCode:\s*([0-9]+).*/\1/' || echo "0") |
| 68 | + rm prev_config.gradle |
| 69 | + else |
| 70 | + PREV_VERSION="" |
| 71 | + PREV_CODE="0" |
| 72 | + fi |
| 73 | + else |
| 74 | + # First commit in repo |
| 75 | + PREV_VERSION="" |
| 76 | + PREV_CODE="0" |
| 77 | + fi |
| 78 | + |
| 79 | + echo "Previous: v$PREV_VERSION (code: $PREV_CODE)" |
| 80 | + echo "Current: v$CURRENT_VERSION (code: $CURRENT_CODE)" |
| 81 | + |
| 82 | + # Check if version increased |
| 83 | + if [ -n "$CURRENT_VERSION" ] && [ "$CURRENT_CODE" -gt "$PREV_CODE" ]; then |
| 84 | + echo "✅ Version increased from $PREV_VERSION to $CURRENT_VERSION" |
| 85 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 86 | + echo "version=v$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 87 | + |
| 88 | + # Check if tag already exists |
| 89 | + if git ls-remote --tags origin | grep -q "refs/tags/v${CURRENT_VERSION}$"; then |
| 90 | + echo "⚠️ Tag v$CURRENT_VERSION already exists, skipping release" |
| 91 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 92 | + fi |
| 93 | + else |
| 94 | + echo "ℹ️ No version increase detected or invalid version" |
| 95 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 96 | + fi |
| 97 | + |
47 | 98 | - name: Determine version |
48 | 99 | id: version |
49 | 100 | run: | |
50 | 101 | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
51 | 102 | VERSION="${{ github.event.inputs.version }}" |
52 | | - else |
| 103 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 104 | + elif [ "${{ steps.check_version.outputs.should_release }}" = "true" ]; then |
| 105 | + VERSION="${{ steps.check_version.outputs.version }}" |
| 106 | + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then |
53 | 107 | VERSION="${{ github.ref_name }}" |
| 108 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 109 | + else |
| 110 | + VERSION="v0.0.0" |
| 111 | + echo "should_release=false" >> $GITHUB_OUTPUT |
54 | 112 | fi |
55 | 113 | echo "version=$VERSION" >> $GITHUB_OUTPUT |
56 | 114 | echo "Version: $VERSION" |
57 | 115 | |
58 | 116 | - name: Extract version code |
59 | 117 | id: version_info |
60 | 118 | run: | |
61 | | - # Extract version code from config.gradle |
62 | | - VERSION_CODE=$(grep "versionCode:" config.gradle | sed 's/.*versionCode: \([0-9]*\).*/\1/') |
| 119 | + # Extract version code from config.gradle - handle both formats |
| 120 | + VERSION_CODE=$(grep "versionCode:" config.gradle | sed -E 's/.*versionCode:\s*([0-9]+).*/\1/') |
63 | 121 | echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT |
64 | 122 | echo "Version Code: $VERSION_CODE" |
| 123 | + |
| 124 | + - name: Create tag if version changed |
| 125 | + if: steps.check_version.outputs.should_release == 'true' && github.event_name == 'push' && contains(github.event.head_commit.modified, 'config.gradle') |
| 126 | + run: | |
| 127 | + TAG_NAME="${{ steps.version.outputs.version }}" |
| 128 | + |
| 129 | + git config user.name "github-actions[bot]" |
| 130 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 131 | + |
| 132 | + # Create annotated tag |
| 133 | + git tag -a "${TAG_NAME}" -m "Release ${TAG_NAME} (version code: ${{ steps.version_info.outputs.version_code }})" |
| 134 | + git push origin "${TAG_NAME}" |
| 135 | + |
| 136 | + echo "🏷️ Created and pushed tag: ${TAG_NAME}" |
65 | 137 |
|
66 | 138 | build-apk: |
67 | 139 | name: Build Release APK |
68 | 140 | needs: prepare |
| 141 | + if: needs.prepare.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') |
69 | 142 | runs-on: ubuntu-latest |
70 | 143 |
|
71 | 144 | steps: |
@@ -141,6 +214,7 @@ jobs: |
141 | 214 | build-aab: |
142 | 215 | name: Build Release Bundle |
143 | 216 | needs: prepare |
| 217 | + if: needs.prepare.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') |
144 | 218 | runs-on: ubuntu-latest |
145 | 219 |
|
146 | 220 | steps: |
@@ -203,6 +277,7 @@ jobs: |
203 | 277 | release: |
204 | 278 | name: Create GitHub Release |
205 | 279 | needs: [prepare, build-apk, build-aab] |
| 280 | + if: needs.prepare.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/') |
206 | 281 | runs-on: ubuntu-latest |
207 | 282 |
|
208 | 283 | steps: |
@@ -276,7 +351,7 @@ jobs: |
276 | 351 | play-store-upload: |
277 | 352 | name: Upload to Play Store |
278 | 353 | needs: [prepare, build-aab] |
279 | | - if: ${{ vars.ENABLE_PLAY_STORE_UPLOAD == 'true' && vars.ENABLE_SIGNING == 'true' }} |
| 354 | + if: ${{ (needs.prepare.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/')) && vars.ENABLE_PLAY_STORE_UPLOAD == 'true' && vars.ENABLE_SIGNING == 'true' }} |
280 | 355 | runs-on: ubuntu-latest |
281 | 356 |
|
282 | 357 | steps: |
@@ -386,7 +461,7 @@ jobs: |
386 | 461 | download-signed-apk: |
387 | 462 | name: Download Google Play Signed APK |
388 | 463 | needs: [prepare, play-store-upload] |
389 | | - if: ${{ vars.ENABLE_PLAY_STORE_UPLOAD == 'true' && vars.ENABLE_SIGNING == 'true' }} |
| 464 | + if: ${{ (needs.prepare.outputs.should_release == 'true' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/')) && vars.ENABLE_PLAY_STORE_UPLOAD == 'true' && vars.ENABLE_SIGNING == 'true' }} |
390 | 465 | runs-on: ubuntu-latest |
391 | 466 |
|
392 | 467 | steps: |
|
0 commit comments