Files
spark-mcp/.github/workflows/build.yml
T
tao.chenandClaude 160c9f32c8
CI / Release / CI (push) Failing after 44s
CI / Release / Release (push) Has been skipped
ci: 用 git clone 替换 actions/checkout (alpine 无 Node)
alpine golang-1.25 镜像没装 Node, actions/checkout@v4 启动失败:

  Run Checkout
  OCI runtime exec failed: exec failed: unable to start container
  process: exec: "node": executable file not found in \$PATH: unknown

actions/checkout 是 Node.js 应用, Gitea alpine runner 镜像不
带 Node. 改用 git clone 手写 checkout step:

  git clone --depth 1 "\${{ github.server_url }}/\${{ github.repository }}.git" .

shallow clone (\$depth 1) 减少传输量, \${{ github.server_url }} 自动
填入 Gitea 实例 URL, \${{ github.repository }} 是 owner/repo 路径.

这个 runner 应该跟 Gitea 在同一网络, 仓库公开, 不需要 auth
token. 如果将来换 runner 跨网络或者仓库私有, 改成:

  git clone --depth 1 \\
    -c http.extraHeader="Authorization: token \$GITEA_TOKEN" \\
    "\${{ github.server_url }}/\${{ github.repository }}.git" .

GITEA_TOKEN 走 \${{ secrets.GITHUB_TOKEN }} (Gitea 自动注入).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-15 18:45:31 +08:00

131 lines
4.6 KiB
YAML

# This workflow runs on Gitea Actions, which is API-compatible with GitHub Actions.
# It performs CI on every push to main and every pull request, and automatically
# builds and attaches a Linux amd64 release binary when a version tag (v*) is pushed.
#
# Runner: golang-1.25 (Gitea-managed image, alpine + Go 1.25 preinstalled).
# No Go installation step needed. GOPROXY is set explicitly to use the
# China-region mirrors (default alpine GOPROXY is proxy.golang.org, which
# is slow from this runner's network).
name: CI / Release
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
jobs:
ci:
name: CI
runs-on: golang-1.25
steps:
- name: Checkout
run: |
# Manual git checkout — actions/checkout needs Node, which the
# alpine golang-1.25 image doesn't have.
# Gitea runner doesn't expose a token for clone in the usual
# way; for a same-network runner the repo URL is enough.
git clone --depth 1 "${{ github.server_url }}/${{ github.repository }}.git" .
- name: Set GOPROXY
run: |
echo "GOPROXY=https://goproxy.cn/,https://goproxy.io,direct" >> $GITHUB_ENV
- name: Build
run: go build ./...
- name: Vet
run: go vet ./...
- name: Test
run: go test ./...
- name: Check formatting
run: |
if [ -n "$(gofmt -l .)" ]; then
gofmt -l .
exit 1
fi
- name: Notify CI via Bark
if: always()
run: |
REF_NAME="${{ github.ref_name }}"
STATUS="${{ job.status }}"
if [ "${STATUS}" = "success" ]; then
EMOJI="✅"
else
EMOJI="❌"
fi
BODY="${EMOJI} ${REF_NAME} ${STATUS}: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${{ github.run_id }}"
bash .github/scripts/bark-notify.sh "CI ${REF_NAME} ${STATUS}" "${BODY}"
release:
name: Release
needs: ci
if: startsWith(github.ref, 'refs/tags/v')
runs-on: golang-1.25
steps:
- name: Checkout
run: |
# Manual git checkout — actions/checkout needs Node, which the
# alpine golang-1.25 image doesn't have.
git clone --depth 1 "${{ github.server_url }}/${{ github.repository }}.git" .
- name: Set GOPROXY
run: |
echo "GOPROXY=https://goproxy.cn/,https://goproxy.io,direct" >> $GITHUB_ENV
- name: Build release binary
run: GOOS=linux GOARCH=amd64 go build -o spark-mcp-linux-amd64 ./main.go
- name: Upload release asset via Gitea API
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# 1. 获取当前 Tag 名字 (例如 v0.0.1-beta)
TAG_NAME="${{ github.ref_name }}"
echo "正在为 Tag ${TAG_NAME} 创建 Gitea Release..."
# 2. 调用 Gitea API 创建一个 Release 并获取其 ID
# 注意:${{ github.api_url }} 会自动解析为你本地 Gitea 的 API 地址 (如 http://your-gitea/api/v1)
# alpine busybox grep 不支持 -P (PCRE), 改用两次 grep -o 拆 id
RELEASE_ID=$(curl -X POST "${{ github.api_url }}/repos/${{ github.repository }}/releases" \
-H "accept: application/json" \
-H "authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"${TAG_NAME}\",
\"target_commitish\": \"${{ github.sha }}\",
\"name\": \"Release ${TAG_NAME}\",
\"body\": \"Auto generated release assets.\",
\"draft\": false,
\"prerelease\": false
}" | grep -o '"id":[0-9]*' | head -n 1 | grep -o '[0-9]*')
echo "Release 创建成功,ID 为: ${RELEASE_ID}"
# 3. 将你的二进制文件上传到该 Release 中
echo "开始上传文件 spark-mcp-linux-amd64 ..."
curl -X POST "${{ github.api_url }}/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
-H "accept: application/json" \
-H "authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: multipart/form-data" \
-F "attachment=@spark-mcp-linux-amd64"
- name: Notify release via Bark
if: always()
run: |
TITLE="${{ github.ref_name }}"
STATUS="${{ job.status }}"
if [ "${STATUS}" = "success" ]; then
EMOJI="✅"
else
EMOJI="❌"
fi
BODY="${EMOJI} spark-mcp ${TITLE} ${STATUS}: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/releases/tag/${TITLE}"
bash .github/scripts/bark-notify.sh "${TITLE} ${STATUS}" "${BODY}"