5 Commits
Author SHA1 Message Date
Sanders b8ee8be9eb Create release tags via POST /tags — Gitea has no POST /git/refs
build-apk / build (push) Successful in 13m7s
POST /git/refs returns 405 with an empty body on Gitea, which crashed
the tag step (json decode of ''). Use the tags API:
POST /repos/{owner}/{repo}/tags with {tag_name, target} (201), and
409 'tag already exists' is handled gracefully.
2026-08-12 01:17:31 +03:00
Sanders ec0a134b5a Run workflow steps under bash (pipefail is sh-incompatible)
build-apk / build (push) Failing after 9m5s
Gitea Actions default shell is sh (dash), which rejects 'set -o pipefail'.
Add defaults.run.shell: bash so the version/release steps work.
2026-08-12 01:03:15 +03:00
Sanders 1c19f5a8e4 Only upload artifacts on master runs
build-apk / build (push) Failing after 3m6s
2026-08-12 01:01:59 +03:00
Sanders 468349e90c Auto-increment version and auto-create release on each master build
build-apk / build (push) Failing after 3m8s
- Compute next vX.Y.Z from the latest tag (patch bump) via Gitea API
- Pass it to flutter build via --build-name/--build-number so the APK
  versionName/versionCode always increase (installs update in place)
- Auto-create tag + Gitea release + upload both APKs on master runs only
- Verbose logging: version computed, built APK sizes, tag/release/asset results
- Drop the tag trigger: the auto-created tag would otherwise re-trigger the
  workflow (double builds / release conflicts)
2026-08-12 00:57:05 +03:00
Sanders 6f7ae57dd7 Only create releases for tags pointing at master
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.
2026-08-12 00:53:22 +03:00
+88 -14
View File
@@ -3,9 +3,14 @@ name: build-apk
on: on:
push: push:
branches: [master] branches: [master]
tags: ['v*']
workflow_dispatch: workflow_dispatch:
defaults:
run:
# Gitea Actions uses sh (dash) by default, which lacks `pipefail`;
# run all steps under bash.
shell: bash
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -59,8 +64,42 @@ jobs:
env: env:
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} 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 - name: Build debug APK
run: flutter build apk --debug run: flutter build apk --debug --build-name=$NEXT_VERSION --build-number=$NEXT_CODE
- name: Restore release keystore - name: Restore release keystore
run: | run: |
@@ -72,39 +111,74 @@ jobs:
"${{ secrets.KEY_PASSWORD }}" > android/key.properties "${{ secrets.KEY_PASSWORD }}" > android/key.properties
- name: Build release APK - name: Build release APK
run: flutter build apk --release 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 - name: Upload debug APK
# Gitea Actions supports only the v3 artifact protocol; # Gitea Actions supports only the v3 artifact protocol;
# upload-artifact@v4 fails with GHESNotSupportedError. # upload-artifact@v4 fails with GHESNotSupportedError.
# Artifacts are only kept for master runs.
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: onbudget-debug-apk name: onbudget-debug-apk
path: build/app/outputs/flutter-apk/app-debug.apk path: build/app/outputs/flutter-apk/app-debug.apk
- name: Upload release APK - name: Upload release APK
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: onbudget-release-apk name: onbudget-release-apk
path: build/app/outputs/flutter-apk/app-release.apk path: build/app/outputs/flutter-apk/app-release.apk
- name: Create Gitea release - name: Create tag + Gitea release
if: startsWith(github.ref, 'refs/tags/') # 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: env:
GITHUB_TOKEN: ${{ github.token }} GITHUB_TOKEN: ${{ github.token }}
run: | run: |
set -eux set -euxo pipefail
TAG=${GITHUB_REF_NAME}
API="${{ github.api_url }}/repos/${GITHUB_REPOSITORY}" API="${{ github.api_url }}/repos/${GITHUB_REPOSITORY}"
REL=$(curl -s -X POST "$API/releases" \ TAG_COMMIT=$(git rev-parse HEAD)
echo "== Creating tag v${NEXT_VERSION} at ${TAG_COMMIT} =="
# Gitea has no POST /git/refs (405); use the tags API instead.
TAG_RESP=$(curl -sS -X POST "$API/tags" \
-H "Authorization: token $GITHUB_TOKEN" \ -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"body\":\"OnBudget ${TAG} — debug + release APKs\"}") -d "{\"tag_name\":\"v${NEXT_VERSION}\",\"target\":\"${TAG_COMMIT}\"}")
ID=$(echo "$REL" | python3 -c "import json,sys; print(json.load(sys.stdin)['id'])") echo "$TAG_RESP" | python3 -c "
echo "release id: ${ID}" import json, sys
d = json.load(sys.stdin)
if 'name' in d:
print(' tag created: ' + d['name'])
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 for f in build/app/outputs/flutter-apk/app-debug.apk build/app/outputs/flutter-apk/app-release.apk; do
echo "uploading $(basename "$f")" echo " $(basename "$f") ($(du -h "$f" | cut -f1))"
curl -s -X POST "$API/releases/${ID}/assets?name=$(basename "$f")" \ curl -sS -X POST "$API/releases/${ID}/assets?name=$(basename "$f")" \
-H "Authorization: token $GITHUB_TOKEN" \ -H "Authorization: token $GITHUB_TOKEN" \
-F "attachment=@$f" | python3 -c "import json,sys; d=json.load(sys.stdin); print(' ok:', d.get('name'))" -F "attachment=@$f" | python3 -c "import json,sys; d=json.load(sys.stdin); print(' ok:', d.get('name'), 'size:', d.get('size'))"
done done
echo "== Done: v${NEXT_VERSION} release created =="