build-apk / build (push) Canceled after 4m12s
Guard the Create Gitea release step: fetch origin/master and compare with the tagged commit; if the tag is not on master's tip, skip release creation instead of publishing a release for a feature/dev branch.
118 lines
4.3 KiB
YAML
118 lines
4.3 KiB
YAML
name: build-apk
|
|
|
|
on:
|
|
push:
|
|
branches: [master]
|
|
tags: ['v*']
|
|
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: Build debug APK
|
|
run: flutter build apk --debug
|
|
|
|
- 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
|
|
|
|
- name: Upload debug APK
|
|
# Gitea Actions supports only the v3 artifact protocol;
|
|
# upload-artifact@v4 fails with GHESNotSupportedError.
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: onbudget-debug-apk
|
|
path: build/app/outputs/flutter-apk/app-debug.apk
|
|
|
|
- name: Upload release APK
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: onbudget-release-apk
|
|
path: build/app/outputs/flutter-apk/app-release.apk
|
|
|
|
- name: Create Gitea release
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
env:
|
|
GITHUB_TOKEN: ${{ github.token }}
|
|
run: |
|
|
set -eux
|
|
# Releases only for tags that point at the master branch tip —
|
|
# a tag pushed to a feature/dev branch never creates a release.
|
|
git fetch origin master
|
|
if [ "$(git rev-parse HEAD)" != "$(git rev-parse FETCH_HEAD)" ]; then
|
|
echo "Tag ${GITHUB_REF_NAME} does not point to master — skipping release creation"
|
|
exit 0
|
|
fi
|
|
TAG=${GITHUB_REF_NAME}
|
|
API="${{ github.api_url }}/repos/${GITHUB_REPOSITORY}"
|
|
REL=$(curl -s -X POST "$API/releases" \
|
|
-H "Authorization: token $GITHUB_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"body\":\"OnBudget ${TAG} — debug + release APKs\"}")
|
|
ID=$(echo "$REL" | python3 -c "import json,sys; print(json.load(sys.stdin)['id'])")
|
|
echo "release id: ${ID}"
|
|
for f in build/app/outputs/flutter-apk/app-debug.apk build/app/outputs/flutter-apk/app-release.apk; do
|
|
echo "uploading $(basename "$f")"
|
|
curl -s -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'))"
|
|
done
|