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: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' cache: gradle - 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: ./gradlew assembleRelease --no-daemon - 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 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 git checkout main 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