Files
Fig-TreeWalker/.gitea/workflows/build.yml
2026-01-03 15:27:25 +08:00

105 lines
3.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Release Build
on:
push:
tags: ['*']
workflow_dispatch:
inputs:
version:
description: '版本号 (如v1.0.0)'
required: true
default: 'dev-build'
jobs:
build:
runs-on: ubuntu
container:
image: alpine:latest
options: >-
--dns 223.5.5.5
--dns 223.6.6.6
steps:
# 1. 安装依赖 (使用阿里云镜像加速)
- name: 安装依赖
run: |
sed -i 's|dl-cdn.alpinelinux.org|mirrors.aliyun.com|g' /etc/apk/repositories
apk update --no-cache
apk add --no-cache gcc g++ make musl-dev linux-headers curl wget tar git
echo "依赖安装完成"
# 2. 安装xmake (使用wget避免bash依赖)
- name: 安装xmake
run: |
wget -q https://xmake.io/shget.text -O /tmp/xmake-install.sh
sh /tmp/xmake-install.sh
export PATH="/root/.local/bin:$PATH"
xmake --version
# 3. 检出代码
- name: 检出代码
run: |
git clone https://git.fig-lang.cn/${{ github.repository }} . --depth=1
git checkout ${{ github.ref }}
# 4. 设置版本
- name: 设置版本
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ inputs.version }}" >> $GITHUB_ENV
else
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
fi
echo "构建版本: ${{ env.VERSION }}"
# 5. 构建项目
- name: 构建项目
run: |
export PATH="/root/.local/bin:$PATH"
xmake f -p linux -a x86_64 -m release -y
xmake build -j$(nproc)
# 6. 打包文件
- name: 打包文件
run: |
PACKAGE_DIR="Fig-${{ env.VERSION }}-linux-x86_64"
mkdir -p "$PACKAGE_DIR"
cp build/linux/x86_64/release/Fig "$PACKAGE_DIR/"
# 如果有Library目录则复制
if [ -d "src/Module/Library" ]; then
cp -r src/Module/Library "$PACKAGE_DIR/"
fi
tar -czf "$PACKAGE_DIR.tar.gz" "$PACKAGE_DIR"
sha256sum "$PACKAGE_DIR.tar.gz" > "$PACKAGE_DIR.sha256"
# 7. 发布到Gitea
- name: 发布到Gitea
env:
GITEA_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
VERSION="${{ env.VERSION }}"
REPO_URL="https://git.fig-lang.cn/api/v1/repos/${{ github.repository }}"
# 创建发布
curl -sSf -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"$VERSION\",\"name\":\"Fig $VERSION\"}" \
"$REPO_URL/releases" 2>/dev/null || echo "Release可能已存在"
# 上传主文件
curl -sSf -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @Fig-$VERSION-linux-x86_64.tar.gz \
"$REPO_URL/releases/$VERSION/assets?name=Fig-$VERSION-linux-x86_64.tar.gz"
# 上传校验文件
curl -sSf -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: text/plain" \
--data-binary @Fig-$VERSION-linux-x86_64.sha256 \
"$REPO_URL/releases/$VERSION/assets?name=Fig-$VERSION-linux-x86_64.sha256"
echo "✅ 发布完成!文件: Fig-$VERSION-linux-x86_64.tar.gz"