This commit is contained in:
1 parent
27a738d0e0
commit
f3012649f3
2 files changed
+47
-2
No files matched your search
@@ -2,10 +2,14 @@ name: Build Android APKs
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: debian
|
runs-on: debian
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -51,3 +55,44 @@ jobs:
|
|||||||
name: android-apks
|
name: android-apks
|
||||||
path: app/build/outputs/apk/**/*.apk
|
path: app/build/outputs/apk/**/*.apk
|
||||||
if-no-files-found: error
|
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"
|
||||||
@@ -18,6 +18,6 @@ Implementation plan: [PLAN.md](PLAN.md).
|
|||||||
|
|
||||||
## Gitea Actions
|
## 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-<run ID>-<attempt>` 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.
|
||||||
Reference in new issue
Block a user