84 lines
2.6 KiB
YAML
84 lines
2.6 KiB
YAML
name: Release Build
|
||
on:
|
||
push:
|
||
tags: ['*']
|
||
workflow_dispatch:
|
||
inputs:
|
||
version:
|
||
description: '版本号'
|
||
required: true
|
||
|
||
jobs:
|
||
build:
|
||
runs-on: ubuntu
|
||
container:
|
||
image: ubuntu:22.04
|
||
|
||
steps:
|
||
# 1. 安装xmake(修复语法错误)
|
||
- name: 安装xmake
|
||
run: |
|
||
curl -fsSL https://xmake.io/shget.text -o install.sh
|
||
bash install.sh
|
||
echo "$HOME/.local/bin" >> $GITHUB_PATH
|
||
|
||
# 2. 检出代码
|
||
- name: 检出代码
|
||
run: |
|
||
git clone https://git.fig-lang.cn/${{ github.repository }} .
|
||
git checkout ${{ github.ref }}
|
||
|
||
# 3. 设置版本
|
||
- name: 设置版本
|
||
run: |
|
||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||
VERSION="${{ inputs.version }}"
|
||
else
|
||
VERSION="${GITHUB_REF#refs/tags/}"
|
||
fi
|
||
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
||
echo "构建版本: $VERSION"
|
||
|
||
# 4. 构建
|
||
- name: 构建
|
||
run: |
|
||
export PATH="$HOME/.local/bin:$PATH"
|
||
xmake f -p linux -a x86_64 -m release -y
|
||
xmake build -j$(nproc)
|
||
|
||
# 5. 打包
|
||
- name: 打包
|
||
run: |
|
||
export PATH="$HOME/.local/bin:$PATH"
|
||
DIR="Fig-${{ env.VERSION }}-linux-x86_64"
|
||
mkdir -p "$DIR"
|
||
cp build/linux/x86_64/release/Fig "$DIR/"
|
||
[ -d "src/Module/Library" ] && cp -r src/Module/Library "$DIR/"
|
||
tar -czf "$DIR.tar.gz" "$DIR"
|
||
sha256sum "$DIR.tar.gz" > "$DIR.sha256"
|
||
|
||
# 6. 发布
|
||
- name: 发布
|
||
env:
|
||
TOKEN: ${{ secrets.CI_TOKEN }}
|
||
run: |
|
||
export PATH="$HOME/.local/bin:$PATH"
|
||
VERSION="${{ env.VERSION }}"
|
||
API="https://git.fig-lang.cn/api/v1/repos/${{ github.repository }}"
|
||
|
||
curl -sS -X POST -H "Authorization: token $TOKEN" \
|
||
-H "Content-Type: application/json" \
|
||
-d "{\"tag_name\":\"$VERSION\"}" \
|
||
"$API/releases" 2>/dev/null || true
|
||
|
||
curl -sS -X POST -H "Authorization: token $TOKEN" \
|
||
-H "Content-Type: application/octet-stream" \
|
||
--data-binary @Fig-$VERSION-linux-x86_64.tar.gz \
|
||
"$API/releases/$VERSION/assets?name=Fig-$VERSION-linux-x86_64.tar.gz"
|
||
|
||
curl -sS -X POST -H "Authorization: token $TOKEN" \
|
||
-H "Content-Type: text/plain" \
|
||
--data-binary @Fig-$VERSION-linux-x86_64.sha256 \
|
||
"$API/releases/$VERSION/assets?name=Fig-$VERSION-linux-x86_64.sha256"
|
||
|
||
echo "✅ 发布完成!" |