Files
Fig-TreeWalker/.gitea/workflows/build.yml
PuqiAR 66c391fe06
Some checks failed
Release Build / build-linux-x64 (push) Successful in 22s
Release Build / build-windows-x64 (push) Failing after 6s
[Action] Windows也来构建!
2026-01-03 20:22:34 +08:00

169 lines
6.2 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-linux-x64:
runs-on: ubuntu
container:
image: git.fig-lang.cn/puqiar/fig-ci:base-latest
options: --network=host
steps:
- name: 验证构建环境
run: |
echo "=== 环境验证开始 ==="
xmake --version
clang++ --version | head -1
echo "=== 环境验证通过 ==="
- name: 检出代码
run: |
git clone https://git.fig-lang.cn/${{ github.repository }} .
git checkout ${{ github.ref }}
- name: 设置版本
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
echo "构建版本: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: 构建项目 (Linux)
run: |
echo "开始构建Linux版本..."
xmake f -p linux -a x86_64 -m release -y
xmake build -j$(nproc)
echo "Linux构建成功。"
- name: 打包Linux发布文件
run: |
PACKAGE_NAME="Fig-${{ env.VERSION }}-linux-x86_64"
mkdir -p "${PACKAGE_NAME}"
cp build/linux/x86_64/release/Fig "${PACKAGE_NAME}/"
if [ -d "src/Module/Library" ]; then
cp -r src/Module/Library "${PACKAGE_NAME}/"
echo "已包含Library目录。"
fi
tar -czf "${PACKAGE_NAME}.tar.gz" "${PACKAGE_NAME}"
sha256sum "${PACKAGE_NAME}.tar.gz" > "${PACKAGE_NAME}.sha256"
echo "Linux打包完成: ${PACKAGE_NAME}.tar.gz"
- name: 发布Linux版本到Gitea
env:
GITEA_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
VERSION="${{ env.VERSION }}"
API="https://git.fig-lang.cn/api/v1/repos/${{ github.repository }}"
echo "正在为Linux版本创建/更新发布 $VERSION ..."
# 创建发布 (如果已存在,忽略错误)
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"$VERSION\",\"name\":\"Fig $VERSION\",\"draft\":false,\"prerelease\":false}" \
"$API/releases" 2>/dev/null || echo "发布已存在,继续上传..."
curl -sS -X POST -H "Authorization: token $GITEA_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 $GITEA_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 "✅ Linux版本发布完成"
build-windows-x64:
runs-on: ubuntu
container:
image: git.fig-lang.cn/puqiar/fig-ci:base-latest
options: --network=host
steps:
- name: 验证环境
run: |
echo "=== Windows构建环境验证 ==="
xmake --version
clang++ --version | head -1
echo "环境就绪。"
- name: 检出代码
run: |
git clone https://git.fig-lang.cn/${{ github.repository }} .
git checkout ${{ github.ref }}
- name: 设置版本
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
echo "Windows构建版本: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: 构建项目 (Windows x64)
run: |
echo "开始交叉编译Windows版本..."
# 关键使用mingw平台指定clang工具链进行交叉编译
xmake f -p mingw -a x86_64 -m release -y --toolchain=clang
xmake build -j$(nproc)
echo "Windows构建成功。"
- name: 打包Windows发布文件
run: |
PACKAGE_NAME="Fig-${{ env.VERSION }}-windows-x86_64"
mkdir -p "${PACKAGE_NAME}"
# 注意Windows可执行文件路径根据你的xmake配置调整
# 尝试多种可能的输出路径
if [ -f "build/mingw/x86_64/release/Fig.exe" ]; then
cp build/mingw/x86_64/release/Fig.exe "${PACKAGE_NAME}/"
elif [ -f "build/mingw/x86_64/release/Fig" ]; then
cp build/mingw/x86_64/release/Fig "${PACKAGE_NAME}/Fig.exe"
else
echo "错误未找到Windows构建输出文件"
find build/ -name "Fig*" -type f | head -5
exit 1
fi
if [ -d "src/Module/Library" ]; then
cp -r src/Module/Library "${PACKAGE_NAME}/"
fi
zip -r "${PACKAGE_NAME}.zip" "${PACKAGE_NAME}"
sha256sum "${PACKAGE_NAME}.zip" > "${PACKAGE_NAME}.sha256"
echo "Windows打包完成: ${PACKAGE_NAME}.zip"
- name: 发布Windows版本到Gitea
env:
GITEA_TOKEN: ${{ secrets.CI_TOKEN }}
run: |
VERSION="${{ env.VERSION }}"
API="https://git.fig-lang.cn/api/v1/repos/${{ github.repository }}"
echo "正在上传Windows版本到发布 $VERSION ..."
# 直接上传到同一个ReleaseRelease已由Linux任务创建
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @Fig-$VERSION-windows-x86_64.zip \
"$API/releases/$VERSION/assets?name=Fig-$VERSION-windows-x86_64.zip"
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: text/plain" \
--data-binary @Fig-$VERSION-windows-x86_64.sha256 \
"$API/releases/$VERSION/assets?name=Fig-$VERSION-windows-x86_64.sha256"
echo "✅ Windows版本发布完成"