121 lines
4.6 KiB
YAML
121 lines
4.6 KiB
YAML
name: Build and Release APK
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
ANDROID_HOME: ${{ runner.tool_cache }}/android-sdk
|
|
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
|
|
- name: Set up JDK
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: temurin
|
|
java-version: 17
|
|
|
|
- name: Install Android SDK
|
|
run: |
|
|
if [ -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
|
|
echo "Android SDK already present in cache"
|
|
else
|
|
rm -rf "$ANDROID_HOME/cmdline-tools"
|
|
mkdir -p "$ANDROID_HOME/cmdline-tools"
|
|
wget -q https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/cmdtools.zip
|
|
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
|
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
|
fi
|
|
mkdir -p "$ANDROID_HOME/licenses"
|
|
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
|
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
|
echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
|
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \
|
|
"platform-tools" \
|
|
"platforms;android-36" \
|
|
"build-tools;36.0.0" \
|
|
"ndk;27.1.12297006"
|
|
mkdir -p carry-your-live/android/app
|
|
echo "sdk.dir=$ANDROID_HOME" > carry-your-live/android/app/local.properties
|
|
|
|
- name: Install JS dependencies
|
|
working-directory: carry-your-live
|
|
run: |
|
|
for i in {1..3}; do
|
|
npm ci && break || sleep 10
|
|
done
|
|
|
|
- name: Generate debug keystore (signs the release APK)
|
|
run: |
|
|
mkdir -p carry-your-live/android/app
|
|
rm -f carry-your-live/android/app/debug.keystore
|
|
keytool -genkeypair -v \
|
|
-keystore carry-your-live/android/app/debug.keystore \
|
|
-alias androiddebugkey -storepass android -keypass android \
|
|
-keyalg RSA -keysize 2048 -validity 10000 \
|
|
-dname "CN=Android Debug,O=Android,C=US"
|
|
|
|
- name: Build release APK
|
|
run: |
|
|
cd carry-your-live/android
|
|
./gradlew assembleRelease
|
|
|
|
- name: Find APK
|
|
id: find-apk
|
|
run: |
|
|
APK_PATH=$(find carry-your-live/android/app/build/outputs -name "*.apk" -type f | head -n 1)
|
|
echo "apk_path=$APK_PATH" >> "$GITHUB_OUTPUT"
|
|
echo "Found APK at: $APK_PATH"
|
|
|
|
- name: Create Gitea Release and Upload APK
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
|
REPO_OWNER="${GITHUB_REPOSITORY%/*}"
|
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
|
APK_PATH="${{ steps.find-apk.outputs.apk_path }}"
|
|
APK_NAME="carry-your-live-${TAG_NAME}.apk"
|
|
|
|
# Create release using Gitea API
|
|
RESPONSE=$(curl -s -X POST "https://techmos.gitea.org/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"${TAG_NAME}\",
|
|
\"name\": \"${TAG_NAME}\",
|
|
\"body\": \"Automated release for ${TAG_NAME}\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}")
|
|
|
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
|
|
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
|
echo "Release might already exist, fetching existing release..."
|
|
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
|
|
"https://techmos.gitea.org/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${TAG_NAME}" | jq -r '.id')
|
|
fi
|
|
|
|
# Upload APK as attachment
|
|
curl -s -X POST "https://techmos.gitea.org/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${APK_PATH};filename=${APK_NAME}"
|
|
|
|
echo "APK uploaded to release ${TAG_NAME}" |