Skip to content

Build and Release APK #35

Build and Release APK

Build and Release APK #35

Workflow file for this run

name: Build and Release APK
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Tag version (e.g., v1.0.0)'
required: true
type: string
permissions:
contents: write
jobs:
build-android-linux:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && 'master' || github.ref }}
- name: Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
else
TAG=${GITHUB_REF#refs/tags/}
fi
VERSION=${TAG#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
# Check if tag contains beta
if [[ "$TAG" == *"beta"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Update pubspec.yaml version
run: |
sed -i "s/^version:.*/version: ${{ steps.version.outputs.version }}+${{ github.run_number }}/" pubspec.yaml
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.35.2'
channel: 'stable'
- name: Get dependencies
run: flutter pub get
- name: Decode keystore
run: |
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > android/app/keystore.jks
- name: Create key.properties
run: |
echo "storePassword=${{ secrets.STORE_PASSWORD }}" > android/key.properties
echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> android/key.properties
echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> android/key.properties
echo "storeFile=keystore.jks" >> android/key.properties
- name: Build APK - All-in-one (arm64-v8a + armeabi-v7a)
run: |
flutter build apk --release --target-platform android-arm64,android-arm
mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/pt_mate-${{ steps.version.outputs.version }}-allinone.apk
- name: Build APK - ARM64 (v8a)
run: |
flutter build apk --release --target-platform android-arm64
mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/pt_mate-${{ steps.version.outputs.version }}-arm64-v8a.apk
- name: Build APK - ARMv7
run: |
flutter build apk --release --target-platform android-arm
mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/pt_mate-${{ steps.version.outputs.version }}-armeabi-v7a.apk
- name: Upload Android artifacts
uses: actions/upload-artifact@v4
with:
name: android-artifacts
path: |
build/app/outputs/flutter-apk/pt_mate-${{ steps.version.outputs.version }}-allinone.apk
build/app/outputs/flutter-apk/pt_mate-${{ steps.version.outputs.version }}-arm64-v8a.apk
build/app/outputs/flutter-apk/pt_mate-${{ steps.version.outputs.version }}-armeabi-v7a.apk
retention-days: 1
# 直接在Android构建后添加Linux构建步骤
- name: Install Linux dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev libblkid-dev libsecret-1-dev
- name: Build Linux
run: flutter build linux --release
- name: Create Linux package
run: |
mkdir -p pt_mate-${{ steps.version.outputs.version }}-linux-x64
cp -r build/linux/x64/release/bundle/* pt_mate-${{ steps.version.outputs.version }}-linux-x64/
tar -czf pt_mate-${{ steps.version.outputs.version }}-linux-x64.tar.gz pt_mate-${{ steps.version.outputs.version }}-linux-x64
- name: Upload Linux artifact
uses: actions/upload-artifact@v4
with:
name: linux-artifact
path: pt_mate-${{ steps.version.outputs.version }}-linux-x64.tar.gz
retention-days: 1
build-windows:
runs-on: windows-latest
# 移除对Android构建的依赖,实现并行构建
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && 'master' || github.ref }}
- name: Extract version from tag
id: version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
else
TAG=${GITHUB_REF#refs/tags/}
fi
VERSION=${TAG#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.35.2'
channel: 'stable'
- name: Get dependencies
run: flutter pub get
- name: Build Windows
run: flutter build windows --release
- name: Install Inno Setup
run: |
choco install innosetup -y
- name: Download Chinese language file
run: |
$languagesDir = "C:\Program Files (x86)\Inno Setup 6\Languages"
if (-not (Test-Path "$languagesDir\ChineseSimplified.isl")) {
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl" -OutFile "$languagesDir\ChineseSimplified.isl"
}
- name: Compile Inno Setup installer
run: |
iscc /DMyAppVersion="${{ steps.version.outputs.version }}" windows/inno_setup.iss
- name: Upload Windows artifact
uses: actions/upload-artifact@v4
with:
name: windows-artifact
path: Output/pt_mate-${{ steps.version.outputs.version }}-windows-x64.exe
retention-days: 1
create-release:
runs-on: ubuntu-latest
needs: [build-android-linux, build-windows]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && 'master' || github.ref }}
- name: Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
else
TAG=${GITHUB_REF#refs/tags/}
fi
VERSION=${TAG#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
# Check if tag contains beta
if [[ "$TAG" == *"beta"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Create Release and Upload All Artifacts
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Release ${{ steps.version.outputs.tag }}
body: |
## Changes in this release
${{ github.event.head_commit.message }}
## 📱 Android APK Downloads
- **All-in-one APK** (arm64-v8a + armeabi-v7a): Compatible with most devices
- **ARM64 APK** (arm64-v8a): For modern 64-bit devices
- **ARMv7 APK** (armeabi-v7a): For older 32-bit devices
## 💻 Desktop Downloads
- **Windows x64**: Windows installer for 64-bit systems
- **Linux x64**: Linux package for 64-bit systems
draft: false
prerelease: ${{ steps.version.outputs.is_prerelease }}
files: |
android-artifacts/pt_mate-${{ steps.version.outputs.version }}-allinone.apk
android-artifacts/pt_mate-${{ steps.version.outputs.version }}-arm64-v8a.apk
android-artifacts/pt_mate-${{ steps.version.outputs.version }}-armeabi-v7a.apk
windows-artifact/pt_mate-${{ steps.version.outputs.version }}-windows-x64.exe
linux-artifact/pt_mate-${{ steps.version.outputs.version }}-linux-x64.tar.gz
fail_on_unmatched_files: true