237 lines
8.3 KiB
YAML
237 lines
8.3 KiB
YAML
name: Build and Release Android
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
NODE_VERSION: '20'
|
|
JAVA_VERSION: '17'
|
|
ANDROID_HOME: ${{ runner.tool_cache }}/android-sdk
|
|
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk
|
|
GITEA_SERVER_URL: "https://techmos.gitea.org"
|
|
|
|
jobs:
|
|
build:
|
|
name: Build Android
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 45
|
|
permissions:
|
|
contents: read
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
cache: 'npm'
|
|
cache-dependency-path: carry-your-live/package-lock.json
|
|
|
|
- name: Setup Java
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: ${{ env.JAVA_VERSION }}
|
|
cache: 'gradle'
|
|
cache-dependency-path: carry-your-live/android/gradle/wrapper/gradle-wrapper.properties
|
|
|
|
- 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 dependencies
|
|
working-directory: carry-your-live
|
|
run: |
|
|
for i in {1..3}; do
|
|
npm ci && break || sleep 10
|
|
done
|
|
|
|
- name: Prebuild Android
|
|
working-directory: carry-your-live
|
|
run: npx expo prebuild --platform android --clean
|
|
|
|
- name: Configure Release Signing
|
|
if: env.KEYSTORE_BASE64 != ''
|
|
working-directory: carry-your-live/android/app
|
|
run: |
|
|
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > release.keystore
|
|
cat > ../release-signing.properties <<EOF
|
|
storeFile=release.keystore
|
|
storePassword=${{ secrets.KEYSTORE_PASSWORD }}
|
|
keyAlias=${{ secrets.KEY_ALIAS }}
|
|
keyPassword=${{ secrets.KEY_PASSWORD }}
|
|
EOF
|
|
|
|
- name: Build Release APK
|
|
working-directory: carry-your-live/android
|
|
run: |
|
|
if [ -f "../release-signing.properties" ]; then
|
|
./gradlew assembleRelease -PreleaseSigningProperties=../release-signing.properties --no-daemon
|
|
else
|
|
./gradlew assembleRelease --no-daemon
|
|
fi
|
|
|
|
- name: Build Release Bundle (AAB)
|
|
working-directory: carry-your-live/android
|
|
run: |
|
|
if [ -f "../release-signing.properties" ]; then
|
|
./gradlew bundleRelease -PreleaseSigningProperties=../release-signing.properties --no-daemon
|
|
else
|
|
./gradlew bundleRelease --no-daemon
|
|
fi
|
|
|
|
- name: Run Tests
|
|
working-directory: carry-your-live/android
|
|
run: ./gradlew test --no-daemon
|
|
|
|
- name: Run Lint
|
|
working-directory: carry-your-live/android
|
|
run: ./gradlew lint --no-daemon
|
|
|
|
- name: Find Release APK
|
|
id: find-release-apk
|
|
run: |
|
|
APK_PATH=$(find carry-your-live/android/app/build/outputs -name "*release*.apk" -type f | head -n 1)
|
|
echo "apk_path=$APK_PATH" >> "$GITHUB_OUTPUT"
|
|
echo "Found Release APK at: $APK_PATH"
|
|
|
|
- name: Find Release Bundle (AAB)
|
|
id: find-release-aab
|
|
run: |
|
|
AAB_PATH=$(find carry-your-live/android/app/build/outputs -name "*release*.aab" -type f | head -n 1)
|
|
echo "aab_path=$AAB_PATH" >> "$GITHUB_OUTPUT"
|
|
echo "Found Release AAB at: $AAB_PATH"
|
|
|
|
- name: Upload Build Artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: android-release-build
|
|
path: |
|
|
${{ steps.find-release-apk.outputs.apk_path }}
|
|
${{ steps.find-release-aab.outputs.aab_path }}
|
|
retention-days: 90
|
|
|
|
- name: Upload Test Reports
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: android-test-reports
|
|
path: carry-your-live/android/app/build/reports/tests/
|
|
retention-days: 30
|
|
|
|
- name: Upload Lint Reports
|
|
if: always()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: android-lint-reports
|
|
path: carry-your-live/android/app/build/reports/lint-results*.html
|
|
retention-days: 30
|
|
|
|
release:
|
|
name: Create Gitea Release
|
|
needs: build
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Download Build Artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: android-release-build
|
|
path: artifacts
|
|
|
|
- name: Create Gitea Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
|
REPO_OWNER="${GITHUB_REPOSITORY%/*}"
|
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
|
|
|
# Detect Gitea server URL
|
|
GITEA_URL="${GITEA_SERVER_URL:-https://techmos.gitea.org}"
|
|
|
|
# Create release
|
|
RESPONSE=$(curl -s -X POST "${GITEA_URL}/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}" \
|
|
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${TAG_NAME}" | jq -r '.id')
|
|
fi
|
|
|
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create or find release"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Release ID: $RELEASE_ID"
|
|
echo "release_id=$RELEASE_ID" >> "$GITHUB_OUTPUT"
|
|
id: create-release
|
|
|
|
- name: Upload APK to Release
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
run: |
|
|
GITEA_URL="${GITEA_URL:-https://techmos.gitea.org}"
|
|
REPO_OWNER="${GITHUB_REPOSITORY%/*}"
|
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
|
RELEASE_ID="${{ steps.create-release.outputs.release_id }}"
|
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
|
|
|
for file in artifacts/*; do
|
|
if [[ "$file" == *.apk ]]; then
|
|
FILENAME="carry-your-live-${TAG_NAME}.apk"
|
|
elif [[ "$file" == *.aab ]]; then
|
|
FILENAME="carry-your-live-${TAG_NAME}.aab"
|
|
else
|
|
continue
|
|
fi
|
|
|
|
echo "Uploading $file as $FILENAME..."
|
|
curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-F "attachment=@${file};filename=${FILENAME}"
|
|
|
|
echo "Uploaded $FILENAME"
|
|
done |