178 lines
6.9 KiB
YAML
178 lines
6.9 KiB
YAML
name: build-apk
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: ghcr.io/cirruslabs/flutter:latest
|
|
steps:
|
|
# The cirruslabs/flutter image has no Node.js; actions/checkout and
|
|
# actions/upload-artifact are JS actions that need `node` inside the job container.
|
|
- name: Install Node.js
|
|
run: |
|
|
set -eux
|
|
NODE_TGZ=$(curl -fsSL https://nodejs.org/dist/latest-v22.x/ | grep -oE 'node-v22\.[0-9]+\.[0-9]+-linux-x64\.tar\.xz' | sort -V | tail -1)
|
|
curl -fsSL "https://nodejs.org/dist/latest-v22.x/${NODE_TGZ}" -o /tmp/node.tar.xz
|
|
tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1
|
|
node --version
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Cache pub deps
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
${{ env.FLUTTER_ROOT }}/.pub-cache
|
|
.dart_tool
|
|
key: pub-${{ hashFiles('pubspec.lock') }}
|
|
|
|
- name: Cache Gradle
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.gradle/caches
|
|
key: gradle-${{ hashFiles('android/**/*.gradle*') }}
|
|
|
|
- name: Pub get
|
|
run: flutter pub get
|
|
|
|
- name: Codegen (build_runner)
|
|
run: dart run build_runner build --delete-conflicting-outputs
|
|
|
|
- name: Generate l10n
|
|
run: flutter gen-l10n
|
|
|
|
- name: Analyze
|
|
run: flutter analyze
|
|
|
|
- name: Unit tests
|
|
run: flutter test
|
|
|
|
- name: Integration tests (DeepSeek AI)
|
|
run: flutter test test/features/notification_parsing/integration/ --dart-define=DEEPSEEK_API_KEY=${{ secrets.DEEPSEEK_API_KEY }}
|
|
env:
|
|
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
|
|
|
|
- name: Compute next version
|
|
env:
|
|
GITHUB_TOKEN: ${{ github.token }}
|
|
run: |
|
|
set -euxo pipefail
|
|
API="${{ github.api_url }}/repos/${GITHUB_REPOSITORY}"
|
|
TAGS=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" "$API/tags?limit=100")
|
|
LAST=$(echo "$TAGS" | python3 -c "
|
|
import json, sys
|
|
tags = [t['name'] for t in json.load(sys.stdin) if t['name'].startswith('v')]
|
|
def key(n):
|
|
try:
|
|
return tuple(int(x) for x in n[1:].split('.')[:3])
|
|
except ValueError:
|
|
return (0, 0, 0)
|
|
print(max(tags, key=key) if tags else '')
|
|
")
|
|
if [ -z "$LAST" ]; then
|
|
NEXT="1.0.0"
|
|
CODE=10000
|
|
else
|
|
IFS=. read -r MAJOR MINOR PATCH <<< "${LAST#v}"
|
|
MINOR=${MINOR:-0}
|
|
PATCH=${PATCH:-0}
|
|
PATCH=$((PATCH + 1))
|
|
NEXT="${MAJOR}.${MINOR}.${PATCH}"
|
|
CODE=$((MAJOR * 10000 + MINOR * 100 + PATCH))
|
|
fi
|
|
echo "NEXT_VERSION=${NEXT}" >> "$GITHUB_ENV"
|
|
echo "NEXT_CODE=${CODE}" >> "$GITHUB_ENV"
|
|
echo "== Version =="
|
|
echo " last release tag: ${LAST:-none}"
|
|
echo " next build: v${NEXT} (versionCode ${CODE})"
|
|
|
|
- name: Build debug APK
|
|
run: flutter build apk --debug --build-name=$NEXT_VERSION --build-number=$NEXT_CODE
|
|
|
|
- name: Restore release keystore
|
|
run: |
|
|
mkdir -p android/app
|
|
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > android/app/release-keystore.p12
|
|
printf 'storeFile=release-keystore.p12\nstorePassword=%s\nkeyAlias=%s\nkeyPassword=%s\n' \
|
|
"${{ secrets.KEYSTORE_PASSWORD }}" \
|
|
"${{ secrets.KEY_ALIAS }}" \
|
|
"${{ secrets.KEY_PASSWORD }}" > android/key.properties
|
|
|
|
- name: Build release APK
|
|
run: flutter build apk --release --build-name=$NEXT_VERSION --build-number=$NEXT_CODE
|
|
|
|
- name: Show built APKs
|
|
run: ls -lh build/app/outputs/flutter-apk/
|
|
|
|
- name: Upload debug APK
|
|
# Gitea Actions supports only the v3 artifact protocol;
|
|
# upload-artifact@v4 fails with GHESNotSupportedError.
|
|
# Artifacts are only kept for master runs.
|
|
if: github.ref == 'refs/heads/master'
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: onbudget-debug-apk
|
|
path: build/app/outputs/flutter-apk/app-debug.apk
|
|
|
|
- name: Upload release APK
|
|
if: github.ref == 'refs/heads/master'
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: onbudget-release-apk
|
|
path: build/app/outputs/flutter-apk/app-release.apk
|
|
|
|
- name: Create tag + Gitea release
|
|
# Releases are created only from master runs. The tag v<NEXT_VERSION>
|
|
# is auto-created and triggers no further workflow runs (no tag trigger).
|
|
if: github.ref == 'refs/heads/master'
|
|
env:
|
|
GITHUB_TOKEN: ${{ github.token }}
|
|
run: |
|
|
set -euxo pipefail
|
|
API="${{ github.api_url }}/repos/${GITHUB_REPOSITORY}"
|
|
TAG_COMMIT=$(git rev-parse HEAD)
|
|
echo "== Creating tag v${NEXT_VERSION} at ${TAG_COMMIT} =="
|
|
TAG_RESP=$(curl -sS -X POST "$API/git/refs" \
|
|
-H "Authorization: token $GITHUB_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"ref\":\"refs/tags/v${NEXT_VERSION}\",\"sha\":\"${TAG_COMMIT}\"}")
|
|
echo "$TAG_RESP" | python3 -c "
|
|
import json, sys
|
|
d = json.load(sys.stdin)
|
|
if 'ref' in d:
|
|
print(' tag created: ' + d['ref'])
|
|
elif 'message' in d and 'already' in str(d['message']).lower():
|
|
print(' tag already exists: ' + str(d['message']))
|
|
else:
|
|
print(' unexpected response: ' + json.dumps(d), file=sys.stderr)
|
|
sys.exit(1)
|
|
"
|
|
echo "== Creating Gitea release v${NEXT_VERSION} =="
|
|
REL=$(curl -sS -X POST "$API/releases" \
|
|
-H "Authorization: token $GITHUB_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"v${NEXT_VERSION}\",\"name\":\"v${NEXT_VERSION}\",\"body\":\"OnBudget v${NEXT_VERSION} — debug + release APKs\"}")
|
|
ID=$(echo "$REL" | python3 -c "
|
|
import json, sys
|
|
d = json.load(sys.stdin)
|
|
if 'id' not in d:
|
|
print('API error: ' + json.dumps(d), file=sys.stderr)
|
|
sys.exit(1)
|
|
print(' release: ' + str(d.get('html_url', d.get('url'))), file=sys.stderr)
|
|
print(d['id'])
|
|
")
|
|
echo "== Uploading APKs to release =="
|
|
for f in build/app/outputs/flutter-apk/app-debug.apk build/app/outputs/flutter-apk/app-release.apk; do
|
|
echo " $(basename "$f") ($(du -h "$f" | cut -f1))"
|
|
curl -sS -X POST "$API/releases/${ID}/assets?name=$(basename "$f")" \
|
|
-H "Authorization: token $GITHUB_TOKEN" \
|
|
-F "attachment=@$f" | python3 -c "import json,sys; d=json.load(sys.stdin); print(' ok:', d.get('name'), 'size:', d.get('size'))"
|
|
done
|
|
echo "== Done: v${NEXT_VERSION} release created =="
|