3a336ddf88
actions/checkout and actions/upload-artifact are JavaScript actions. When container: is set, act runs them inside the container (not on the host runner), but ghcr.io/cirruslabs/flutter:stable has no Node.js. Replace both with equivalent shell commands: - checkout: git clone + git checkout SHA - artifact upload: curl to Forgejo API (best-effort, non-blocking) The release APK attach step was already a pure shell step and is unchanged.
146 lines
5.0 KiB
YAML
146 lines
5.0 KiB
YAML
# CI runs first; build only proceeds if analyze and test pass.
|
|
#
|
|
# Push to dev: analyze + test → build APK → upload artifact (fabledapp-dev-<sha>)
|
|
# Push to main: analyze + test only (no build — wait for release tag)
|
|
# Tag v*: analyze + test → build APK → upload artifact + attach to Forgejo Release
|
|
# Pull request: analyze + test only
|
|
#
|
|
# To cut a release:
|
|
# Create a release via the Forgejo UI on main with a v* tag name.
|
|
# The tag push triggers this workflow; the build job attaches the APK.
|
|
#
|
|
# Note: JavaScript actions (actions/checkout, actions/upload-artifact) cannot run
|
|
# inside the Flutter container because it has no Node.js. All steps use shell
|
|
# commands directly instead.
|
|
#
|
|
# Required secrets (repo → Settings → Secrets → Actions):
|
|
# RELEASE_TOKEN — Forgejo PAT with write:repository scope
|
|
name: CI & Build
|
|
|
|
on:
|
|
push:
|
|
branches: [main, dev]
|
|
tags: ["v*"]
|
|
paths:
|
|
- "lib/**"
|
|
- "test/**"
|
|
- "pubspec.yaml"
|
|
- "pubspec.lock"
|
|
- "analysis_options.yaml"
|
|
- "android/**"
|
|
- "assets/**"
|
|
- ".forgejo/workflows/ci.yml"
|
|
pull_request:
|
|
paths:
|
|
- "lib/**"
|
|
- "test/**"
|
|
- "pubspec.yaml"
|
|
- "pubspec.lock"
|
|
- "analysis_options.yaml"
|
|
- ".forgejo/workflows/ci.yml"
|
|
|
|
jobs:
|
|
analyze:
|
|
name: Analyze & test
|
|
runs-on: py3.12-node22
|
|
container:
|
|
image: ghcr.io/cirruslabs/flutter:stable
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git clone "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" .
|
|
git checkout "$GITHUB_SHA"
|
|
|
|
- name: Install dependencies
|
|
run: flutter pub get
|
|
|
|
- name: Analyze
|
|
run: flutter analyze
|
|
|
|
- name: Test
|
|
run: flutter test
|
|
|
|
build:
|
|
name: Build release APK
|
|
needs: [analyze]
|
|
# Build on dev branch pushes and version tag pushes only.
|
|
# main branch pushes run CI for safety but do not build —
|
|
# the release tag (v*) is the sole trigger for a production APK.
|
|
if: |
|
|
github.event_name == 'push' &&
|
|
(github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/tags/'))
|
|
runs-on: py3.12-node22
|
|
container:
|
|
image: ghcr.io/cirruslabs/flutter:stable
|
|
steps:
|
|
- name: Checkout
|
|
run: |
|
|
git clone "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" .
|
|
git checkout "$GITHUB_SHA"
|
|
|
|
- name: Install dependencies
|
|
run: flutter pub get
|
|
|
|
- name: Build release APK
|
|
run: flutter build apk --release
|
|
|
|
- name: Set artifact name
|
|
id: artifact
|
|
run: |
|
|
if [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
|
|
echo "name=fabledapp-dev-${{ github.sha }}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "name=fabledapp-${{ github.sha }}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Upload artifact to Forgejo
|
|
env:
|
|
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
APK: build/app/outputs/flutter-apk/app-release.apk
|
|
API: https://git.fabledsword.com/api/v1/repos/bvandeusen/FabledApp
|
|
ARTIFACT_NAME: ${{ steps.artifact.outputs.name }}
|
|
run: |
|
|
# Upload the APK as a workflow artifact via the Forgejo API.
|
|
curl -s -X POST "$API/actions/artifacts" \
|
|
-H "Authorization: token $RELEASE_TOKEN" \
|
|
-F "name=$ARTIFACT_NAME" \
|
|
-F "file=@$APK" || echo "Artifact upload skipped (API may not support this endpoint)."
|
|
|
|
- name: Publish Forgejo release
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
env:
|
|
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
|
TAG: ${{ github.ref_name }}
|
|
API: https://git.fabledsword.com/api/v1/repos/bvandeusen/FabledApp
|
|
run: |
|
|
# Look for an existing release (created via the UI or a prior run).
|
|
EXISTING=$(curl -s \
|
|
"$API/releases/tags/$TAG" \
|
|
-H "Authorization: token $RELEASE_TOKEN")
|
|
|
|
RELEASE_ID=$(echo "$EXISTING" | grep -oE '"id":[[:space:]]*[0-9]+' | head -1 | grep -oE '[0-9]+')
|
|
|
|
if [ -n "$RELEASE_ID" ]; then
|
|
echo "Found existing release $TAG (id $RELEASE_ID), attaching APK..."
|
|
else
|
|
echo "No existing release found, creating $TAG..."
|
|
RESPONSE=$(curl -s -X POST "$API/releases" \
|
|
-H "Authorization: token $RELEASE_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"\"}")
|
|
RELEASE_ID=$(echo "$RESPONSE" | grep -oE '"id":[[:space:]]*[0-9]+' | head -1 | grep -oE '[0-9]+')
|
|
if [ -z "$RELEASE_ID" ]; then
|
|
echo "Failed to create release. API response:"
|
|
echo "$RESPONSE"
|
|
exit 1
|
|
fi
|
|
echo "Release created with id $RELEASE_ID."
|
|
fi
|
|
|
|
curl -s -X POST "$API/releases/$RELEASE_ID/assets" \
|
|
-H "Authorization: token $RELEASE_TOKEN" \
|
|
-F "attachment=@build/app/outputs/flutter-apk/app-release.apk"
|
|
|
|
echo "Done — $TAG is live at:"
|
|
echo "https://git.fabledsword.com/bvandeusen/FabledApp/releases/tag/$TAG"
|