name: Android Release on: push: branches: - master jobs: release: runs-on: ubuntu-latest steps: # ------------------- Checkout ------------------- - name: Checkout uses: https://git.daemonlord.ru/actions/checkout@v4 with: fetch-depth: 0 tags: true # ------------------- Setup JDK ------------------- - name: Set up JDK 17 uses: https://git.daemonlord.ru/actions/setup-java@v4 with: distribution: temurin java-version: 17 # ------------------- Install Node.js ------------------- - name: Install Node.js run: | curl -fsSL https://deb.nodesource.com/setup_22.x | bash - apt-get install -y nodejs # ------------------- Extract version ------------------- - name: Extract versionName id: extract_version run: | VERSION=$(grep -oP 'versionName\s+"[^"]+"' app/build.gradle | head -n1 | cut -d'"' -f2 | tr -d '\r\n') echo "version=$VERSION" >> $GITHUB_OUTPUT echo "Detected version: $VERSION" # ------------------- Stop if already released ------------------- - name: Stop if version already released id: stop run: | VERSION=${{ steps.extract_version.outputs.version }} echo "version=$VERSION" >> $GITHUB_OUTPUT if git show-ref --tags --quiet --verify "refs/tags/$VERSION"; then echo "Version $VERSION already released, stopping job." echo "continue=false" >> $GITHUB_OUTPUT else echo "Version $VERSION not released yet, continuing workflow..." echo "continue=true" >> $GITHUB_OUTPUT fi # ------------------- Decode keystore ------------------- - name: Decode keystore if: steps.stop.outputs.continue == 'true' run: | echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > app/release.keystore - name: Make Gradlew executable if: steps.stop.outputs.continue == 'true' run: chmod +x ./gradlew # ------------------- Set up Android SDK ------------------- - name: Set up Android SDK if: steps.stop.outputs.continue == 'true' uses: https://git.daemonlord.ru/actions/setup-android@v3 # ------------------- Build Release APK ------------------- - name: Build Release APK if: steps.stop.outputs.continue == 'true' env: KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} KEY_ALIAS: ${{ secrets.KEY_ALIAS }} KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} run: ./gradlew --no-daemon assembleRelease # ------------------- Git tag ------------------- - name: Create git tag if: steps.stop.outputs.continue == 'true' run: | VERSION=${{ steps.stop.outputs.version }} git tag $VERSION git push origin $VERSION # ------------------- Gitea release ------------------- - name: Create Gitea Release if: steps.stop.outputs.continue == 'true' uses: https://git.daemonlord.ru/actions/gitea-release-action@v1 with: server_url: https://git.daemonlord.ru repository: ${{ gitea.repository }} token: ${{ secrets.API_TOKEN }} tag_name: ${{ steps.stop.outputs.version }} name: Release ${{ steps.stop.outputs.version }} body: | Android release ${{ steps.stop.outputs.version }} files: | app/build/outputs/apk/release/*.apk # ------------------- Prepare F-Droid Repo ------------------- - name: Prepare F-Droid Repo if: steps.stop.outputs.continue == 'true' run: | LICENSE="MIT" # или ${{ secrets.FDROID_LICENSE }} mkdir -p fdroid-repo/repo mkdir -p fdroid-repo/metadata cp app/build/outputs/apk/release/*.apk fdroid-repo/repo/ for apk in fdroid-repo/repo/*.apk; do FILENAME=$(basename "$apk") SHA256=$(sha256sum "$apk" | awk '{print $1}') VERSION=${{ steps.stop.outputs.version }} VERSION_CODE=$(echo $VERSION | awk -F. '{ printf("%d%02d%02d", $1,$2,$3 ? $3 : 0); }') APPID=$(grep 'applicationId' app/build.gradle | awk -F '"' '{print $2}') SOURCECODE="https://git.daemonlord.ru/${{ gitea.repository }}" cat > "fdroid-repo/metadata/$APPID.yml" < ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan -p $SCP_PORT -H $SCP_SERVER >> ~/.ssh/known_hosts rsync -avz --delete -e "ssh -p $SCP_PORT" fdroid-repo/ $SCP_USER@$SCP_SERVER:$SCP_TARGET_PATH