Skip to content

chore(CI): 去除之前设置的强制关闭. 虽然没有立刻回收很奇怪 #193

chore(CI): 去除之前设置的强制关闭. 虽然没有立刻回收很奇怪

chore(CI): 去除之前设置的强制关闭. 虽然没有立刻回收很奇怪 #193

Workflow file for this run

# 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_*
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
# 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@v3
# 由于此处没有Tag, 所以Tag从配置文件中读取
- name: Init
run: |
source build/info
git log --pretty=format:"%s" -1>CHANGELOG.md
echo "GITHUB_REF: ${GITHUB_REF}"
mkdir packages
bash build/prepare.sh
# 构建deb包
- name: Build deb
run: |
source build/info
tag=${Version}
echo "tag: ${tag}"
echo ${{ steps.Init.outputs.TAG }}
echo ${{ 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}"
#tag=${GITHUB_REF/refs\/tags\//}
echo "work_path: ${work_path}"
dpkg -b ${work_path} ${pwd_path}/packages/minecraftctl_${tag//v/}_${Arch}.deb
done
ls -lab
ls -lab packages
# 构建rpm包
- name: Build RPM
run: |
source build/info
tag=${Version}
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 yum install -y rpmdevtools>/dev/null
echo install rpmdevtools Finish.
work_path="${pwd_path}/build/rpm/"
#tag=${GITHUB_REF/refs\/tags\//}
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-${Version}-1.el7.${Arch/amd64/x86_64}.rpm ${pwd_path}/packages/
done
docker exec -t centos7Instance rm -rf /root/rpmbuild
docker kill -s KILL centos7Instance
docker rm centos7Instance
ls -lab packages
# 上传包以在多个作业中共享
- uses: actions/upload-artifact@v3
name: upload amd64.deb
with:
name: amd64.deb
path: packages/minecraftctl_*_amd64.deb
if-no-files-found: error
- uses: actions/upload-artifact@v3
name: upload i386.deb
with:
name: i386.deb
path: packages/minecraftctl_*i386.deb
if-no-files-found: error
- uses: actions/upload-artifact@v3
name: upload amd64.rpm
with:
name: amd64.rpm
path: packages/minecraftctl-*.x86_64.rpm
if-no-files-found: error
- uses: actions/upload-artifact@v3
name: upload i386.rpm
with:
name: i386.rpm
path: packages/minecraftctl-*.i386.rpm
if-no-files-found: error
# Releases(这个字段是用于发布的字段)
# - name: Releases
# if: startsWith(github.ref, 'refs/tags/')
# uses: softprops/action-gh-release@v1
# with:
# body_path: CHANGELOG.md
# files: |
# minecraftctl_${{ steps.init.outputs.VERSION }}_x86_64.deb
# minecraftctl-${{ steps.init.outputs.VERSION }}-1.el7.x86_64.rpm
# env:
# GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
Install-Test:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: get amd64.deb
uses: actions/download-artifact@v3
with:
name: amd64.deb
path: packages
- name: get amd64.rpm
uses: actions/download-artifact@v3
with:
name: amd64.rpm
path: packages
- name: DEB Install and test
run: |
source build/info
ls -lab packages
tag=${Version}
echo $PWD
pwd_path=$PWD
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/minecraftctl_${Version}_amd64.deb | grep 'minecraftctl'; \
echo minecraftctl installed...;\
sudo minecraftctl help;\
cat /etc/minecraftctl/config | grep --color '^export GamePath=\"\${HOME}/Minecraft\"$';"
- name: RPM Install and test
run: |
source build/info
ls -lab packages
tag=${Version}
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
echo yum update...
docker exec -t centos7Instance bash -c "yum install -y http://mirror.math.princeton.edu/pub/epel/7/x86_64/Packages/a/aria2-1.34.0-5.el7.x86_64.rpm > /dev/null; \
yum install -y ${pwd_path}/packages/minecraftctl-${Version}-1.el7.x86_64.rpm | 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/minecraftctl-${Version}-1.el7.x86_64.rpm | 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@v3
- 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;
curl -s https://adoptopenjdk.jfrog.io/artifactory/deb/pool/main/a/adoptopenjdk-8-openj9-jre/adoptopenjdk-8-openj9-jre_8u292-b10.openj9-0.26.0-3_amd64.deb -o ~/adoptopenjdk-8-openj9-jre.deb>/dev/null;
sudo sudo apt install -y ~/adoptopenjdk-8-openj9-jre.deb>/dev/null;
rm ~/adoptopenjdk-8-openj9-jre.deb;
# 部署pyCraft
git clone https://github.com/MemoryShadow/pyCraft.git ../pyCraft;
pip install 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;
ls -labh; cat minecraftctl.conf;
- name: Run Minecraft Server
run: |
# 生成一个随机ID, 这个ID也会成为在这个CI校验流程中的重要ID,
CheckID=`date +%s%N | md5sum | cut -c 1-10`
ProjectDir=${PWD}
#*新增start事件响应, 启动时拉起一个pyCraft实例
sudo tee -a "/opt/minecraftctl/event/INFO/start" >> /dev/null <<EOF
echo "拉起一个pyCraft实例" >> /tmp/E_CICheck.log
# 拉起一个pyCraft实例
cd ../pyCraft;
echo " 创建会话" >> /tmp/E_CICheck.log
screen -dmS "pyCraft"
echo " 设置权限" >> /tmp/E_CICheck.log
chmod +x ./start.py
echo ${PWD} >> /tmp/E_CICheck.log
ls-lab >> /tmp/E_CICheck.log
# 上线
screen -x -S "pyCraft" -p 0 -X stuff "echo ' 检查环境: ${CheckID}' >> /tmp/E_CICheck.log 2>&1\n";
screen -x -S "pyCraft" -p 0 -X stuff "./start.py -u ${CheckID} -s localhost -o >> /tmp/E_CICheck.log 2>&1\n";
EOF
cat "/opt/minecraftctl/event/INFO/start"
#*新增login事件响应, 登陆时发送消息
sudo tee -a "/opt/minecraftctl/event/INFO/login" >>/dev/null <<EOF
echo "发送消息触发插件" >> /tmp/E_CICheck.log
# 发送消息触发插件
screen -x -S "pyCraft" -p 0 -X stuff "\!\!ci ${CheckID}\n";
EOF
#*新增logout事件响应, 退出登陆时关闭服务端
sudo tee -a "/opt/minecraftctl/event/INFO/logout" >>/dev/null <<EOF
echo "玩家退出时自动关闭服务端" >> /tmp/E_CICheck.log
# 玩家退出时自动关闭服务端
minecraftctl stop;
EOF
#*创建CI模块, 输出日志并关闭服务器
sudo tee "/opt/minecraftctl/command/ci" >/dev/null <<EOF
#!/bin/bash
cd ~/D_MCServer
echo "\${1#*\!\!ci }" > /tmp/CICheck.log
echo "退出登陆" >> /tmp/E_CICheck.log
# 退出登陆
screen -S "pyCraft" -X quit;
EOF
sudo chmod +x "/opt/minecraftctl/command/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
- name: Uninstall minecraftctl
run: sudo build/Universal.sh uninstall