mirror of
https://github.com/Dasemu/NavFrame.git
synced 2026-11-26 15:26:05 +00:00
ci: publish signed main releases and development debug artifacts
This commit is contained in:
1 parent
4b586cc3e2
commit
e96e905b09
4 files changed
+205
-6
No files matched your search
@@ -1,13 +1,15 @@
|
|||||||
name: Android build and checks
|
name: Android build and checks
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main, development]
|
||||||
pull_request:
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
# Grouping by branch would drop pending builds during rapid pushes.
|
||||||
concurrency:
|
concurrency:
|
||||||
group: android-${{ github.workflow }}-${{ github.ref }}
|
group: android-${{ github.workflow }}-${{ github.run_id }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: false
|
||||||
jobs:
|
jobs:
|
||||||
verify:
|
verify:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -23,15 +25,133 @@ jobs:
|
|||||||
run: sdkmanager "platforms;android-36" "build-tools;35.0.0"
|
run: sdkmanager "platforms;android-36" "build-tools;35.0.0"
|
||||||
- uses: gradle/actions/setup-gradle@v4
|
- uses: gradle/actions/setup-gradle@v4
|
||||||
- name: Build, unit tests and lint
|
- name: Build, unit tests and lint
|
||||||
run: ./gradlew --no-daemon :app:assembleDebug :app:testDebugUnitTest :app:lintDebug :core:test :navilite:testDebugUnitTest
|
run: ./gradlew --no-daemon --max-workers=4 :app:assembleDebug :app:testDebugUnitTest :app:lintDebug :core:test :navilite:testDebugUnitTest
|
||||||
- name: Preserve check reports
|
- name: Preserve check reports
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: android-check-reports
|
name: android-check-reports-${{ github.run_id }}
|
||||||
path: |
|
path: |
|
||||||
app/build/reports/
|
app/build/reports/
|
||||||
core/build/reports/
|
core/build/reports/
|
||||||
navilite/build/reports/
|
navilite/build/reports/
|
||||||
if-no-files-found: ignore
|
if-no-files-found: ignore
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
|
- name: Upload development debug APK
|
||||||
|
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/development'
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: navframe-debug-${{ github.sha }}
|
||||||
|
path: app/build/outputs/apk/debug/app-debug.apk
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 14
|
||||||
|
release:
|
||||||
|
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
|
||||||
|
needs: verify
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 45
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: temurin
|
||||||
|
java-version: '17'
|
||||||
|
- uses: android-actions/setup-android@v4
|
||||||
|
- name: Install Android compile SDK
|
||||||
|
run: sdkmanager "platforms;android-36" "build-tools;35.0.0"
|
||||||
|
- uses: gradle/actions/setup-gradle@v4
|
||||||
|
- name: Restore production signing key
|
||||||
|
env:
|
||||||
|
ANDROID_RELEASE_KEYSTORE_BASE64: ${{ secrets.ANDROID_RELEASE_KEYSTORE_BASE64 }}
|
||||||
|
ANDROID_RELEASE_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD }}
|
||||||
|
ANDROID_RELEASE_KEY_ALIAS: ${{ secrets.ANDROID_RELEASE_KEY_ALIAS }}
|
||||||
|
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
for name in ANDROID_RELEASE_KEYSTORE_BASE64 ANDROID_RELEASE_KEYSTORE_PASSWORD ANDROID_RELEASE_KEY_ALIAS ANDROID_RELEASE_KEY_PASSWORD; do
|
||||||
|
if [[ -z "${!name}" ]]; then
|
||||||
|
echo "::error::Missing production signing secret: $name (see docs/ANDROID_RELEASES.md)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
umask 077
|
||||||
|
printf '%s' "$ANDROID_RELEASE_KEYSTORE_BASE64" | base64 --decode > "$RUNNER_TEMP/navframe-release.p12"
|
||||||
|
echo "NAVFRAME_KEYSTORE_PATH=$RUNNER_TEMP/navframe-release.p12" >> "$GITHUB_ENV"
|
||||||
|
- name: Build signed production APK and lint
|
||||||
|
env:
|
||||||
|
NAVFRAME_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEYSTORE_PASSWORD }}
|
||||||
|
NAVFRAME_KEY_ALIAS: ${{ secrets.ANDROID_RELEASE_KEY_ALIAS }}
|
||||||
|
NAVFRAME_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# Preserve numeric versionName for the diagnostic history schema.
|
||||||
|
VERSION_CODE=$((1000000 + GITHUB_RUN_NUMBER))
|
||||||
|
./gradlew --no-daemon --max-workers=4 :app:assembleRelease :app:lintRelease -PnavframeVersionCode="$VERSION_CODE"
|
||||||
|
- name: Verify signature and prepare release files
|
||||||
|
id: package
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
SDK_ROOT="${ANDROID_SDK_ROOT:-$ANDROID_HOME}"
|
||||||
|
"$SDK_ROOT/build-tools/35.0.0/apksigner" verify --verbose app/build/outputs/apk/release/app-release.apk
|
||||||
|
python3 - <<'PY'
|
||||||
|
import json, os, pathlib, re, shutil, hashlib
|
||||||
|
metadata = json.loads(pathlib.Path('app/build/outputs/apk/release/output-metadata.json').read_text())
|
||||||
|
item = metadata['elements'][0]
|
||||||
|
version = item['versionName']
|
||||||
|
if not re.fullmatch(r'[0-9]+(?:\.[0-9]+){1,3}', version):
|
||||||
|
raise SystemExit('Unexpected versionName')
|
||||||
|
if item['versionCode'] != 1000000 + int(os.environ['GITHUB_RUN_NUMBER']):
|
||||||
|
raise SystemExit('Unexpected production versionCode')
|
||||||
|
tag = f"app-v{version}-build-{os.environ['GITHUB_RUN_NUMBER']}-{os.environ['GITHUB_SHA'][:12]}"
|
||||||
|
folder = pathlib.Path(os.environ['RUNNER_TEMP']) / 'navframe-release-output'; folder.mkdir()
|
||||||
|
apk = folder / f'navframe-{tag}.apk'
|
||||||
|
shutil.copyfile('app/build/outputs/apk/release/app-release.apk', apk)
|
||||||
|
(folder / 'SHA256SUMS.txt').write_text(f'{hashlib.sha256(apk.read_bytes()).hexdigest()} {apk.name}\n')
|
||||||
|
(folder / 'build-info.json').write_text(json.dumps({'versionName': version, 'versionCode': item['versionCode'], 'commit': os.environ['GITHUB_SHA'], 'runNumber': int(os.environ['GITHUB_RUN_NUMBER'])}, indent=2) + '\n')
|
||||||
|
with open(os.environ['GITHUB_OUTPUT'], 'a') as out:
|
||||||
|
out.write(f'tag={tag}\nversion={version}\ndirectory={folder}\n')
|
||||||
|
PY
|
||||||
|
- name: Publish production release
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
RELEASE_TAG: ${{ steps.package.outputs.tag }}
|
||||||
|
VERSION_NAME: ${{ steps.package.outputs.version }}
|
||||||
|
RELEASE_DIRECTORY: ${{ steps.package.outputs.directory }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# A rerun may finish its own draft but cannot replace published assets.
|
||||||
|
if gh release view "$RELEASE_TAG" --json isDraft,targetCommitish > "$RUNNER_TEMP/existing-release.json" 2>/dev/null; then
|
||||||
|
python3 - <<'PY'
|
||||||
|
import json, os, pathlib
|
||||||
|
release = json.loads(pathlib.Path(os.environ['RUNNER_TEMP'], 'existing-release.json').read_text())
|
||||||
|
if release['targetCommitish'] != os.environ['GITHUB_SHA']:
|
||||||
|
raise SystemExit('Existing release targets another commit')
|
||||||
|
PY
|
||||||
|
if [[ "$(python3 -c 'import json,os,pathlib; print(str(json.loads(pathlib.Path(os.environ["RUNNER_TEMP"], "existing-release.json").read_text())["isDraft"]).lower())')" == false ]]; then
|
||||||
|
echo "Production release already published; preserving its assets."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
gh release upload "$RELEASE_TAG" "$RELEASE_DIRECTORY"/* --clobber
|
||||||
|
else
|
||||||
|
printf 'Signed production APK for commit %s.\n\nVersion code: %s. Checksums and build metadata are attached.\n' "$GITHUB_SHA" "$((1000000 + GITHUB_RUN_NUMBER))" > "$RUNNER_TEMP/release-notes.md"
|
||||||
|
gh release create "$RELEASE_TAG" "$RELEASE_DIRECTORY"/* --draft --target "$GITHUB_SHA" --title "NavFrame $VERSION_NAME · build $GITHUB_RUN_NUMBER" --notes-file "$RUNNER_TEMP/release-notes.md"
|
||||||
|
fi
|
||||||
|
# An older build finishing late cannot replace the current main release as latest.
|
||||||
|
LATEST=false
|
||||||
|
if [[ "$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha')" == "$GITHUB_SHA" ]]; then
|
||||||
|
LATEST=true
|
||||||
|
fi
|
||||||
|
gh release edit "$RELEASE_TAG" --draft=false --latest="$LATEST"
|
||||||
|
- name: Preserve production lint report
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-release-lint-${{ github.run_id }}
|
||||||
|
path: app/build/reports/lint-results-release.*
|
||||||
|
if-no-files-found: ignore
|
||||||
|
retention-days: 7
|
||||||
|
- name: Remove temporary signing key
|
||||||
|
if: always()
|
||||||
|
run: rm -f "$RUNNER_TEMP/navframe-release.p12"
|
||||||
@@ -31,6 +31,10 @@ Set up `local.properties` for your own Android SDK when needed. It is excluded f
|
|||||||
|
|
||||||
Version 0.13.2 automatically saves the latest 100 TFT map failures and recoveries on the phone. After a reboot or empty battery, open **Information and licenses → TFT map diagnosis → Share** to export the saved history. It excludes coordinates, URLs, route/search text, and Bluetooth identifiers. See [Persistent TFT diagnostics](docs/TFT_DIAGNOSTICS.md) for retention and limitations.
|
Version 0.13.2 automatically saves the latest 100 TFT map failures and recoveries on the phone. After a reboot or empty battery, open **Information and licenses → TFT map diagnosis → Share** to export the saved history. It excludes coordinates, URLs, route/search text, and Bluetooth identifiers. See [Persistent TFT diagnostics](docs/TFT_DIAGNOSTICS.md) for retention and limitations.
|
||||||
|
|
||||||
|
## Automated builds
|
||||||
|
|
||||||
|
GitHub Actions uploads a debug APK artifact for pushes to `development`. Pushes to `main` publish a signed production APK release after build, tests, lint and signature checks pass. Production signing requires the repository secrets described in [Android builds and releases](docs/ANDROID_RELEASES.md). Pull requests run checks without publishing releases.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
- [Documentation index](docs/README.md)
|
- [Documentation index](docs/README.md)
|
||||||
|
|||||||
+23
-1
@@ -1,4 +1,12 @@
|
|||||||
plugins { id("com.android.application"); kotlin("android") }
|
plugins { id("com.android.application"); kotlin("android") }
|
||||||
|
val releaseSigningNames = listOf("NAVFRAME_KEYSTORE_PATH", "NAVFRAME_KEYSTORE_PASSWORD", "NAVFRAME_KEY_ALIAS", "NAVFRAME_KEY_PASSWORD")
|
||||||
|
val releaseSigning = releaseSigningNames.associateWith { System.getenv(it).orEmpty() }
|
||||||
|
val hasReleaseSigning = releaseSigning.values.all { it.isNotBlank() }
|
||||||
|
if (releaseSigning.values.any { it.isNotBlank() } && !hasReleaseSigning) {
|
||||||
|
throw GradleException("Incomplete release signing configuration. Required variables: ${releaseSigningNames.joinToString()}")
|
||||||
|
}
|
||||||
|
val navframeVersionCode = providers.gradleProperty("navframeVersionCode").orElse("18").get().toInt()
|
||||||
|
require(navframeVersionCode in 1..2_100_000_000) { "Android versionCode must be between 1 and 2100000000" }
|
||||||
android {
|
android {
|
||||||
namespace = "dev.navframe.app"
|
namespace = "dev.navframe.app"
|
||||||
compileSdk = 36
|
compileSdk = 36
|
||||||
@@ -7,12 +15,26 @@ android {
|
|||||||
applicationId = "dev.navframe.app"
|
applicationId = "dev.navframe.app"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 18
|
versionCode = navframeVersionCode
|
||||||
versionName = "0.13.2"
|
versionName = "0.13.2"
|
||||||
}
|
}
|
||||||
|
if (hasReleaseSigning) {
|
||||||
|
signingConfigs.create("production") {
|
||||||
|
storeFile = file(releaseSigning.getValue("NAVFRAME_KEYSTORE_PATH"))
|
||||||
|
storePassword = releaseSigning.getValue("NAVFRAME_KEYSTORE_PASSWORD")
|
||||||
|
keyAlias = releaseSigning.getValue("NAVFRAME_KEY_ALIAS")
|
||||||
|
keyPassword = releaseSigning.getValue("NAVFRAME_KEY_PASSWORD")
|
||||||
|
}
|
||||||
|
buildTypes.getByName("release").signingConfig = signingConfigs.getByName("production")
|
||||||
|
}
|
||||||
testOptions { unitTests.isIncludeAndroidResources = true }
|
testOptions { unitTests.isIncludeAndroidResources = true }
|
||||||
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
|
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
|
||||||
}
|
}
|
||||||
|
gradle.taskGraph.whenReady {
|
||||||
|
if (!hasReleaseSigning && allTasks.any { it.path in setOf(":app:assembleRelease", ":app:bundleRelease", ":app:packageRelease") }) {
|
||||||
|
throw GradleException("Production builds require release signing. Configure ${releaseSigningNames.joinToString()}.")
|
||||||
|
}
|
||||||
|
}
|
||||||
kotlin { jvmToolchain(17) }
|
kotlin { jvmToolchain(17) }
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# Android builds and automatic releases
|
||||||
|
|
||||||
|
The Android workflow verifies the debug build, unit tests and lint for pull requests and pushes to `main` or `development`. A manual Actions run is also available. Pull requests never receive production signing secrets or publish releases.
|
||||||
|
|
||||||
|
## Branch outputs
|
||||||
|
|
||||||
|
| Event | Output after checks pass |
|
||||||
|
| --- | --- |
|
||||||
|
| Push to `development` | `app-debug.apk` uploaded as `navframe-debug-COMMIT_SHA`, retained for 14 days. |
|
||||||
|
| Push to `main` | Signed production/release APK, `SHA256SUMS.txt` and `build-info.json` published in a new GitHub Release. |
|
||||||
|
| Pull request | Build/test/lint reports only; no release publication. |
|
||||||
|
| Manual run | Same branch behavior as a push when run on `main` or `development`. |
|
||||||
|
|
||||||
|
Each push is a separate run, including rapid successive pushes; older builds are not cancelled or discarded. A push containing several commits builds its final commit. Release publication requires successful checks, release compilation/lint, and APK signature verification. Tags include versionName, workflow run number and commit SHA, for example `app-v0.13.2-build-42-0123456789ab`. APK versionCode is `1000000 + github.run_number`, so successive production builds can update each other without changing the human-readable versionName for every commit. Preserve the workflow's run-number history if reorganizing the workflow.
|
||||||
|
|
||||||
|
An older build finishing late does not replace the current main build as `latest`. Rerunning a run can finish its own draft release, but preserves an already published release and its assets. Offline-region release/catalog workflows are separate.
|
||||||
|
|
||||||
|
## Production signing secrets
|
||||||
|
|
||||||
|
Create these repository Actions secrets under **Settings → Secrets and variables → Actions**:
|
||||||
|
|
||||||
|
| Secret | Contents |
|
||||||
|
| --- | --- |
|
||||||
|
| `ANDROID_RELEASE_KEYSTORE_BASE64` | Base64-encoded production `.p12`/keystore file. |
|
||||||
|
| `ANDROID_RELEASE_KEYSTORE_PASSWORD` | Keystore password. |
|
||||||
|
| `ANDROID_RELEASE_KEY_ALIAS` | Alias of the production signing key. |
|
||||||
|
| `ANDROID_RELEASE_KEY_PASSWORD` | Key password; for a PKCS12 key it normally matches the keystore password. |
|
||||||
|
|
||||||
|
Use a permanent production key and keep a secure offline backup of the keystore and passwords. The newly prepared NavFrame key uses RSA-4096, PKCS12, alias `navframe-release`, and a 10,000-day certificate validity. Its private backup is supplied separately from the repository; neither keys nor password values belong in Git, Actions artifacts, release assets or this document. A replacement key normally cannot update an app signed by the old key. A production key also cannot update an earlier APK signed with a debug key; preserve/export app data before any uninstall required by a signature mismatch.
|
||||||
|
|
||||||
|
The workflow restores the keystore to a private temporary runner file, checks that all four secrets exist, builds with environment-only signing parameters, verifies the APK signature, and removes the temporary key even if the job fails. The verification job remains read-only; only the guarded main release job has `contents: write`. The normal repository `GITHUB_TOKEN` publishes releases, with no separate personal token required. Repository/org policies must permit the release job's requested permission.
|
||||||
|
|
||||||
|
Development artifacts use Android's default debug signing. Fresh GitHub runners can generate different debug keys, so debug artifacts are not a stable production update channel. They do not contain the production private key.
|
||||||
|
|
||||||
|
## Local production validation
|
||||||
|
|
||||||
|
Provide these values securely in the process environment (never commit a shell script containing their values):
|
||||||
|
|
||||||
|
- `NAVFRAME_KEYSTORE_PATH`
|
||||||
|
- `NAVFRAME_KEYSTORE_PASSWORD`
|
||||||
|
- `NAVFRAME_KEY_ALIAS`
|
||||||
|
- `NAVFRAME_KEY_PASSWORD`
|
||||||
|
|
||||||
|
From the repository root, using JDK 17 and Android SDK 36:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gradlew --no-daemon --max-workers=4 :app:assembleRelease :app:lintRelease -PnavframeVersionCode=1000042
|
||||||
|
"$ANDROID_HOME/build-tools/35.0.0/apksigner" verify --verbose app/build/outputs/apk/release/app-release.apk
|
||||||
|
```
|
||||||
|
|
||||||
|
The version-code override is optional for local builds; ordinary debug builds retain the manifest's normal version code and need no signing variables. An unsigned production build is rejected instead of producing a publishable release. Partially specified signing configuration is rejected with variable names only.
|
||||||
|
|
||||||
|
Publication is active only after this workflow lands on the selected branch and the production secrets are configured. A successful local production build does not establish a GitHub Release was published.
|
||||||
Reference in new issue
Block a user