## 0.7.2 #92
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 构建发布Flutter应用 | |
#on: | |
# push: | |
on: | |
push: | |
paths: | |
- "pubspec.yaml" | |
branches: | |
- main | |
jobs: | |
pre-build: | |
name: 预构建 | |
runs-on: ubuntu-latest | |
outputs: | |
APP_VERSION: ${{ steps.output-version.outputs.APP_VERSION }} | |
APP_LAST_VERSION: ${{ steps.output-tag-version.outputs.APP_VERSION }} | |
steps: | |
- name: 拉取代码 | |
uses: actions/checkout@v3 | |
with: | |
sparse-checkout: | | |
pubspec.yaml | |
sparse-checkout-cone-mode: false | |
fetch-depth: 0 | |
- name: 读取当前版本号 | |
id: output-version | |
run: | | |
VERSION=`grep -iE --regexp="version: ([0-9\.+]*)" pubspec.yaml | grep -io "[0-9\.+]*"` | |
echo "Version: $VERSION" | |
echo "APP_VERSION=$VERSION" >> $GITHUB_OUTPUT | |
- name: 获取最新的TAG | |
id: output-tag-version | |
run: | | |
LAST_VERSION=`git tag --sort=-creatordate | head -1` | |
echo "Version: $LAST_VERSION" | |
echo "APP_LAST_VERSION=$LAST_VERSION" >> $GITHUB_OUTPUT | |
build-apk: | |
name: 编译android | |
runs-on: ubuntu-latest | |
needs: [ pre-build ] | |
steps: | |
- name: 设置Flutter环境 | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- name: 拉取代码 | |
uses: actions/checkout@v4 | |
- name: 安装依赖项 | |
run: flutter pub get | |
- name: 设置java环境 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: "adopt" | |
java-version: "21" | |
- name: 运行代码生成器 | |
run: dart run build_runner build | |
- name: 初始化签名 | |
run: | | |
touch ./android/key.properties | |
echo keyPassword='${{ secrets.KEYPASSWORD }}' >> ./android/key.properties | |
echo storePassword='${{ secrets.STOREPASSWORD }}' >> ./android/key.properties | |
echo keyAlias='${{ secrets.KEYALIAS }}' >> ./android/key.properties | |
echo storeFile='./key.jks' >> ./android/key.properties | |
echo ${{ secrets.KEY_STORE }} | base64 --decode > ./android/app/key.jks | |
- name: 编译apk | |
run: flutter build apk --split-per-abi --obfuscate --split-debug-info=build/app/outputs/symbols/release | |
- name: 上传apk到工作流程 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-apk | |
path: build/app/outputs/apk/release/* | |
build-linux: | |
name: 编译linux | |
runs-on: ubuntu-latest | |
needs: [ pre-build ] | |
steps: | |
- name: 拉取代码 | |
uses: actions/checkout@v4 | |
- name: 设置Flutter环境 | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- name: 安装ninja、libgtk | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y ninja-build libgtk-3-dev libmpv-dev mpv | |
- name: 安装依赖项 | |
run: flutter pub get | |
- name: 配置桌面 | |
run: flutter config --enable-linux-desktop | |
- name: 运行代码生成器 | |
run: dart run build_runner build | |
- name: 编译linux | |
run: flutter build linux | |
- name: 压缩生成的文件 | |
run: tar -zcvf "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-linux-x86_64-release.tar.gz" --directory=build/linux/x64/release/bundle . | |
- name: 上传到工作流程 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-linux | |
path: "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-linux-x86_64-release.tar.gz" | |
build-windows: | |
name: 编译windows | |
runs-on: windows-latest | |
needs: [ pre-build ] | |
steps: | |
- name: 拉取代码 | |
uses: actions/checkout@v4 | |
- name: 设置Flutter环境 | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- name: 安装依赖项 | |
run: flutter pub get | |
- name: 启动windows桌面 | |
run: flutter config --enable-windows-desktop | |
- name: 运行代码生成器 | |
run: dart run build_runner build | |
- name: 编译windows | |
run: flutter build windows | |
- name: 压缩生成的文件 | |
run: | | |
$sourceFolder = "build\windows\x64\runner\Release" | |
$destinationPath = "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-windows-x86_64-release.zip" | |
Compress-Archive -Path $sourceFolder -DestinationPath $destinationPath | |
- name: 上传到工作流程 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-windows | |
path: "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-windows-x86_64-release.zip" | |
build-macos: | |
name: 编译macOS | |
runs-on: macos-latest | |
needs: [ pre-build ] | |
steps: | |
- name: 拉取代码 | |
uses: actions/checkout@v4 | |
- name: 设置Flutter环境 | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- name: 安装依赖项 | |
run: flutter pub get | |
- name: 启动桌面 | |
run: flutter config --enable-macos-desktop | |
- name: 运行代码生成器 | |
run: dart run build_runner build | |
- name: 编译macOS | |
run: flutter build macos | |
- name: 压缩生成的文件 | |
run: | | |
cd build/macos/Build/Products/Release | |
zip -rq MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip MoeKey.app | |
mv MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip $GITHUB_WORKSPACE | |
mkdir dmg && cp -r MoeKey.app dmg | |
hdiutil create -volname "MoeKey" -srcfolder dmg -ov -format UDRW MoeKey.dmg | |
hdiutil attach MoeKey.dmg | |
cp $GITHUB_WORKSPACE/assets/favicon.icns /Volumes/MoeKey/.VolumeIcon.icns | |
SetFile -c icnC /Volumes/MoeKey/.VolumeIcon.icns | |
SetFile -a C /Volumes/MoeKey | |
hdiutil detach /Volumes/MoeKey | |
hdiutil convert MoeKey.dmg -format UDZO -o MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.dmg | |
mv MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.dmg $GITHUB_WORKSPACE | |
- name: 上传到工作流程 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-macos | |
path: | | |
MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip | |
MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.dmg | |
release: | |
name: 上传包 | |
needs: [ build-apk, build-linux, build-windows, build-macos, pre-build ] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: 下载apk | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-apk | |
path: artifact | |
- name: 下载linux | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-linux | |
path: artifact | |
- name: 下载windows | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-windows | |
path: artifact | |
- name: 下载macOS | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-macos | |
path: artifact | |
- name: 创建releases | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ needs.pre-build.outputs.APP_VERSION }} | |
files: ./artifact/* | |
body: "[CHANGELOG.md](CHANGELOG.md)" |