From a9738212cc0781edf52d58d68e092d736a95f9d3 Mon Sep 17 00:00:00 2001 From: gongyun Date: Fri, 15 May 2026 23:51:30 +0800 Subject: [PATCH] Build an Android APK --- .gitea/workflows/build.yml | 185 +++++++++++++++---------------------- .gitignore | 1 + 2 files changed, 74 insertions(+), 112 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 7740b56..d708e39 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build Release +name: Build Android Release on: push: @@ -12,6 +12,7 @@ on: permissions: actions: read contents: read + releases: write jobs: android: @@ -27,17 +28,14 @@ jobs: token: ${{ secrets.GITEA_TOKEN }} github-server-url: https://git.saont.net - - name: Set up Java - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: "17" - - - name: Set up Flutter - uses: subosito/flutter-action@v2 - with: - channel: stable - cache: true + - name: Check build environment + shell: bash + run: | + set -euo pipefail + df -h + java -version + flutter --version + flutter doctor -v - name: Install dependencies run: flutter pub get @@ -50,95 +48,67 @@ jobs: ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }} 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" exit 1 fi printf "%s" "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/app-release.jks - cat > android/key.properties < android/key.properties - 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 - 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 uses: actions/upload-artifact@v4 with: - name: android-release + name: 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 + if: startsWith(github.ref, 'refs/tags/') shell: bash env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} @@ -155,15 +125,15 @@ jobs: exit 1 fi - RELEASES_URL="$GITEA_API_URL/repos/$GITEA_OWNER/$GITEA_REPO/releases" - RELEASE_BY_TAG_URL="$RELEASES_URL/tags/$TAG_NAME" + releases_url="$GITEA_API_URL/repos/$GITEA_OWNER/$GITEA_REPO/releases" + 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" \ - "$RELEASE_BY_TAG_URL") + "$release_by_tag_url")" if [ "$status" = "404" ]; then - release_payload=$(python3 - <<'PY' + release_payload="$(python3 - <<'PY' import json import os @@ -177,14 +147,14 @@ jobs: "prerelease": False, })) PY - ) + )" - status=$(curl -sS -o release.json -w "%{http_code}" \ + status="$(curl -sS -o release.json -w "%{http_code}" \ -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "$release_payload" \ - "$RELEASES_URL") + "$releases_url")" fi if [ "$status" != "200" ] && [ "$status" != "201" ]; then @@ -193,19 +163,19 @@ jobs: exit 1 fi - RELEASE_ID=$(python3 - <<'PY' + release_id="$(python3 - <<'PY' import json with open("release.json", encoding="utf-8") as f: print(json.load(f)["id"]) PY - ) + )" - ASSETS_URL="$RELEASES_URL/$RELEASE_ID/assets" + assets_url="$releases_url/$release_id/assets" curl -sS -f \ -H "Authorization: token $GITEA_TOKEN" \ - "$ASSETS_URL" \ + "$assets_url" \ -o assets.json python3 - <<'PY' > asset-ids-to-delete.txt @@ -223,21 +193,12 @@ jobs: curl -sS -f \ -X DELETE \ -H "Authorization: token $GITEA_TOKEN" \ - "$ASSETS_URL/$asset_id" + "$assets_url/$asset_id" fi done < asset-ids-to-delete.txt - upload_asset() { - local file="$1" - local name - name="$(basename "$file")" - - curl -sS -f \ - -X POST \ - -H "Authorization: token $GITEA_TOKEN" \ - -F "attachment=@$file" \ - "$ASSETS_URL?name=$name" - } - - upload_asset dist/gongyun-app-release.apk - # upload_asset dist/gongyun.zip + curl -sS -f \ + -X POST \ + -H "Authorization: token $GITEA_TOKEN" \ + -F "attachment=@gongyun-app-release.apk" \ + "$assets_url?name=gongyun-app-release.apk" diff --git a/.gitignore b/.gitignore index 4593f89..03ade25 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ DESIGN-copy.md *.jsonl example.dart install.sh +.gitea/workflows/build.sh dist/ # Local secrets/config that should not be published.