feat: Update build workflow to handle APK release and upload to Gitea
Build Android APK / build-apk (push) Successful in 13m55s
Build Android APK / build-apk (push) Successful in 13m55s
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
name: Build Android APK
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
build-apk:
|
||||
@@ -14,6 +13,7 @@ jobs:
|
||||
BASE_URL: ${{ secrets.BASE_URL }}
|
||||
GOOGLE_SERVER_CLIENT_ID: ${{ secrets.GOOGLE_SERVER_CLIENT_ID }}
|
||||
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
|
||||
TOKEN: ${{ secrets.TOKEN }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@@ -55,6 +55,9 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: flutter pub get
|
||||
|
||||
- name: Install release tooling
|
||||
run: sudo apt-get update && sudo apt-get install -y jq
|
||||
|
||||
- name: Build release APK
|
||||
run: |
|
||||
BASE_URL_VALUE="${BASE_URL:-http://127.0.0.1:8000}"
|
||||
@@ -74,9 +77,49 @@ jobs:
|
||||
|
||||
"${FLUTTER_CMD[@]}"
|
||||
|
||||
- name: Upload APK artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: reader-app-release-apk
|
||||
path: build/app/outputs/flutter-apk/app-release.apk
|
||||
if-no-files-found: error
|
||||
- name: Create or update Gitea release and upload APK
|
||||
run: |
|
||||
if [ -z "${TOKEN}" ]; then
|
||||
echo "Missing required secret: TOKEN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
APK_PATH="build/app/outputs/flutter-apk/app-release.apk"
|
||||
if [ ! -f "$APK_PATH" ]; then
|
||||
echo "APK not found at $APK_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OWNER_REPO="${GITHUB_REPOSITORY}"
|
||||
OWNER="${OWNER_REPO%%/*}"
|
||||
REPO="${OWNER_REPO##*/}"
|
||||
TAG="${GITHUB_REF_NAME}"
|
||||
API_BASE="${GITHUB_SERVER_URL}/api/v1"
|
||||
|
||||
RELEASE_JSON=$(curl -sS -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${API_BASE}/repos/${OWNER}/${REPO}/releases" \
|
||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"draft\":false,\"prerelease\":false}" \
|
||||
|| true)
|
||||
|
||||
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id // empty')
|
||||
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
# Fallback: release may already exist for the tag
|
||||
RELEASE_JSON=$(curl -sS \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
"${API_BASE}/repos/${OWNER}/${REPO}/releases/tags/${TAG}")
|
||||
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id // empty')
|
||||
fi
|
||||
|
||||
if [ -z "$RELEASE_ID" ]; then
|
||||
echo "Could not resolve release ID for tag ${TAG}"
|
||||
echo "$RELEASE_JSON"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
curl -sS -X POST \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-F "attachment=@${APK_PATH}" \
|
||||
"${API_BASE}/repos/${OWNER}/${REPO}/releases/${RELEASE_ID}/assets?name=reader-app-${TAG}.apk"
|
||||
|
||||
Reference in New Issue
Block a user