forked from upstream-mirrors/quik
117 lines
4.1 KiB
YAML
117 lines
4.1 KiB
YAML
name: Build and Release APK
|
|
|
|
on:
|
|
push:
|
|
branches: [ master ]
|
|
tags: [ 'v*' ]
|
|
pull_request:
|
|
branches: [ master ]
|
|
|
|
jobs:
|
|
build:
|
|
name: Build APK
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: mingc/android-build-box:latest
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Java 17
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: temurin
|
|
java-version: '17'
|
|
|
|
- name: Test release signing checks
|
|
run: python3 -m unittest discover -s .gitea/tests -v
|
|
|
|
- name: Restore and validate release signing key
|
|
if: github.event_name != 'pull_request'
|
|
run: python3 .gitea/scripts/signing.py prepare
|
|
env:
|
|
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
|
|
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
|
|
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
|
|
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
|
|
|
|
- name: Restore Gradle Cache
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-gradle-
|
|
|
|
- name: Grant execute permission for gradlew
|
|
run: chmod +x gradlew
|
|
|
|
- name: Bump Version Code for CI
|
|
run: |
|
|
python3 - <<'PYTHON'
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
path = Path("presentation/build.gradle")
|
|
source = path.read_text()
|
|
run = int(os.environ["BUILD_NUMBER"])
|
|
code = int(re.search(r"versionCode (\d+)", source).group(1)) + run
|
|
base = re.search(r"versionName '([^']+)'", source).group(1)
|
|
version = f"{base}-remotrix.{run}"
|
|
source = re.sub(r"versionCode \d+", f"versionCode {code}", source, count=1)
|
|
source = re.sub(r"versionName '[^']+'", f"versionName '{version}'", source, count=1)
|
|
path.write_text(source)
|
|
with open(os.environ["GITHUB_ENV"], "a") as env:
|
|
env.write(f"APP_VERSION={version}\n")
|
|
PYTHON
|
|
env:
|
|
BUILD_NUMBER: ${{ github.run_number }}
|
|
|
|
- name: Test worker factory and Matrix bridge
|
|
run: |
|
|
set -eu
|
|
./gradlew :presentation:cleanTestDebugUnitTest :remotrix-sync:cleanTestDebugUnitTest :presentation:testDebugUnitTest :remotrix-sync:testDebugUnitTest
|
|
python3 .gitea/scripts/check_test_results.py
|
|
|
|
- name: Build Debug APK
|
|
run: |
|
|
for i in 1 2 3; do
|
|
./gradlew assembleDebug && exit 0 || { echo "Attempt $i failed, retrying in 30s..."; sleep 30; }
|
|
done
|
|
exit 1
|
|
|
|
- name: Build Release APK
|
|
if: github.event_name != 'pull_request'
|
|
env:
|
|
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
|
|
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
|
|
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
|
|
run: |
|
|
for i in 1 2 3; do
|
|
./gradlew assembleRelease && exit 0 || { echo "Attempt $i failed, retrying in 30s..."; sleep 30; }
|
|
done
|
|
exit 1
|
|
|
|
- name: Verify release APK signature
|
|
if: github.event_name != 'pull_request'
|
|
run: python3 .gitea/scripts/signing.py verify presentation/build/outputs/apk/release/*.apk
|
|
|
|
- name: Create Release
|
|
if: github.event_name != 'pull_request'
|
|
uses: https://gitea.com/actions/gitea-release-action@v1
|
|
with:
|
|
tag_name: "v${{ env.APP_VERSION }}"
|
|
name: "Remotrix Build #${{ github.run_number }}"
|
|
body: "Automated release of Quik Fork with Remotrix integration. Generated from the latest push."
|
|
files: |
|
|
presentation/build/outputs/apk/debug/*.apk
|
|
presentation/build/outputs/apk/release/*.apk
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Remove temporary signing key
|
|
if: always()
|
|
run: python3 .gitea/scripts/signing.py cleanup
|