Files
xxxigcc/.gitea/workflows/ci.yaml
Wang Defa 8100b2f2e5
All checks were successful
Build and Release / build-and-test (arm64, alpine) (push) Successful in 7s
Build and Release / build-and-test (arm64, ubuntu) (push) Successful in 7s
Build and Release / build-and-test (amd64, alpine) (push) Successful in 14s
Build and Release / build-and-test (amd64, ubuntu) (push) Successful in 22s
Build and Release / docker-images (push) Successful in 39s
Build and Release / release (push) Successful in 47s
修改 PACKAGE_VERSION
2025-12-02 14:56:36 +08:00

262 lines
9.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.
# .gitea/workflows/ci.yaml
name: Build and Release
on:
push:
branches: [main, develop]
tags: ['*']
env:
DOCKER_BUILDKIT: "1"
PRODUCT_NAME: "xxxigcc"
PACKAGE_VERSION: "3.4.6-xg2"
BUILDX_NO_DEFAULT_ATTESTATIONS: "1"
jobs:
build-and-test:
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest-amd64' || 'ubuntu-latest-arm64' }}
strategy:
matrix:
arch: [amd64, arm64]
distro: [ubuntu, alpine]
steps:
- uses: actions/checkout@v4
- name: Setup Docker Buildx
run: |
# 创建 buildx builder原生构建不需要 QEMU
docker buildx create --use --name native-builder \
--driver docker-container \
--driver-opt network=host \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=50000000 \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=10000000 \
|| true
docker buildx inspect --bootstrap
- name: Build binaries
run: |
XMRIGCC_VERSION=${PACKAGE_VERSION%-*}
PLATFORM="linux/${{ matrix.arch }}"
echo "🏗️ Building ${PLATFORM} on native ${{ matrix.arch }} runner"
echo "📦 Distribution: ${{ matrix.distro }}"
# 设置 BuildKit 优化参数
export BUILDKIT_PROGRESS=plain
docker buildx build --pull \
--platform ${PLATFORM} \
--build-arg XMRIGCC_VERSION=${XMRIGCC_VERSION} \
--output type=local,dest=./output \
-f docker/Dockerfile.${{ matrix.distro }} .
- name: Package and test
run: |
DIR="./output/linux_${{ matrix.arch }}"
if [ ! -d "$DIR" ]; then
echo "❌ 构建输出目录不存在: $DIR"
exit 1
fi
TARGZ="${PRODUCT_NAME}-${{ matrix.arch }}-${{ matrix.distro }}-${PACKAGE_VERSION}.tar.gz"
tar -czf "${TARGZ}" -C "$DIR" .
echo "📦 Created package: ${TARGZ}"
ls -lh "${TARGZ}"
# 快速验证
mkdir -p test && tar -xzf "${TARGZ}" -C test
test/xxxigDaemon --version 2>/dev/null || echo "⚠️ 跳过版本检查"
rm -rf test
- uses: https://github.com/ChristopherHX/gitea-upload-artifact@v4
with:
name: binaries-${{ matrix.arch }}-${{ matrix.distro }}
path: "*.tar.gz"
retention-days: 1
docker-images:
runs-on: ubuntu-latest-amd64
needs: build-and-test
if: github.ref_name == 'main' || github.ref_name == 'develop' || startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Debug branch info
run: |
echo "📋 Branch Information:"
echo " github.ref: ${{ github.ref }}"
echo " github.ref_name: ${{ github.ref_name }}"
echo " github.event_name: ${{ github.event_name }}"
- uses: https://github.com/ChristopherHX/gitea-download-artifact@v4
with:
pattern: binaries-*
path: ./app
merge-multiple: true
- name: Setup Docker and Login
run: |
# 尝试设置 QEMU忽略错误
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes 2>/dev/null || true
# 创建 buildx builder增加资源限制和优化参数
docker buildx create --use --name multiarch-builder \
--driver docker-container \
--driver-opt network=host \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=50000000 \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=10000000 \
--buildkitd-flags '--allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host' \
|| true
docker buildx inspect --bootstrap
# 登录
echo "${{ secrets.BUILD_TOKEN }}" | docker login ${{ gitea.server_url }} -u ${{ gitea.actor }} --password-stdin
- name: Determine Docker tag
id: tag
run: |
if [ "${{ github.ref_name }}" = "main" ]; then
TAG="latest"
elif [ "${{ github.ref_name }}" = "develop" ]; then
TAG="develop"
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAG="${{ github.ref_name }}"
else
TAG="${{ github.ref_name }}"
fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "📦 Docker tag: ${TAG}"
- name: Build and push Docker images
run: |
# 移除 URL 中的 https:// 前缀
REGISTRY=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||')/${{ gitea.repository }}
TAG="${{ steps.tag.outputs.tag }}"
echo "📦 Docker Registry: ${REGISTRY}"
echo "📦 Docker Tag: ${TAG}"
BUILD_ARGS="--pull --push --platform linux/amd64,linux/arm64 \
--build-arg TARGZ_FILE_AMD64=${PRODUCT_NAME}-amd64-alpine-${PACKAGE_VERSION}.tar.gz \
--build-arg TARGZ_FILE_ARM64=${PRODUCT_NAME}-arm64-alpine-${PACKAGE_VERSION}.tar.gz \
--provenance=false --sbom=false"
echo "🐳 Building server image..."
docker buildx build $BUILD_ARGS -t "${REGISTRY}/server:${TAG}" -f docker/Dockerfile.Server .
echo "🐳 Building daemon image..."
docker buildx build $BUILD_ARGS -t "${REGISTRY}/daemon:${TAG}" -f docker/Dockerfile.Daemon .
release:
runs-on: ubuntu-latest-amd64
needs: build-and-test
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: https://github.com/ChristopherHX/gitea-download-artifact@v4
with:
pattern: binaries-*
path: ./packages
merge-multiple: true
- name: Upload packages and create release
env:
TOKEN: ${{ secrets.BUILD_TOKEN }}
TAG: ${{ github.ref_name }}
run: |
cd packages
# 提取仓库信息(移除 https:// 前缀和仓库路径)
REGISTRY=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||')
OWNER="${{ gitea.repository_owner }}"
REPO_NAME=$(echo "${{ gitea.repository }}" | cut -d'/' -f2)
echo "📦 上传包到 Generic Package Registry..."
echo " Registry: ${REGISTRY}"
echo " Owner: ${OWNER}"
echo " Package: ${PRODUCT_NAME}"
echo " Version: ${TAG}"
# 上传所有包到 Generic Package Registry
for file in *.tar.gz; do
[ ! -f "$file" ] && continue
echo " ⬆️ $file"
curl -fsSL -X PUT \
-H "Authorization: token ${TOKEN}" \
--upload-file "$file" \
"https://${REGISTRY}/api/packages/${OWNER}/generic/${PRODUCT_NAME}/${TAG}/$file" || {
echo "❌ 上传失败: $file"
exit 1
}
done
# 生成 Release 描述(包含 Package Registry 和 Release 附件两种下载方式)
echo ""
echo "📝 生成 Release 描述..."
BODY="## Release ${TAG}\n\n"
BODY="${BODY}### 📥 下载方式\n\n"
BODY="${BODY}#### 方式 1: 直接下载(推荐)\n\n"
BODY="${BODY}点击下面 **Assets** 部分的文件名直接下载。\n\n"
BODY="${BODY}#### 方式 2: Package Registry\n\n"
for file in *.tar.gz; do
[ -f "$file" ] && BODY="${BODY}- [\`${file}\`](https://${REGISTRY}/api/packages/${OWNER}/generic/${PRODUCT_NAME}/${TAG}/${file})\n"
done
# 创建 Release
echo ""
echo "🎉 创建 Release..."
RESPONSE=$(curl -fsSL -w "\n%{http_code}" -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
"https://${REGISTRY}/api/v1/repos/${{ gitea.repository }}/releases" \
-d @- << EOF
{
"tag_name": "${TAG}",
"name": "Release ${TAG}",
"body": "${BODY}",
"draft": false,
"prerelease": false
}
EOF
)
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
RESPONSE_BODY=$(echo "$RESPONSE" | head -n-1)
if [ "$HTTP_CODE" = "201" ]; then
echo "✅ Release 创建成功"
RELEASE_ID=$(echo "$RESPONSE_BODY" | grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
echo " Release ID: ${RELEASE_ID}"
elif [ "$HTTP_CODE" = "409" ]; then
echo "⚠️ Release 已存在,获取现有 Release ID..."
RELEASE_ID=$(curl -fsSL \
-H "Authorization: token ${TOKEN}" \
"https://${REGISTRY}/api/v1/repos/${{ gitea.repository }}/releases/tags/${TAG}" | \
grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
echo " Release ID: ${RELEASE_ID}"
else
echo "❌ 创建 Release 失败 (HTTP ${HTTP_CODE})"
echo "$RESPONSE_BODY"
exit 1
fi
# 上传文件作为 Release 附件
echo ""
echo "📎 上传文件作为 Release 附件..."
for file in *.tar.gz; do
[ ! -f "$file" ] && continue
echo " ⬆️ $file"
# 使用 multipart/form-data 上传附件
curl -fsSL -X POST \
-H "Authorization: token ${TOKEN}" \
-F "attachment=@${file}" \
"https://${REGISTRY}/api/v1/repos/${{ gitea.repository }}/releases/${RELEASE_ID}/assets?name=${file}" || {
echo " ⚠️ 附件上传失败: $file可能已存在"
}
done
echo ""
echo "✅ Release 创建完成!"
echo "🔗 访问: https://${REGISTRY}/${{ gitea.repository }}/releases/tag/${TAG}"