Skip to content

build: 更新版本号至 v0.0.9 #48

build: 更新版本号至 v0.0.9

build: 更新版本号至 v0.0.9 #48

Workflow file for this run

name: Build
on:
push:
branches:
- main
- dev
paths:
- '.github/workflows/build.yml'
- 'src/**'
- 'include/**'
- 'CMakeLists.txt'
tags:
- 'v*' # 匹配 v 开头的标签
pull_request:
paths:
- '.github/workflows/build.yml'
- 'src/**'
- 'include/**'
- 'CMakeLists.txt'
workflow_dispatch:
jobs:
build_windows:
name: Build on Windows
runs-on: windows-2022
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up MSVC
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86_64
- name: Set up CMake and Ninja
uses: lukka/get-cmake@latest
- name: Build with CMake
run: |
mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHUHOBOT_SERVER_URL="${{ secrets.WS_SERVER_URL }}" ..
cmake --build .
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: endstone-huhobot-${{ runner.os }}
path: |
./build/endstone_*.dll
./build/endstone_*.pdb
build_linux:
name: Build on Ubuntu
runs-on: ubuntu-22.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Clang 15
env:
LLVM_VERSION: 15
run: |
sudo apt-get update -y -q
sudo apt-get install -y -q lsb-release wget software-properties-common gnupg
sudo wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
sudo ./llvm.sh ${LLVM_VERSION}
sudo apt-get install -y -q libc++-${LLVM_VERSION}-dev libc++abi-${LLVM_VERSION}-dev
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${LLVM_VERSION} 100
- name: Set up CMake and Ninja
uses: lukka/get-cmake@latest
- name: Build with CMake
run: |
mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHUHOBOT_SERVER_URL="${{ secrets.WS_SERVER_URL }}" ..
cmake --build .
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: endstone-huhobot-${{ runner.os }}
path: |
./build/endstone_*.so
release:
name: Create Release
needs:
- build_linux
- build_windows
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
# 新增权限配置
permissions:
contents: write # 必须的权限
actions: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract release info
id: changelog
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
# 修复:使用正确的标签格式匹配
VERSION=${TAG_NAME#v} # 去除v前缀(如果CHANGELOG使用纯版本号)
CHANGELOG_CONTENT=$(awk -v version="[v$VERSION]" '
BEGIN {RS="## "; FS="\n"}
$1 ~ version {
sub(/\[.*\] - .*\n/, "")
gsub(/`/, "\\`")
gsub(/"/, "\\\"")
print
exit
}
' CHANGELOG.md)
EOF_MARKER=$(openssl rand -base64 12)
echo "body<<$EOF_MARKER" >> $GITHUB_OUTPUT
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
echo "$EOF_MARKER" >> $GITHUB_OUTPUT
# 添加标签名输出
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
- name: Download Linux Artifacts
uses: actions/download-artifact@v4
with:
name: endstone-huhobot-Linux
path: artifacts
- name: Download Windows Artifacts
uses: actions/download-artifact@v4
with:
name: endstone-huhobot-Windows
path: artifacts
- name: Rename release files
run: |
cd artifacts
TAG_NAME=${{ steps.changelog.outputs.tag_name }}
# 处理Windows文件
for file in endstone_*.dll endstone_*.pdb; do
new_name="${file%.*}_${TAG_NAME}.${file##*.}"
mv "$file" "$new_name"
done
# 处理Linux文件
for file in endstone_*.so; do
new_name="${file%.*}_${TAG_NAME}.so"
mv "$file" "$new_name"
done
- name: Get timestamp
id: get-time
run: echo "TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1 # 改用更可靠的 Action
with:
tag_name: ${{ steps.changelog.outputs.tag_name }}
name: HuHoBot ${{ steps.changelog.outputs.tag_name }}
body: |
${{ steps.changelog.outputs.body }}
### 构建信息
- 构建时间: ${{ steps.get-time.outputs.TIME }}
- 提交哈希: [${{ github.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
### 下载说明
- Linux:
- 插件本体: [endstone_huhobot_${{ steps.changelog.outputs.tag_name }}.so](https://github.com/HuHoBot/EndStoneAdapter/releases/download/${{ steps.changelog.outputs.tag_name }}/endstone_huhobot_${{ steps.changelog.outputs.tag_name }}.so)
- Windows:
- 插件本体: [endstone_huhobot_${{ steps.changelog.outputs.tag_name }}.dll](https://github.com/HuHoBot/EndStoneAdapter/releases/download/${{ steps.changelog.outputs.tag_name }}/endstone_huhobot_${{ steps.changelog.outputs.tag_name }}.dll)
- 插件调试信息: [endstone_huhobot_${{ steps.changelog.outputs.tag_name }}.pdb](https://github.com/HuHoBot/EndStoneAdapter/releases/download/${{ steps.changelog.outputs.tag_name }}/endstone_huhobot_${{ steps.changelog.outputs.tag_name }}.pdb)
files: |
artifacts/*