1+ name : Fast Multi-Platform Build
2+
13on :
24 workflow_dispatch :
35 push :
46 tags :
57 - ' *'
8+
9+ permissions :
10+ contents : write
11+
612jobs :
7- web :
13+ prepare :
814 runs-on : ubuntu-latest
15+ outputs :
16+ tag_name : ${{ steps.vars.outputs.tag_name }}
917 steps :
1018 - uses : actions/checkout@v4
11- with :
12- fetch-depth : 0 # 获取完整历史,以便获取最新的提交哈希
1319 - uses : subosito/flutter-action@v2
14- - run : flutter pub get
15- - run : flutter build web --release
16- - run : tar -czvf web.tar.gz -C build/web .
17- - uses : softprops/action-gh-release@v2
1820 with :
19- files : web.tar.gz
20- tag_name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
21- name : Release ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
22- draft : ${{ startsWith(github.ref, 'refs/tags/') == false }}
23- prerelease : false
24- linux :
25- runs-on : ubuntu-latest
26- steps :
27- - uses : actions/checkout@v4
21+ cache : true
22+
23+ - id : vars
24+ run : echo "tag_name=${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}" >> $GITHUB_OUTPUT
25+
26+ - name : Install dependencies
27+ run : flutter pub get
28+
29+ - name : Generate Code
30+ run : dart run build_runner build --delete-conflicting-outputs
31+
32+ - name : Upload Generated Files
33+ uses : actions/upload-artifact@v4
2834 with :
29- fetch-depth : 0
30- - uses : subosito/flutter-action@v2
31- - run : |
32- sudo apt-get update -y
33- sudo apt-get install -y ninja-build libgtk-3-dev
34- - run : flutter pub get
35- - run : flutter build linux --release
36- - run : tar -czvf linux-x64.tar.gz -C build/linux/x64/release/bundle .
37- - uses : softprops/action-gh-release@v2
38- with :
39- files : linux-x64.tar.gz
40- tag_name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
41- name : Release ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
42- draft : ${{ startsWith(github.ref, 'refs/tags/') == false }}
43- prerelease : false
44- android :
45- runs-on : ubuntu-latest
35+ name : generated-code
36+ path : |
37+ lib/**/*.g.dart
38+ .dart_tool/ # 包含 pub 缓存索引,非常重要
39+
40+ build :
41+ needs : prepare
42+ runs-on : ${{ matrix.config.os }}
43+ strategy :
44+ fail-fast : false
45+ matrix :
46+ config :
47+ - { os: ubuntu-latest, platform: web, name: web }
48+ - { os: ubuntu-latest, platform: apk, name: android }
49+ - { os: ubuntu-latest, platform: linux, name: linux }
50+ - { os: windows-latest, platform: windows, name: windows }
51+ - { os: macos-latest, platform: macos, name: macos }
52+ - { os: macos-latest, platform: ios, name: ios, args: "--no-codesign" }
53+
4654 steps :
4755 - uses : actions/checkout@v4
48- with :
49- fetch-depth : 0
50- - uses : actions/setup-java@v4
56+
57+ # 1. 【Android 专用优化】设置 Java 和 Gradle 缓存
58+ - name : Setup Java
59+ if : matrix.config.name == 'android'
60+ uses : actions/setup-java@v4
5161 with :
5262 distribution : ' temurin'
5363 java-version : ' 17'
64+
65+ - name : Setup Gradle
66+ if : matrix.config.name == 'android'
67+ uses : gradle/actions/setup-gradle@v3 # 核心加速器:缓存 Gradle 依赖和构建输出
68+
69+ # 2. 设置 Flutter
5470 - uses : subosito/flutter-action@v2
55- - run : flutter pub get
56- - run : flutter build apk --target-platform android-arm64
57- - uses : softprops/action-gh-release@v2
5871 with :
59- files : build/app/outputs/flutter-apk/app-release.apk
60- tag_name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
61- name : Release ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
62- draft : ${{ startsWith(github.ref, 'refs/tags/') == false }}
63- prerelease : false
64- windows :
65- runs-on : windows-latest
66- steps :
67- - uses : actions/checkout@v4
72+ cache : true
73+
74+ # 3. 下载预生成的代码
75+ - name : Download Generated Files
76+ uses : actions/download-artifact@v4
6877 with :
69- fetch-depth : 0
70- - uses : subosito/flutter-action@v2
71- - run : flutter pub get
72- - run : flutter build windows --release
73- - run : Compress-Archive -Path build/windows/x64/runner/Release/* -DestinationPath windows-x64.zip
74- - uses : softprops/action-gh-release@v2
78+ name : generated-code
79+
80+ - name : Install System Dependencies (Linux)
81+ if : matrix.config.platform == 'linux'
82+ run : |
83+ sudo apt-get update
84+ sudo apt-get install -y ninja-build libgtk-3-dev
85+
86+ # 4. 编译(由于下载了 .dart_tool,pub get 会极快)
87+ - name : Build
88+ run : |
89+ flutter pub get --offline || flutter pub get # 优先尝试离线模式
90+ flutter build ${{ matrix.config.platform }} --release ${{ matrix.config.args }}
91+
92+ # 5. 产物打包(修正了路径和逻辑)
93+ - name : Package Assets
94+ shell : bash
95+ run : |
96+ if [ "${{ matrix.config.platform }}" == "web" ]; then
97+ tar -czvf web.tar.gz -C build/web .
98+ elif [ "${{ matrix.config.platform }}" == "linux" ]; then
99+ tar -czvf linux-x64.tar.gz -C build/linux/x64/release/bundle .
100+ elif [ "${{ matrix.config.platform }}" == "windows" ]; then
101+ cd build/windows/x64/runner/Release && 7z a ../../../../../windows-x64.zip *
102+ elif [ "${{ matrix.config.platform }}" == "macos" ]; then
103+ cd build/macos/Build/Products/Release && tar -czvf ../../../../../macos.tar.gz *.app
104+ elif [ "${{ matrix.config.platform }}" == "ios" ]; then
105+ cd build/ios/iphoneos && tar -czvf ../../../ios.tar.gz Runner.app
106+ elif [ "${{ matrix.config.platform }}" == "apk" ]; then
107+ cp build/app/outputs/flutter-apk/app-release.apk android-release.apk
108+ fi
109+
110+ - name : Upload Platform Artifacts
111+ uses : actions/upload-artifact@v4
75112 with :
76- files : windows-x64.zip
77- tag_name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
78- name : Release ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
79- draft : ${{ startsWith(github.ref, 'refs/tags/') == false }}
80- prerelease : false
81- macos :
82- runs-on : macos-latest
113+ name : build-artifacts-${{ matrix.config.name }}
114+ path : |
115+ *.tar.gz
116+ *.zip
117+ *.apk
118+
119+ publish :
120+ needs : [prepare, build]
121+ runs-on : ubuntu-latest
122+ if : startsWith(github.ref, 'refs/tags/') # 仅在有 Tag 时发布
83123 steps :
84- - uses : actions/checkout@v4
124+ - name : Download All Artifacts
125+ uses : actions/download-artifact@v4
85126 with :
86- fetch-depth : 0
87- - uses : subosito/flutter-action@v2
88- - run : flutter pub get
89- - run : flutter build macos --release
90- - run : tar -czvf macos.tar.gz -C build/macos/Build/Products/ Release auth.app
91- - uses : softprops/action-gh-release@v2
127+ path : release-assets
128+ pattern : build-artifacts-*
129+ merge-multiple : true
130+
131+ - name : Release
132+ uses : softprops/action-gh-release@v2
92133 with :
93- files : macos.tar.gz
94- tag_name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
95- name : Release ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
96- draft : ${{ startsWith(github.ref, 'refs/tags/') == false }}
134+ files : release-assets/*
135+ tag_name : ${{ needs.prepare.outputs.tag_name }}
136+ name : Release ${{ needs.prepare.outputs.tag_name }}
137+ draft : false
97138 prerelease : false
98- ios :
99- runs-on : macos-latest
100- steps :
101- - uses : actions/checkout@v4
102- with :
103- fetch-depth : 0
104- - uses : subosito/flutter-action@v2
105- - run : flutter pub get
106- - run : flutter build ios --release --no-codesign
107- - run : tar -czvf ios.tar.gz -C build/ios/iphoneos Runner.app
108- - uses : softprops/action-gh-release@v2
109- with :
110- files : ios.tar.gz
111- tag_name : ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
112- name : Release ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || github.sha }}
113- draft : ${{ startsWith(github.ref, 'refs/tags/') == false }}
114- prerelease : false
139+ generate_release_notes : true
0 commit comments