Build an Android APK
Build Android Release / Build Android (push) Failing after 14s

This commit is contained in:
2026-05-15 23:51:30 +08:00
parent 49d417b817
commit a9738212cc
2 changed files with 74 additions and 112 deletions
+70 -109
View File
@@ -1,4 +1,4 @@
name: Build Release name: Build Android Release
on: on:
push: push:
@@ -12,6 +12,7 @@ on:
permissions: permissions:
actions: read actions: read
contents: read contents: read
releases: write
jobs: jobs:
android: android:
@@ -27,17 +28,14 @@ jobs:
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.GITEA_TOKEN }}
github-server-url: https://git.saont.net github-server-url: https://git.saont.net
- name: Set up Java - name: Check build environment
uses: actions/setup-java@v4 shell: bash
with: run: |
distribution: temurin set -euo pipefail
java-version: "17" df -h
java -version
- name: Set up Flutter flutter --version
uses: subosito/flutter-action@v2 flutter doctor -v
with:
channel: stable
cache: true
- name: Install dependencies - name: Install dependencies
run: flutter pub get run: flutter pub get
@@ -50,95 +48,67 @@ jobs:
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }} ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: | run: |
if [ -z "$ANDROID_KEYSTORE_BASE64" ] || [ -z "$ANDROID_STORE_PASSWORD" ] || [ -z "$ANDROID_KEY_ALIAS" ] || [ -z "$ANDROID_KEY_PASSWORD" ]; then set -euo pipefail
if [ -z "${ANDROID_KEYSTORE_BASE64:-}" ] || [ -z "${ANDROID_STORE_PASSWORD:-}" ] || [ -z "${ANDROID_KEY_ALIAS:-}" ] || [ -z "${ANDROID_KEY_PASSWORD:-}" ]; then
echo "Android signing secrets are required: ANDROID_KEYSTORE_BASE64, ANDROID_STORE_PASSWORD, ANDROID_KEY_ALIAS, ANDROID_KEY_PASSWORD" echo "Android signing secrets are required: ANDROID_KEYSTORE_BASE64, ANDROID_STORE_PASSWORD, ANDROID_KEY_ALIAS, ANDROID_KEY_PASSWORD"
exit 1 exit 1
fi fi
printf "%s" "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/app-release.jks printf "%s" "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/app-release.jks
cat > android/key.properties <<EOF {
storeFile=../app-release.jks printf "storeFile=../app-release.jks\n"
storePassword=$ANDROID_STORE_PASSWORD printf "storePassword=%s\n" "$ANDROID_STORE_PASSWORD"
keyAlias=$ANDROID_KEY_ALIAS printf "keyAlias=%s\n" "$ANDROID_KEY_ALIAS"
keyPassword=$ANDROID_KEY_PASSWORD printf "keyPassword=%s\n" "$ANDROID_KEY_PASSWORD"
EOF } > android/key.properties
- name: Build Android release APK - name: Build Android release APK
run: flutter build apk --release shell: bash
run: |
set -euo pipefail
pkg_dir="$PWD/dist/android"
if [ -d "$pkg_dir" ]; then
echo "Cleaning old Android build artifacts: $pkg_dir"
rm -rf "$pkg_dir"
fi
echo "Building Flutter Android release APK..."
flutter build apk -v --release
mkdir -p "$pkg_dir"
apk_path="$(find "$PWD/build/app/outputs" -type f -name '*release*.apk' | head -n 1)"
if [ -z "$apk_path" ]; then
echo "Release APK not found under build/app/outputs"
exit 1
fi
cp "$apk_path" "$pkg_dir/gongyun-app-release.apk"
ls -alh "$pkg_dir/gongyun-app-release.apk"
- name: Rename Android APK - name: Rename Android APK
run: cp build/app/outputs/flutter-apk/app-release.apk gongyun-app-release.apk shell: bash
run: |
set -euo pipefail
apk="dist/android/gongyun-app-release.apk"
if [ ! -f "$apk" ]; then
echo "Release APK was not found at $apk."
exit 1
fi
cp "$apk" gongyun-app-release.apk
ls -alh gongyun-app-release.apk
- name: Upload Android APK artifact - name: Upload Android APK artifact
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: android-release name: gongyun-app-release.apk
path: gongyun-app-release.apk path: gongyun-app-release.apk
# windows:
# name: Build Windows
# runs-on: windows-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# with:
# repository: gongyun/app
# ref: ${{ github.ref }}
# token: ${{ secrets.GITEA_TOKEN }}
# github-server-url: https://git.saont.net
#
# - name: Set up Flutter
# uses: subosito/flutter-action@v2
# with:
# channel: stable
# cache: true
#
# - name: Enable Windows desktop
# run: flutter config --enable-windows-desktop
#
# - name: Install dependencies
# run: flutter pub get
#
# - name: Build Windows release
# run: flutter build windows --release
#
# - name: Package Windows release
# shell: pwsh
# run: Compress-Archive -Path build\windows\x64\runner\Release\* -DestinationPath gongyun.zip -Force
#
# - name: Upload Windows artifact
# uses: actions/upload-artifact@v4
# with:
# name: windows-release
# path: gongyun.zip
release:
name: Publish Release
runs-on: ubuntu-latest
needs:
- android
# - windows
if: startsWith(github.ref, 'refs/tags/')
permissions:
actions: read
contents: read
releases: write
steps:
- name: Download Android artifact
uses: actions/download-artifact@v4
with:
name: android-release
path: dist
# - name: Download Windows artifact
# uses: actions/download-artifact@v4
# with:
# name: windows-release
# path: dist
- name: Publish Gitea release - name: Publish Gitea release
if: startsWith(github.ref, 'refs/tags/')
shell: bash shell: bash
env: env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
@@ -155,15 +125,15 @@ jobs:
exit 1 exit 1
fi fi
RELEASES_URL="$GITEA_API_URL/repos/$GITEA_OWNER/$GITEA_REPO/releases" releases_url="$GITEA_API_URL/repos/$GITEA_OWNER/$GITEA_REPO/releases"
RELEASE_BY_TAG_URL="$RELEASES_URL/tags/$TAG_NAME" release_by_tag_url="$releases_url/tags/$TAG_NAME"
status=$(curl -sS -o release.json -w "%{http_code}" \ status="$(curl -sS -o release.json -w "%{http_code}" \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
"$RELEASE_BY_TAG_URL") "$release_by_tag_url")"
if [ "$status" = "404" ]; then if [ "$status" = "404" ]; then
release_payload=$(python3 - <<'PY' release_payload="$(python3 - <<'PY'
import json import json
import os import os
@@ -177,14 +147,14 @@ jobs:
"prerelease": False, "prerelease": False,
})) }))
PY PY
) )"
status=$(curl -sS -o release.json -w "%{http_code}" \ status="$(curl -sS -o release.json -w "%{http_code}" \
-X POST \ -X POST \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$release_payload" \ -d "$release_payload" \
"$RELEASES_URL") "$releases_url")"
fi fi
if [ "$status" != "200" ] && [ "$status" != "201" ]; then if [ "$status" != "200" ] && [ "$status" != "201" ]; then
@@ -193,19 +163,19 @@ jobs:
exit 1 exit 1
fi fi
RELEASE_ID=$(python3 - <<'PY' release_id="$(python3 - <<'PY'
import json import json
with open("release.json", encoding="utf-8") as f: with open("release.json", encoding="utf-8") as f:
print(json.load(f)["id"]) print(json.load(f)["id"])
PY PY
) )"
ASSETS_URL="$RELEASES_URL/$RELEASE_ID/assets" assets_url="$releases_url/$release_id/assets"
curl -sS -f \ curl -sS -f \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
"$ASSETS_URL" \ "$assets_url" \
-o assets.json -o assets.json
python3 - <<'PY' > asset-ids-to-delete.txt python3 - <<'PY' > asset-ids-to-delete.txt
@@ -223,21 +193,12 @@ jobs:
curl -sS -f \ curl -sS -f \
-X DELETE \ -X DELETE \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
"$ASSETS_URL/$asset_id" "$assets_url/$asset_id"
fi fi
done < asset-ids-to-delete.txt done < asset-ids-to-delete.txt
upload_asset() {
local file="$1"
local name
name="$(basename "$file")"
curl -sS -f \ curl -sS -f \
-X POST \ -X POST \
-H "Authorization: token $GITEA_TOKEN" \ -H "Authorization: token $GITEA_TOKEN" \
-F "attachment=@$file" \ -F "attachment=@gongyun-app-release.apk" \
"$ASSETS_URL?name=$name" "$assets_url?name=gongyun-app-release.apk"
}
upload_asset dist/gongyun-app-release.apk
# upload_asset dist/gongyun.zip
+1
View File
@@ -31,6 +31,7 @@ DESIGN-copy.md
*.jsonl *.jsonl
example.dart example.dart
install.sh install.sh
.gitea/workflows/build.sh
dist/ dist/
# Local secrets/config that should not be published. # Local secrets/config that should not be published.