Skip to content

chore(LinkGet): 手动更新了mohist支持的版本 #230

chore(LinkGet): 手动更新了mohist支持的版本

chore(LinkGet): 手动更新了mohist支持的版本 #230

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_*
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@v3
# 由于此处没有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 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@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
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
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/${{ needs.build.outputs.DEB_AMD64 }} | 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
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/${{ 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@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;
# 安装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 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`;
#*新增start事件响应, 启动时拉起一个pyCraft实例
sudo tee -a "/opt/minecraftctl/event/INFO/start" >> /dev/null <<EOF;
echo "拉起一个pyCraft实例" >> /tmp/E_CICheck.log;
# 拉起一个pyCraft实例
ls -lab ./ >> /tmp/E_CICheck.log;
echo "======" >> /tmp/E_CICheck.log;
ls -lab ../ >> /tmp/E_CICheck.log;
cd ~/pyCraft;;
echo " 创建会话" >> /tmp/E_CICheck.log;
screen -dmS "pyCraft";
echo " 设置权限" >> /tmp/E_CICheck.log;
chmod +x ./start.py;
# 上线
screen -x -S "pyCraft" -p 0 -X stuff "echo ' 检查环境: ${CheckID} \${PWD}' >> /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
#*新增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 | 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@v3
- name: Init
run: |
mkdir packages
git log --pretty=format:"%s" -1>CHANGELOG.md
- name: download artifact
uses: actions/download-artifact@v3
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.*