-
Notifications
You must be signed in to change notification settings - Fork 1
326 lines (294 loc) · 13 KB
/
main.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches:
- master
- develop
- develop/**
- dev_*
tags:
- 'v*.*.*'
pull_request:
branches:
- master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
outputs:
TAG: ${{ steps.Init.outputs.TAG }}
VERSION: ${{ steps.Init.outputs.VERSION }}
DEB_AMD64: ${{ steps.deb.outputs.amd64 }}
DEB_I386: ${{ steps.deb.outputs.i386 }}
RPM_AMD64: ${{ steps.rpm.outputs.amd64 }}
RPM_I386: ${{ steps.rpm.outputs.i386 }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
# 由于此处没有Tag, 所以Tag从配置文件中读取
- name: Init
id: Init
run: |
source build/info
git log --pretty=format:"%s" -1>CHANGELOG.md
echo "GITHUB_REF: ${GITHUB_REF}"
# 当由tag触发时, 使用tag指定的版本
if [[ "${GITHUB_REF}" =~ ^refs/tags/.* ]]; then
echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_OUTPUT
else
echo "TAG=v${Version}" >> $GITHUB_OUTPUT
echo "VERSION=${Version}" >> $GITHUB_OUTPUT
fi
mkdir packages
bash build/prepare.sh
# 构建deb包
- name: Build deb
id: deb
run: |
source build/info
echo "TAG: ${{ steps.Init.outputs.TAG }}"
echo "VERSION: ${{ steps.Init.outputs.VERSION }}"
pwd_path=`pwd`
echo "pwd_path: ${pwd_path}"
Architecture_T=(${Architecture//,/ })
for Arch in ${Architecture_T[@]}; do
work_path="${pwd_path}/build/deb/${Arch}"
echo "work_path: ${work_path}"
dpkg -b ${work_path} ${pwd_path}/packages/minecraftctl_${{ steps.Init.outputs.VERSION }}_${Arch}.deb
echo "${Arch}=minecraftctl_${{ steps.Init.outputs.VERSION }}_${Arch}.deb" >> $GITHUB_OUTPUT
done
ls -lab
ls -lab packages
# 构建rpm包
- name: Build RPM
id: rpm
run: |
source build/info
echo $PWD
pwd_path=$PWD
Architecture_T=(${Architecture//,/ })
mkdir -p ${pwd_path}/packages
docker run -itd -v ${pwd_path}:${pwd_path} --name centos7Instance --net="host" docker.io/centos:7 /bin/bash
echo install rpmdevtools ing...
docker exec -t centos7Instance curl -so /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
docker exec -t centos7Instance yum install -y rpmdevtools>/dev/null
echo install rpmdevtools Finish.
work_path="${pwd_path}/build/rpm/"
echo "work_path: ${work_path}"
docker exec -t centos7Instance cp -r ${work_path} /root/rpmbuild
docker exec -t centos7Instance rpmdev-setuptree
for Arch in ${Architecture_T[@]}; do
docker exec -t centos7Instance rpmbuild -bb --target ${Arch/amd64/x86_64} /root/rpmbuild/SPECS/minecraftctl.spec
docker exec -t centos7Instance cp /root/rpmbuild/RPMS/${Arch/amd64/x86_64}/minecraftctl-${{ steps.Init.outputs.VERSION }}-1.el7.${Arch/amd64/x86_64}.rpm ${pwd_path}/packages/
echo "${Arch}=minecraftctl-${{ steps.Init.outputs.VERSION }}-1.el7.${Arch/amd64/x86_64}.rpm" >> $GITHUB_OUTPUT
done
docker exec -t centos7Instance rm -rf /root/rpmbuild
docker kill -s KILL centos7Instance
docker rm centos7Instance
ls -lab packages
# 上传包以在多个作业中共享
- uses: actions/upload-artifact@v4
name: upload amd64.deb
with:
name: amd64.deb
path: packages/minecraftctl_*_amd64.deb
if-no-files-found: error
- uses: actions/upload-artifact@v4
name: upload i386.deb
with:
name: i386.deb
path: packages/minecraftctl_*i386.deb
if-no-files-found: error
- uses: actions/upload-artifact@v4
name: upload amd64.rpm
with:
name: amd64.rpm
path: packages/minecraftctl-*.x86_64.rpm
if-no-files-found: error
- uses: actions/upload-artifact@v4
name: upload i386.rpm
with:
name: i386.rpm
path: packages/minecraftctl-*.i386.rpm
if-no-files-found: error
Install-Test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: get amd64.deb
uses: actions/download-artifact@v4
with:
name: amd64.deb
path: packages
- name: get amd64.rpm
uses: actions/download-artifact@v4
with:
name: amd64.rpm
path: packages
- name: DEB Install and test
run: |
source build/info
ls -lab packages
echo $PWD
pwd_path=$PWD
download_url=`curl -s https://api.github.com/repos/MemoryShadow/minecraftctl/releases/latest | grep browser_download_url | grep amd64.deb`;
download_url=${download_url#*: \"}; download_url=${download_url%\"*};
echo download_url: ${download_url};
CheckID=`date +%s%N | md5sum | cut -c 1-10`;
docker run -itd -v ${pwd_path}:${pwd_path} --name ubuntuInstance --env TZ=Asia/Shanghai --env DEBIAN_FRONTEND=noninteractive --net="host" docker.io/ubuntu:20.04 /bin/bash
echo Apt update...
# TODO 这里暂时先不测试升级后存档继承的问题. 因为目前只有一个版本
docker exec -t ubuntuInstance bash -c "apt-get update &> /dev/null; apt-get install -y -q sudo wget tzdata>/dev/null; \
echo minecraftctl installing...; \
sudo apt install -y -q ${pwd_path}/packages/${{ needs.build.outputs.DEB_AMD64 }} | grep 'minecraftctl'; \
echo minecraftctl installed...; \
sudo minecraftctl help; \
cat /etc/minecraftctl/config | grep --color '^export GamePath=\"\${HOME}/Minecraft\"$'; \
echo minecraftctl uninstalling...; \
sudo apt remove --purge -y minecraftctl > /dev/null; \
echo minecraftctl Install the latest release...; \
wget ${download_url}; sudo apt install -y -q ./${download_url##*/}; rm ${download_url##*/}; \
CheckID=`date +%s%N | md5sum | cut -c 1-10`; \
echo -e "\n\nexport CheckID='${CheckID}'" | sudo tee -a /etc/minecraftctl/config; \
cat /etc/minecraftctl/config | grep --color \"^export CheckID='${CheckID}'\"; \
echo minecraftctl updating...; \
sudo apt install -y -q ${pwd_path}/packages/${{ needs.build.outputs.DEB_AMD64 }} | grep 'minecraftctl'; \
cat /etc/minecraftctl/config | grep ${CheckID};"
- name: RPM Install and test
run: |
source build/info
ls -lab packages
echo $PWD
pwd_path=$PWD
docker run -itd -v ${pwd_path}:${pwd_path} --name centos7Instance --net="host" docker.io/centos:7.9.2009 /bin/bash
docker exec -t centos7Instance curl -so /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
echo yum update...
docker exec -t centos7Instance bash -c "yum install -y http://mirrors.aliyun.com/epel/7/x86_64/Packages/a/aria2-1.34.0-5.el7.x86_64.rpm > /dev/null; \
yum install -y ${pwd_path}/packages/${{ needs.build.outputs.RPM_AMD64 }} | grep 'minecraftctl' | grep -v '\[#* *\]'; \
minecraftctl help;\
cat /etc/minecraftctl/config | grep --color '^export GamePath=\"\${HOME}/Minecraft\"$';\
sed '\$a\export ScreenName=Test' /etc/minecraftctl/config > ~/config.bak;\
yum remove -y minecraftctl | grep 'minecraftctl' | grep -v '\[#* *\]';\
mkdir /etc/minecraftctl; cp ~/config.bak /etc/minecraftctl/config;\
yum install -y ${pwd_path}/packages/${{ needs.build.outputs.RPM_AMD64 }} | grep 'minecraftctl' | grep -v '\[#* *\]';\
cat /etc/minecraftctl/config | grep --color '^export ScreenName=\"Test\"$';"
Linux-Universal-Installation-and-testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup run environment
run: |
# 部署运行环境
source build/info;
sudo apt install -y ${Depends//,/ };
export TZ=Asia/Shanghai;
export DEBIAN_FRONTEND=noninteractive;
sudo apt update>/dev/null;
sudo apt install -y -q sudo wget tzdata openjdk-8-jre-headless>/dev/null;
# 安装Java环境
wget -q https://github.com/ibmruntimes/semeru8-binaries/releases/download/jdk8u372-b07_openj9-0.38.0/ibm-semeru-open-jre_x64_linux_8u372b07_openj9-0.38.0.tar.gz -O adoptopenjdk-8-openj9-jre.tar.gz > /dev/null;
mkdir -p /usr/lib/jvm/;
sudo tar -xzf adoptopenjdk-8-openj9-jre.tar.gz -C /usr/lib/jvm/;
rm adoptopenjdk-8-openj9-jre.tar.gz;
# 部署pyCraft
git clone --depth 1 -b master https://github.com/MemoryShadow/pyCraft.git ~/pyCraft;
pip install --user pynbt requests cryptography;
- name: Install old-minecraftctl
run: |
sudo build/Universal.sh install;
minecraftctl help;
- name: Update minecraftctl
run: |
sudo sed -i 's/GamePath=".*"/GamePath="~\/D_MCServer"/' /etc/minecraftctl/config;
sudo build/Universal.sh update;
grep D_MCServer /etc/minecraftctl/config;
if [ $? -ne 0 ]; then
echo "Update config failed.";
exit 1;
fi
minecraftctl help;
sudo build/Universal.sh uninstall;
- name: Install minecraftctl
run: sudo build/Universal.sh install && minecraftctl help;
- name: Download Minecraft Server
run: |
minecraftctl install -h;
mkdir -p ~/D_MCServer;
cd ~/D_MCServer;
minecraftctl install -i vanilla -c -v 1.16.5;
if [ $? -ne 0 ]; then
echo "Install Minecraft Server failed.";
exit 1;
fi
ls -labh; cat minecraftctl.conf;
- name: Run Minecraft Server
run: |
# 生成一个随机ID, 这个ID也会成为在这个CI校验流程中的重要ID,
CheckID=`date +%s%N | md5sum | cut -c 1-10`;
echo -e "\n\nexport CheckID='${CheckID}'" | sudo tee -a /etc/minecraftctl/config;
minecraftctl install -mE -i ci
#*启动服务
sudo sed -i 's/> \/dev\/stderr;/>> \/tmp\/E_CICheck.log;/' /opt/minecraftctl/module/listen.sh;
cd ~/D_MCServer; minecraftctl start;
while [ ! -f eula.txt ]; do sleep 1; done;
sed -i 's/eula=false/eula=true/' eula.txt;
while [ ! -f server.properties ]; do sleep 1; done;
sed -i 's/online-mode=true/online-mode=false/' server.properties;
minecraftctl start;
#*在这里记录等待的时间, 通过循环可以尽可能快的返回(节约CI时间)
WaitTimeS=0;
while [ ! -f /tmp/CICheck.log ]; do
sleep 1;
WaitTimeS=$[ WaitTimeS + 1];
if [ ${WaitTimeS} -gt 120 ]; then
echo "等待超时" > /dev/stderr;
minecraftctl stop;
cat logs/latest.log;
cat /tmp/E_CICheck.log;
exit 1;
fi
done
cat /tmp/CICheck.log | grep ${CheckID};
- name: Uninstall minecraftctl
run: sudo build/Universal.sh uninstall;
# 当检测到tag时, 自动生成CHANGELOG与发布构建物
AutoReleases:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [build, Install-Test, Linux-Universal-Installation-and-testing]
steps:
- uses: actions/checkout@v4
- name: Init
run: |
mkdir packages
git log --pretty=format:"%s" -1>CHANGELOG.md
- name: download artifact
uses: actions/download-artifact@v4
with:
path: packages
- name: Releases
uses: softprops/action-gh-release@v1
with:
body_path: CHANGELOG.md
files: |
packages/amd64.deb/${{ needs.build.outputs.DEB_AMD64 }}
packages/i386.deb/${{ needs.build.outputs.DEB_I386 }}
packages/amd64.rpm/${{ needs.build.outputs.RPM_AMD64 }}
packages/i386.rpm/${{ needs.build.outputs.RPM_I386 }}
token: ${{ secrets.ACCESS_TOKEN }}
- name: Cleanup
uses: geekyeggo/delete-artifact@v2
with:
name: |
amd64.*
i386.*