name: Android Release on: push: tags: - 'v*' jobs: build: runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout code uses: actions/checkout@v4 - name: Configure Environment (Gitea) if: "!contains(github.server_url, 'github.com')" run: | JAVA_BIN=$(which java 2>/dev/null || find /usr /opt -name java -type f 2>/dev/null | grep -E '/bin/java$' | head -n 1 || echo /usr/lib/jvm/java-21-openjdk-amd64/bin/java) JAVA_PATH=$(dirname $(dirname $(readlink -f "$JAVA_BIN"))) echo "Using JAVA_HOME=$JAVA_PATH" echo "JAVA_HOME=$JAVA_PATH" >> $GITHUB_ENV echo "ANDROID_HOME=/opt/android-sdk-linux" >> $GITHUB_ENV echo "ANDROID_SDK_ROOT=/opt/android-sdk-linux" >> $GITHUB_ENV echo "$JAVA_PATH/bin" >> $GITHUB_PATH echo "/opt/android-sdk-linux/cmdline-tools/latest/bin" >> $GITHUB_PATH echo "/opt/android-sdk-linux/platform-tools" >> $GITHUB_PATH - name: Set up JDK 21 (GitHub Hosted) if: contains(github.server_url, 'github.com') uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Create Keystore env: KEYSTORE_B64: ${{ secrets.KEYSTORE_BASE64 }} run: echo "$KEYSTORE_B64" | base64 -d > app/release-key.jks - name: Build Release APK env: RELEASE_STORE_FILE: release-key.jks RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }} RELEASE_KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }} RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }} run: | # 1. Setup Java JAVA_BIN=$(which java 2>/dev/null || find /usr /opt -name java -type f 2>/dev/null | grep -E '/bin/java$' | head -n 1 || echo /usr/lib/jvm/java-21-openjdk-amd64/bin/java) export JAVA_HOME=$(dirname $(dirname $(readlink -f "$JAVA_BIN"))) export PATH="$JAVA_HOME/bin:$PATH" # 2. Setup Android SDK export ANDROID_HOME=/opt/android-sdk-linux export ANDROID_SDK_ROOT=/opt/android-sdk-linux export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH" echo "sdk.dir=/opt/android-sdk-linux" > local.properties # 3. Build Release APK ./gradlew assembleRelease --no-daemon -x lint -x test - name: Rename APK run: | mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/MonthlyPaymentApp-${{ github.ref_name }}.apk - name: Upload APK Artifact uses: actions/upload-artifact@v4 continue-on-error: true with: name: MonthlyPaymentApp-${{ github.ref_name }} path: app/build/outputs/apk/release/MonthlyPaymentApp-${{ github.ref_name }}.apk - name: Create Release (GitHub) if: contains(github.server_url, 'github.com') uses: softprops/action-gh-release@v2 with: files: app/build/outputs/apk/release/MonthlyPaymentApp-${{ github.ref_name }}.apk env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create Release (Gitea) if: "!contains(github.server_url, 'github.com')" uses: akkuman/gitea-release-action@v1 env: NODE_OPTIONS: '--experimental-fetch' with: files: app/build/outputs/apk/release/MonthlyPaymentApp-${{ github.ref_name }}.apk name: "Release ${{ github.ref_name }}" tag_name: ${{ github.ref_name }} token: ${{ secrets.GITHUB_TOKEN }} draft: false prerelease: false - name: Update update.json after release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | TAG_NAME="${{ github.ref_name }}" VERSION_NAME="${TAG_NAME#v}" VERSION_CODE=$(grep 'versionCode' app/build.gradle.kts | head -n 1 | awk '{print $3}') git config user.name "actions-bot" git config user.email "bot@mizbanplatform.ir" git fetch origin main || true git checkout main || true cat < update.json { "versionCode": ${VERSION_CODE}, "versionName": "${VERSION_NAME}", "url": "${{ github.server_url }}/${{ github.repository }}/releases/download/${TAG_NAME}/MonthlyPaymentApp-${TAG_NAME}.apk", "releaseNotes": "رفع باگ حذف پرداخت‌ها و پایداری همگام‌سازی", "isForceUpdate": false } EOF git add update.json git commit -m "auto-update update.json for release ${TAG_NAME}" || true git push origin main || echo "Push skipped or not needed"