-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (192 loc) · 6.95 KB
/
build-and-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Build and Release Flutter Packages
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [linux, windows, macos, android, ios]
arch: [x64, arm64]
exclude:
- platform: windows
arch: arm64
- platform: ios
arch: x64
- platform: android
arch: x64
include:
- platform: macos
arch: x64
- platform: macos
arch: arm64
- platform: linux
arch: x64
- platform: linux
arch: arm64
- platform: android
arch: arm64
- platform: ios
arch: arm64
- platform: windows
arch: x64
runs-on: ${{
matrix.platform == 'windows' && 'windows-latest' ||
matrix.platform == 'linux' && 'ubuntu-latest' ||
matrix.platform == 'android' && 'ubuntu-latest' ||
matrix.platform == 'macos' && 'macos-latest' ||
matrix.platform == 'ios' && 'macos-latest' }}
env:
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Set up Flutter environment for Linux
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get update
sudo snap install flutter --classic
export PATH="$PATH:/snap/bin"
flutter doctor
- name: Set up Flutter environment for Windows
if: ${{ matrix.platform == 'windows' }}
shell: powershell
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install flutter -y
echo "C:\flutter\bin" >> $GITHUB_ENV
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
refreshenv
flutter --version
- name: Set up Flutter environment for Android
if: ${{ matrix.platform == 'android' }}
run: |
sudo apt-get update
sudo snap install flutter --classic
sudo apt-get install -y snapd openjdk-17-jdk
echo "JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" >> $GITHUB_ENV
# Set OpenJDK 17 as the default version
sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac
export PATH="$PATH:/snap/bin"
java -version
flutter doctor
- name: Set up Flutter environment for macOS/iOS
if: ${{ matrix.platform == 'macos' || matrix.platform == 'ios' }}
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)" # For Apple Silicon
else
eval "$(/usr/local/bin/brew shellenv)" # For Intel
fi
brew install --cask flutter
export PATH="$PATH:/Users/runner/Library/Flutter/bin"
flutter doctor
- name: Show workflow information
run: |
echo "Platform: $PLATFORM, Architecture: $ARCH"
- name: Build Flutter packages for Windows
if: ${{ matrix.platform == 'windows' }}
shell: powershell
run: |
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
refreshenv
flutter build windows --release
env:
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
PATH: C:\flutter\bin;${{ secrets.PATH }}
- name: Build Flutter packages for Linux/Android/macOS/iOS
run: |
case $PLATFORM in
"linux")
flutter build linux --release
;;
"android")
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
flutter build apk --release
;;
"macos")
flutter build macos --release
;;
"ios")
flutter build ios --release --no-codesign
;;
esac
shell: bash
env:
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
- name: List built files
run: ls -R build
- name: Upload built packages to artifact
if: success() # 仅在构建成功时执行
uses: actions/upload-artifact@v3
with:
name: flutter-packages-${{ github.run_number }}-${{ github.run_id }}
path: |
build/linux/x64/release/bundle/*
build/linux/arm64/release/bundle/*
build/windows/runner/Release/XStream.exe
build/macos/Build/Products/Release/XStream.app
build/app/outputs/flutter-apk/app-release.apk
build/ios/iphoneos/XStream.app
release:
runs-on: ubuntu-latest
needs: build # 确保构建任务完成后再执行
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Download built packages from artifact
uses: actions/download-artifact@v3
with:
name: flutter-packages-${{ github.run_number }}-${{ github.run_id }}
- name: Check if tag exists
id: check_tag
run: |
TAG_EXISTS=$(git tag --list "v${{ github.run_number }}-${{ github.run_id }}")
echo "tag_exists=$TAG_EXISTS" >> $GITHUB_ENV
- name: Set tag_name
id: set_tag_name
run: |
# 根据标签是否存在设置 tag_name
if [ -z "$TAG_EXISTS" ]; then
echo "tag_name=v${{ github.run_number }}-${{ github.run_id }}" >> $GITHUB_ENV
else
echo "tag_name=$TAG_EXISTS" >> $GITHUB_ENV
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ env.tag_name }}
release_name: Release ${{ env.tag_name }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload built packages to Release
if: env.tag_exists != '' # 只有在标签存在时才上传
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.tag_name }}
files: |
build/linux/x64/release/bundle/*
build/linux/arm64/release/bundle/*
build/windows/runner/Release/XStream.exe
build/macos/Build/Products/Release/XStream.app
build/app/outputs/flutter-apk/app-release.apk
build/ios/iphoneos/XStream.app
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}