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

108 lines
3.4 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: '版本号'
required: true
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 --virtual .build-deps \
gcc \
g++ \
make \
musl-dev \
linux-headers \
curl \
tar
echo "✅ 依赖安装完成耗时约30秒"
# 2. 并行安装xmake不等待git
- name: ⚡ 安装xmake
run: |
curl --retry 3 --connect-timeout 10 -fsSL https://xmake.io/shget.text | bash
echo "/root/.local/bin" >> $GITHUB_PATH
/root/.local/bin/xmake --version
# 3. 获取代码使用act内置的检出机制
- name: 📦 获取代码
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
ref: ${{ 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: |
xmake f -p linux -a x86_64 -m release -y
xmake build -j$(nproc)
# 6. 打包
- name: 📦 打包文件
run: |
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"
ls -lh Fig-*
# 7. 发布
- name: 📤 发布到Gitea
env:
TOKEN: ${{ secrets.CI_TOKEN }}
run: |
VERSION="${{ env.VERSION }}"
API="https://git.fig-lang.cn/api/v1/repos/${{ github.repository }}"
# 快速发布
curl -m 30 -sSf -X POST \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"$VERSION\"}" \
"$API/releases" 2>/dev/null || true
# 快速上传
curl -m 60 -sSf -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 -m 30 -sSf -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 "✅ 发布完成!"