Compare commits
2 Commits
2026-08-31
...
2026-08-31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc2a16bf66 | ||
|
|
56a7103503 |
@@ -1,7 +1,7 @@
|
||||
name: Android build
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
contents: write
|
||||
releases: write
|
||||
|
||||
on:
|
||||
@@ -96,6 +96,29 @@ jobs:
|
||||
set -euxo pipefail
|
||||
printf 'sdk.dir=%s/.android/sdk\n' "$HOME" > local.properties
|
||||
|
||||
- name: Prepare CI build metadata
|
||||
id: build_meta
|
||||
shell: bash
|
||||
run: |
|
||||
set -euxo pipefail
|
||||
timestamp_utc="$(date -u +%Y%m%d-%H%M%S)"
|
||||
version_code="$(date -u +%s)"
|
||||
project_name="$(basename "$GITHUB_REPOSITORY")"
|
||||
python3 - "$version_code" <<'PY'
|
||||
from pathlib import Path
|
||||
import re, sys
|
||||
path = Path('app/build.gradle.kts')
|
||||
text = path.read_text(encoding='utf-8')
|
||||
new_text, count = re.subn(r'(\bversionCode\s*=\s*)\d+', rf'\g<1>{sys.argv[1]}', text, count=1)
|
||||
if count != 1:
|
||||
raise SystemExit('versionCode not found in app/build.gradle.kts')
|
||||
path.write_text(new_text, encoding='utf-8')
|
||||
PY
|
||||
echo "Using CI versionCode: $version_code"
|
||||
echo "project_name=$project_name" >> "$GITHUB_OUTPUT"
|
||||
echo "timestamp_utc=$timestamp_utc" >> "$GITHUB_OUTPUT"
|
||||
echo "version_code=$version_code" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Build debug APK
|
||||
if: github.event_name != 'release'
|
||||
shell: bash
|
||||
@@ -114,6 +137,18 @@ jobs:
|
||||
export ANDROID_HOME="$ANDROID_SDK_ROOT"
|
||||
./gradlew --no-daemon bundleRelease
|
||||
|
||||
- name: Rename release AAB for upload
|
||||
if: github.event_name == 'release'
|
||||
id: release_aab
|
||||
shell: bash
|
||||
run: |
|
||||
set -euxo pipefail
|
||||
aab="$(find app/build/outputs/bundle/release -name '*.aab' | head -n 1)"
|
||||
renamed="app/build/outputs/bundle/release/${{ steps.build_meta.outputs.project_name }}-${{ steps.build_meta.outputs.timestamp_utc }}-release.aab"
|
||||
mv -f "$aab" "$renamed"
|
||||
echo "Renamed release AAB to $(basename "$renamed")"
|
||||
echo "path=$renamed" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Upload debug APK
|
||||
if: github.event_name != 'release'
|
||||
uses: actions/upload-artifact@v3
|
||||
@@ -126,13 +161,19 @@ jobs:
|
||||
if: github.event_name == 'release'
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -euxo pipefail
|
||||
token="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}"
|
||||
if [ -z "$token" ]; then
|
||||
echo "::error::No release upload token is available from secrets.GITEA_TOKEN or github.token"
|
||||
exit 1
|
||||
fi
|
||||
release_id="$(python3 -c 'import json, os; print(json.load(open(os.environ["GITHUB_EVENT_PATH"], encoding="utf-8"))["release"]["id"])')"
|
||||
aab="$(find app/build/outputs/bundle/release -name '*.aab' | head -n 1)"
|
||||
aab="${{ steps.release_aab.outputs.path }}"
|
||||
curl --fail-with-body \
|
||||
--request POST \
|
||||
--header "Authorization: token ${GITEA_TOKEN}" \
|
||||
--header "Authorization: token ${token}" \
|
||||
--form "attachment=@${aab}" \
|
||||
"${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}/releases/${release_id}/assets?name=$(basename "$aab")"
|
||||
|
||||
Reference in New Issue
Block a user