Skip to content

Merge remote-tracking branch 'upstream/master' #63

Merge remote-tracking branch 'upstream/master'

Merge remote-tracking branch 'upstream/master' #63

Workflow file for this run

name: Release
on:
push:
branches:
- master
jobs:
release:
runs-on: ubuntu-latest
if: startsWith(github.event.head_commit.message, 'release:')
strategy:
max-parallel: 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate release commit message format
run: |
COMMIT_MSG="${{ github.event.head_commit.message }}"
echo "Commit message: $COMMIT_MSG"
# 使用正则表达式验证格式: release: x.x.x-xxx (其中 -xxx 是可选的)
if echo "$COMMIT_MSG" | grep -qE "^release:\s*[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(\s|$)"; then
echo "✅ Commit message format is valid for release"
else
echo "❌ Commit message format is invalid. Expected format: 'release: x.x.x' or 'release: x.x.x-xxx'"
echo "Examples:"
echo " - release: 1.0.0"
echo " - release: 2.1.3-alpha"
echo " - release: 1.5.0-beta1"
exit 1
fi
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Install pip dependencies
run: |
pip3 install semver luadata
- name: Install apt dependencies
run: |
sudo rm -f /var/lib/man-db/auto-update
sudo apt install --no-install-recommends lua5.1 p7zip-full
- name: Set up Git user
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Write secret to file
run: |
cat > secret.jx3dat << 'EOF'
${{ secrets.SECRET_JX3DAT }}
EOF
- name: Run Release Command
run: |
python3 \!src-dist/release.py --skip-branch-check
- name: Run Build Command
run: |
python3 \!src-dist/ci.py
- name: Get tag from Base.lua
id: get_tag
run: |
VERSION=$(grep "local _VERSION_" "MY_!Base/src/lib/Base.lua" | sed -n "s/local _VERSION_.*= *['\"]\\([^'\"]*\\)['\"].*/\\1/p")
if [ -z "$VERSION" ]; then
echo "Error: Could not extract version from Base.lua"
exit 1
fi
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Generate release notes
id: release_notes
run: |
TAG="${{ steps.get_tag.outputs.tag }}"
# 获取tag的完整注释信息
TAG_MESSAGE=$(git tag -l --format='%(contents)' "$TAG")
if [ -z "$TAG_MESSAGE" ]; then
echo "Error: No tag message found for $TAG"
echo "Please create tag with proper release notes"
exit 1
fi
echo "Found tag message for $TAG"
# 提取从 "Release vX.X.X" 开始的所有内容作为release notes
RELEASE_NOTES=$(echo "$TAG_MESSAGE" | sed -n '/^Release v/,$p')
if [ -z "$RELEASE_NOTES" ]; then
# 如果没有找到 "Release v" 开头的内容,使用整个tag消息
RELEASE_NOTES="$TAG_MESSAGE"
fi
# 设置release notes(只使用tag内容)
{
echo "release_notes<<EOF"
echo "$RELEASE_NOTES"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.tag }}
release_name: Release ${{ steps.get_tag.outputs.tag }}
body: ${{ steps.release_notes.outputs.release_notes }}
draft: false
prerelease: false
- name: Upload Release Assets
run: |
TAG="${{ steps.get_tag.outputs.tag }}"
UPLOAD_URL="${{ steps.create_release.outputs.upload_url }}"
# 上传所有.7z文件到release
for file in \!src-dist/dist/*.7z; do
if [ -f "$file" ]; then
filename=$(basename "$file")
echo "Uploading $filename to release $TAG..."
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$file" \
"${UPLOAD_URL%\{*}?name=$filename"
fi
done