glp-companion/.forgejo/workflows/release.yaml

167 lines
5.4 KiB
YAML

name: Build and Publish Alpha Releases
on:
push:
tags:
- 'v*'
jobs:
build-android:
name: Build Android APK
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.47.x'
channel: 'stable'
cache: true
- name: Install Dependencies
run: flutter pub get
- name: Run Code Generation
run: dart run build_runner build --delete-conflicting-outputs
- name: Decode Android Keystore & Key Properties
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
KEY_PROPERTIES: ${{ secrets.ANDROID_KEY_PROPERTIES }}
run: |
if [ -n "$KEYSTORE_BASE64" ]; then
echo "$KEYSTORE_BASE64" | base64 -d > android/app/upload-keystore.jks
echo "$KEY_PROPERTIES" > android/key.properties
fi
- name: Build Split APKs
run: flutter build apk --release --split-per-abi
- name: Rename and Stage APK
run: |
mkdir -p dist
TAG_NAME=${GITHUB_REF#refs/tags/}
cp build/app/outputs/flutter-apk/app-arm64-v8a-release.apk "dist/GLP1Companion-Android-arm64-${TAG_NAME}.apk"
- name: Upload Artifact for Release
uses: actions/upload-artifact@v4
with:
name: android-release-apk
path: dist/*.apk
retention-days: 1
build-windows:
name: Build Windows MSIX & Portable
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.47.x'
channel: 'stable'
cache: true
- name: Install Dependencies
shell: pwsh
run: flutter pub get
- name: Run Code Generation
shell: pwsh
run: dart run build_runner build --delete-conflicting-outputs
- name: Build Windows Native Release
shell: pwsh
run: flutter build windows --release
- name: Generate MSIX Installer
shell: pwsh
run: dart run msix:create --install-certificate false
- name: Package Portable Zip & Stage MSIX
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist | Out-Null
$tag = $env:GITHUB_REF -replace 'refs/tags/', ''
# Copy MSIX
Copy-Item "build\windows\x64\runner\Release\*.msix" "dist\GLP1Companion-Windows-${tag}.msix" -Force
# Compress standalone runner folder
Compress-Archive -Path "build\windows\x64\runner\Release\*" -DestinationPath "dist\GLP1Companion-Windows-x64-${tag}-Portable.zip" -Force
- name: Upload Artifacts for Release
uses: actions/upload-artifact@v4
with:
name: windows-release-packages
path: dist/*
retention-days: 1
publish-release:
name: Attach Assets to Forgejo Release
needs: [build-android, build-windows]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Staged Artifacts
uses: actions/download-artifact@v4
with:
path: staged-assets
- name: Create Forgejo Release and Upload Assets
env:
FORGEJO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
REPO="${{ github.repository }}"
SERVER="${{ github.server_url }}"
echo "Target Release: $TAG_NAME on $REPO"
# 1. Fetch or Create Release
RELEASE_JSON=$(curl -s -X POST "$SERVER/api/v1/repos/$REPO/releases" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"$TAG_NAME\",
\"name\": \"GLP-1 Companion $TAG_NAME\",
\"body\": \"Automated alpha release build for $TAG_NAME.\",
\"draft\": false,
\"prerelease\": true
}")
RELEASE_ID=$(echo "$RELEASE_JSON" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
if [ -z "$RELEASE_ID" ]; then
echo "Release may already exist, fetching existing release ID..."
RELEASE_JSON=$(curl -s "$SERVER/api/v1/repos/$REPO/releases/tags/$TAG_NAME" \
-H "Authorization: token $FORGEJO_TOKEN")
RELEASE_ID=$(echo "$RELEASE_JSON" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
fi
echo "Release ID: $RELEASE_ID"
# 2. Upload All Staged Artifacts to Release
find staged-assets -type f \( -name "*.apk" -o -name "*.msix" -o -name "*.zip" \) | while read -r FILE; do
FILENAME=$(basename "$FILE")
echo "Uploading $FILENAME to release $RELEASE_ID..."
curl -s -X POST "$SERVER/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILENAME" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$FILE" > /dev/null
done
echo "All release assets uploaded successfully."