Files
MonthlyPaymentApp/.github/workflows/release.yml
T
Oqba 5848f7a3bb
Android Release / build (push) Failing after 3m25s
Configure local.properties, disable lint, and fix SDK path
2026-11-03 06:09:57 +03:30

134 lines
5.3 KiB
YAML

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
if [ -z "$JAVA_HOME" ] || [ ! -d "$JAVA_HOME" ]; then
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"
fi
# 2. Setup Android SDK and local.properties
SDK_DIR="/opt/android-sdk-linux"
if [ ! -d "$SDK_DIR" ]; then
SDK_DIR=$(find /opt /usr /root -maxdepth 3 -name "platforms" -type d 2>/dev/null | head -n 1 | xargs -r dirname)
fi
echo "Using Android SDK at: $SDK_DIR"
export ANDROID_HOME="$SDK_DIR"
export ANDROID_SDK_ROOT="$SDK_DIR"
export PATH="$SDK_DIR/cmdline-tools/latest/bin:$SDK_DIR/platform-tools:$PATH"
# Write local.properties so Gradle finds it unconditionally
echo "sdk.dir=$SDK_DIR" > local.properties
cat local.properties
# 3. Build Release APK without lint
./gradlew assembleRelease -Pandroid.sdk.path="$SDK_DIR" -x lint -x lintVitalRelease -x lintVitalReportRelease --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
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 <<EOF > 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"