134 lines
3.6 KiB
YAML
134 lines
3.6 KiB
YAML
name: Build and Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build-macos:
|
|
name: Build macOS (M-Series)
|
|
runs-on: macos-14
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Flutter
|
|
uses: subosito/flutter-action@v2
|
|
with:
|
|
channel: 'stable'
|
|
cache: true
|
|
|
|
- name: Get dependencies
|
|
run: flutter pub get
|
|
|
|
- name: Build macOS
|
|
run: |
|
|
flutter clean
|
|
flutter build macos --release
|
|
|
|
- name: Create DMG
|
|
run: |
|
|
APP_NAME="caption_trans"
|
|
BUILD_PATH="build/macos/Build/Products/Release/${APP_NAME}.app"
|
|
DMG_NAME="${APP_NAME}-macos-arm64.dmg"
|
|
|
|
# Create temporary folder for DMG content
|
|
mkdir -p dmg_content
|
|
cp -R "$BUILD_PATH" dmg_content/
|
|
ln -s /Applications dmg_content/Applications
|
|
|
|
# Create DMG
|
|
hdiutil create -volname "$APP_NAME" -srcfolder dmg_content -ov -format UDZO "$DMG_NAME"
|
|
|
|
# Clean up
|
|
rm -rf dmg_content
|
|
|
|
- name: Upload macOS Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: macos-dmg
|
|
path: caption_trans-macos-arm64.dmg
|
|
|
|
build-windows:
|
|
name: Build Windows
|
|
runs-on: windows-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Flutter
|
|
uses: subosito/flutter-action@v2
|
|
with:
|
|
channel: 'stable'
|
|
cache: true
|
|
|
|
- name: Get dependencies
|
|
run: flutter pub get
|
|
|
|
- name: Build Windows
|
|
run: |
|
|
flutter clean
|
|
flutter build windows --release
|
|
|
|
- name: Package Windows
|
|
shell: pwsh
|
|
run: |
|
|
$APP_NAME = "caption_trans"
|
|
$WORKSPACE = "${{ github.workspace }}"
|
|
|
|
# 拼接出 Release 文件夹的绝对路径
|
|
$RELEASE_DIR = Join-Path $WORKSPACE "build\windows\x64\runner\Release"
|
|
$ZIP_NAME = Join-Path $WORKSPACE "${APP_NAME}-windows-x64.zip"
|
|
|
|
Write-Host "Looking for Release directory at: $RELEASE_DIR"
|
|
|
|
# 验证目录是否存在
|
|
if (!(Test-Path $RELEASE_DIR)) {
|
|
Write-Error "!!! 找不到 Release 目录 !!!"
|
|
Write-Host "打印 build\windows 目录结构用于排查:"
|
|
Get-ChildItem -Path "$WORKSPACE\build\windows" -Recurse -Depth 3 | Select-Object FullName
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Found Release directory. Packaging..."
|
|
# 将该目录下的所有文件打包到工作区根目录
|
|
Compress-Archive -Path "$RELEASE_DIR\*" -DestinationPath "$ZIP_NAME" -Force
|
|
Write-Host "Successfully created $ZIP_NAME"
|
|
|
|
- name: Upload Windows Artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: windows-zip
|
|
path: caption_trans-windows-x64.zip
|
|
|
|
create-release:
|
|
name: Create GitHub Release
|
|
needs: [build-macos, build-windows]
|
|
runs-on: ubuntu-latest
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
steps:
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
path: artifacts
|
|
merge-multiple: true
|
|
|
|
- name: Create Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
files: |
|
|
artifacts/*.dmg
|
|
artifacts/*.zip
|
|
draft: false
|
|
prerelease: false
|
|
generate_release_notes: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |