From f3012649f327703465ab9c059f73fd3969b438f8 Mon Sep 17 00:00:00 2001 From: Alvin Date: Fri, 13 Nov 2026 23:15:53 +0100 Subject: [PATCH] Publish APK release on every branch push --- .gitea/workflows/android-build.yml | 45 ++++++++++++++++++++++++++++++ README.md | 4 +-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/android-build.yml b/.gitea/workflows/android-build.yml index cb0c4e1..e37381d 100644 --- a/.gitea/workflows/android-build.yml +++ b/.gitea/workflows/android-build.yml @@ -2,10 +2,14 @@ name: Build Android APKs on: push: + branches: + - '**' jobs: build: runs-on: debian + permissions: + contents: write steps: - name: Check out repository uses: actions/checkout@v4 @@ -51,3 +55,44 @@ jobs: name: android-apks path: app/build/outputs/apk/**/*.apk if-no-files-found: error + + - name: Create Gitea release with APK + shell: bash + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + SERVER_URL: ${{ gitea.server_url }} + REPOSITORY: ${{ gitea.repository }} + COMMIT_SHA: ${{ gitea.sha }} + RUN_ID: ${{ gitea.run_id }} + RUN_ATTEMPT: ${{ gitea.run_attempt }} + run: | + set -euo pipefail + : "${GITEA_TOKEN:?Gitea job token is unavailable}" + tag="build-${RUN_ID}-${RUN_ATTEMPT}" + release_apk=app/build/outputs/apk/release/app-release.apk + if [[ -f "$release_apk" ]]; then + apk="$release_apk" + asset_name=smb-explorer-release.apk + build_type='Signed release APK' + else + apk=app/build/outputs/apk/debug/app-debug.apk + asset_name=smb-explorer-debug.apk + build_type='Debug APK (installable test build; configure signing secrets for a signed release)' + fi + test -s "$apk" + + api="${SERVER_URL%/}/api/v1/repos/${REPOSITORY}/releases" + payload="$(mktemp)" + response="$(mktemp)" + trap 'rm -f "$payload" "$response"' EXIT + TAG="$tag" BUILD_TYPE="$build_type" python3 -c 'import json, os, sys; json.dump({"tag_name": os.environ["TAG"], "target_commitish": os.environ["COMMIT_SHA"], "name": os.environ["TAG"], "body": os.environ["BUILD_TYPE"] + "\nCommit: " + os.environ["COMMIT_SHA"], "draft": False, "prerelease": True}, sys.stdout)' > "$payload" + curl --fail-with-body --silent --show-error \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H 'Content-Type: application/json' \ + --data-binary "@$payload" "$api" > "$response" + release_id="$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["id"])' "$response")" + curl --fail-with-body --silent --show-error \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -F "attachment=@${apk};filename=${asset_name}" \ + "$api/$release_id/assets" > /dev/null + echo "Published $tag with $asset_name" diff --git a/README.md b/README.md index d774cf5..c89572f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,6 @@ Implementation plan: [PLAN.md](PLAN.md). ## Gitea Actions -Every push runs `.gitea/workflows/android-build.yml` on the runner labelled `debian`. The `android-apks` artifact on the Actions run contains a debug APK for testing and an unsigned release APK by default. The workflow installs JDK 17 and the required Android SDK packages, so the runner needs outbound access to the action repositories, Gradle, Maven, and Google Android downloads. +Every branch push runs `.gitea/workflows/android-build.yml` on the runner labelled `debian`. It creates a Gitea pre-release tagged `build--` with an installable APK attached. The `android-apks` artifact on the Actions run also contains the debug APK and an unsigned release APK by default. The workflow installs JDK 17 and the required Android SDK packages, so the runner needs outbound access to the action repositories, Gradle, Maven, and Google Android downloads. Repository Actions permissions must allow the job token to write releases. -For an installable release APK, add these repository Actions secrets: `ANDROID_KEYSTORE_BASE64` (base64 encoding of your release `.jks` file), `ANDROID_KEYSTORE_PASSWORD`, `ANDROID_KEY_ALIAS`, and `ANDROID_KEY_PASSWORD`. When all are present, the workflow signs the release build. Keep the keystore and its passwords backed up outside the repository; future updates need the same signing key. Never commit the keystore or passwords. +For a signed release APK, add these repository Actions secrets: `ANDROID_KEYSTORE_BASE64` (base64 encoding of your release `.jks` file), `ANDROID_KEYSTORE_PASSWORD`, `ANDROID_KEY_ALIAS`, and `ANDROID_KEY_PASSWORD`. When all are present, the workflow attaches the signed release APK. Without them, it attaches the installable debug APK instead. Keep the keystore and its passwords backed up outside the repository; future updates need the same signing key. Never commit the keystore or passwords.