Handle sync #96
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Android CI with Versioning | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - 'release/**' | |
| pull_request: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: 17 | |
| - name: Set up Android SDK | |
| uses: android-actions/setup-android@v3 | |
| - name: Accept SDK Licenses | |
| run: yes | sdkmanager --licenses | |
| # ✅ Create local.properties & keystore at project root | |
| - name: Create local.properties & decode keystore | |
| run: | | |
| echo "sdk.dir=$ANDROID_HOME" > local.properties | |
| echo "KEYSTORE_FILE=keystore/release.jks" >> local.properties | |
| echo "KEYSTORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}" >> local.properties | |
| echo "KEY_ALIAS=${{ secrets.KEY_ALIAS }}" >> local.properties | |
| echo "KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}" >> local.properties | |
| mkdir -p keystore | |
| printf '%s' "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > keystore/release.jks | |
| - name: Show local.properties | |
| run: cat local.properties | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: ${{ runner.os }}-gradle- | |
| # ✅ Write google-services.json from secret | |
| - name: Write google-services.json | |
| run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > app/google-services.json | |
| - name: Build and run unit tests | |
| run: ./gradlew clean assembleDebug assembleRelease testDebugUnitTest --no-daemon --stacktrace | |
| - name: Debug Show APK files | |
| run: ls -R app/build/outputs/apk | |
| - name: Upload Debug APK artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: UgandaEMR-Mobile-debug-apk | |
| path: app/build/outputs/apk/debug/app-debug.apk | |
| - name: Upload Release APK artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: UgandaEMR-Mobile-release-apk | |
| path: app/build/outputs/apk/release/app-release.apk | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| outputs: | |
| tag: ${{ steps.auto_tag.outputs.tag }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Download Debug APK artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: UgandaEMR-Mobile-debug-apk | |
| path: app/build/outputs/apk/debug | |
| - name: Download Release APK artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: UgandaEMR-Mobile-release-apk | |
| path: app/build/outputs/apk/release | |
| - name: Auto-tag new version | |
| id: auto_tag | |
| run: | | |
| git fetch --tags | |
| LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) | |
| if [ -z "$LATEST_TAG" ]; then | |
| LATEST_TAG="v0.0.0" | |
| fi | |
| echo "Latest tag: $LATEST_TAG" | |
| VERSION_PARTS=(${LATEST_TAG//./ }) | |
| MAJOR=${VERSION_PARTS[0]#v} | |
| MINOR=${VERSION_PARTS[1]} | |
| PATCH=${VERSION_PARTS[2]} | |
| NEW_PATCH=$((PATCH + 1)) | |
| NEW_VERSION="v${MAJOR}.${MINOR}.${NEW_PATCH}" | |
| echo "New version: $NEW_VERSION" | |
| if git rev-parse "$NEW_VERSION" >/dev/null 2>&1; then | |
| echo "Tag $NEW_VERSION already exists! Skipping..." | |
| echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT | |
| else | |
| git config user.name "github-actions" | |
| git config user.email "actions@github.com" | |
| git tag $NEW_VERSION | |
| git push origin $NEW_VERSION | |
| echo "tag=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate release notes | |
| run: | | |
| git fetch --tags | |
| LATEST_TAG=$(git tag --sort=-v:refname | head -n 1) | |
| echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
| git log ${LATEST_TAG}..HEAD --pretty=format:"- %s" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Install Firebase CLI | |
| run: npm install -g firebase-tools | |
| - name: Upload Release APK to Firebase App Distribution | |
| run: | | |
| firebase appdistribution:distribute app/build/outputs/apk/release/app-release.apk \ | |
| --app ${{ secrets.FIREBASE_APP_ID }} \ | |
| --groups internal-testers \ | |
| --release-notes "Automated build from GitHub Actions with Service Account" | |
| env: | |
| FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ steps.auto_tag.outputs.tag }} | |
| name: Release ${{ steps.auto_tag.outputs.tag }} | |
| body: ${{ env.RELEASE_NOTES }} | |
| files: | | |
| app/build/outputs/apk/debug/app-debug.apk | |
| app/build/outputs/apk/release/app-release.apk | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Notify Slack on Success | |
| if: success() | |
| run: | | |
| curl -X POST -H 'Content-type: application/json' \ | |
| --data '{ | |
| "text": "✅ *Build and Release Successful* for `${{ github.repository }}` on `${{ github.ref_name }}`. Version: `${{ steps.auto_tag.outputs.tag }}`" | |
| }' ${{ secrets.SLACK_WEBHOOK_URL }} | |
| - name: Notify Slack on Failure | |
| if: failure() | |
| run: | | |
| curl -X POST -H 'Content-type: application/json' \ | |
| --data '{ | |
| "text": "❌ *Build Failed* for `${{ github.repository }}` on `${{ github.ref_name }}`." | |
| }' ${{ secrets.SLACK_WEBHOOK_URL }} |