forked from guozhigq/pilipala
-
Notifications
You must be signed in to change notification settings - Fork 53
211 lines (179 loc) · 6.1 KB
/
build-alpha.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
name: Build alpha
on:
workflow_dispatch:
push:
branches:
- 'dev'
paths-ignore:
- '**.md'
- '**.txt'
- '.github/**'
- '.idea/**'
- '!.github/workflows/build-alpha.yml'
jobs:
update_version:
name: Read latest version
runs-on: ubuntu-latest
outputs:
# 定义输出变量 version,以便在其他job中引用
new_version: ${{ steps.update-version.outputs.new_version }}
last_commit: ${{ steps.get-last-commit.outputs.last_commit }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 获取最后一次提交
id: get-last-commit
run: |
last_commit=$(git log -1 --pretty="%h %s" --first-parent)
echo "last_commit=$last_commit" >> $GITHUB_OUTPUT
- name: 生成alpha版本号
id: update-version
run: |
version_name=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
last_tag=$(git tag --sort=committerdate | tail -1)
if (echo $last_tag | grep -v "+"); then
echo "Illegal tag! ($last_tag)"
exit 1
elif (echo $last_tag | grep -v $version_name); then
echo "No tags for current version in the repo, please add one manually."
exit 1
fi
version_code=$(echo $last_tag | cut -d "+" -f 2)
datetime=$(date -u -d "8 hours" +%m%d%H%M)
echo "new_version=${version_name}-alpha.${datetime}+${version_code}" >> $GITHUB_OUTPUT
android:
name: Build CI (Android)
needs: update_version
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: 构建Java环境
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "21"
token: ${{secrets.GIT_TOKEN}}
- name: 检查缓存
uses: actions/cache@v2
id: cache-flutter
with:
path: /root/flutter-sdk
key: ${{ runner.os }}-flutter-${{ hashFiles('**/pubspec.lock') }}
- name: 安装Flutter
if: steps.cache-flutter.outputs.cache-hit != 'true'
uses: subosito/flutter-action@v2
with:
flutter-version: 3.24.4
channel: stable
- name: 修复3.24的stable显示中文不正确问题
run: |
cd $FLUTTER_ROOT
git config --global user.name "orz12"
git config --global user.email "[email protected]"
git cherry-pick d4124bd --strategy-option theirs
# flutter precache
flutter --version
cd -
- name: 下载项目依赖
run: flutter pub get
- name: 解码生成 jks
run: echo $KEYSTORE_BASE64 | base64 -di > android/app/vvex.jks
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
- name: 更新版本号
id: version
run: |
# 更新pubspec.yaml文件中的版本号
sed -i "s/version: .*/version: ${{ needs.update_version.outputs.new_version }}/g" pubspec.yaml
- name: flutter build apk
run: |
flutter build apk --release --split-per-abi
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD}}
- name: 重命名应用
run: |
version_name=$(yq e .version pubspec.yaml | cut -d "+" -f 1)
for file in build/app/outputs/flutter-apk/app-*.apk; do
if [[ $file =~ app-(.?*)release.apk ]]; then
new_file_name="build/app/outputs/flutter-apk/Pili-${BASH_REMATCH[1]}${version_name}.apk"
mv "$file" "$new_file_name"
fi
done
- name: 上传
uses: actions/upload-artifact@v3
with:
name: PiliPalaX-alpha
path: |
build/app/outputs/flutter-apk/Pili-*.apk
iOS:
name: Build CI (iOS)
needs: update_version
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: 安装Flutter
uses: subosito/[email protected]
with:
cache: true
flutter-version: 3.24.4
- name: 更新版本号
id: version
run: |
# 更新pubspec.yaml文件中的版本号
sed -i "" "s/version: .*/version: ${{ needs.update_version.outputs.new_version }}/g" pubspec.yaml
- name: flutter build ipa
run: |
flutter build ios --release --no-codesign
ln -sf ./build/ios/iphoneos Payload
zip -r9 app.ipa Payload/runner.app
- name: 重命名应用
run: |
for file in app.ipa; do
new_file_name="build/Pili-${{ needs.update_version.outputs.new_version }}.ipa"
mv "$file" "$new_file_name"
done
- name: 上传
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: PiliPalaX-alpha
path: |
build/Pili-*.ipa
upload:
runs-on: ubuntu-latest
needs:
- update_version
- iOS
steps:
- uses: actions/download-artifact@v3
with:
name: PiliPalaX-alpha
path: ./PiliPalaX-alpha
# - name: Upload Pre-release
# uses: ncipollo/release-action@v1
# with:
# name: ${{ needs.update_version.outputs.new_version }}
# token: ${{ secrets.GIT_TOKEN }}
# commit: main
# tag: ${{ needs.update_version.outputs.new_version }}
# prerelease: true
# allowUpdates: true
# artifacts: Pilipala-CI/*
- name: 发送到Telegram频道
uses: xireiki/[email protected]
with:
bot_token: ${{ secrets.BOT_TOKEN }}
chat_id: ${{ secrets.CHAT_ID }}
large_file: false
method: sendFile
path: PiliPalaX-alpha/*
parse_mode: Markdown
context: "*v${{ needs.update_version.outputs.new_version }}*\n${{ needs.update_version.outputs.last_commit }}"