diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb81c9bc..c29f743f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,76 +1,14 @@ -name: CI - -on: - push: - branches: [master, main] - tags: ["v*"] - pull_request: - branches: [master, main] - workflow_dispatch: - +name: ci +on: [push, pull_request, repository_dispatch] jobs: - # ── 编译 + 静态检查 ────────────────────────────────────────────────────── build: - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: "1.24" - - run: go mod tidy - - run: go build ./... - - # ── tutorial 集成测试(需要 Redis)──────────────────────────────────────── - tutorial-test: - runs-on: ubuntu-latest - services: - redis: - image: redis:7-alpine - ports: - - 6379:6379 - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: "1.24" - - run: go mod tidy - - run: go build -o kvlang ./cmd/kvlang/ - - run: go install github.com/array2d/kvspace-go/cmd/kvspace@latest - - run: python3 -m unittest tutorial.test.BenchmarkTest - - run: python3 tutorial/test.py - - # ── 多平台交叉编译(仅 tag 时生成 release 产物)───────────────────────── - release: - if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: "1.24" - - - name: Cross-compile - run: | - go mod tidy - mkdir -p dist - for GOOS in linux darwin; do - for GOARCH in amd64 arm64; do - echo "Building $GOOS/$GOARCH..." - GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w" -o dist/kvlang-$GOOS-$GOARCH ./cmd/kvlang/ - done - done - ls -lh dist/ - - - name: Create Release - uses: softprops/action-gh-release@v2 - with: - files: dist/* - generate_release_notes: true + - name: 下载 ABI 依赖 + env: { GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" } + run: ./ci/deps.sh + - name: 构建 + run: make runtime layout + - name: 测试 + run: python3 tutorial/test.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..742adcf0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: release-abi +on: + push: + tags: ['v*'] +permissions: + contents: write +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: 下载 ABI 依赖 + env: { GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" } + run: ./ci/deps.sh + - name: 构建 runtime + layout + run: make runtime layout + - name: 打包 ABI 产物 + run: | + set -euo pipefail + v="${GITHUB_REF_NAME}" + d="kvlang-abi-$v-linux-x86_64" + mkdir -p "$d/include" "$d/lib" + cp runtime/include/*.h "$d/include/" + cp bin/libkvlang_runtime.so "$d/lib/" + cp layout/target/release/libkvlang_layout.so "$d/lib/" + printf '{"abi":"%s"}\n' "$v" > "$d/abi-manifest.json" + tar czf "$d.tar.gz" "$d" + sha256sum "$d.tar.gz" > SHA256SUMS + - name: 发布 release + run: gh release create "${GITHUB_REF_NAME}" kvlang-abi-*.tar.gz SHA256SUMS --generate-notes diff --git a/ci/deps.sh b/ci/deps.sh new file mode 100755 index 00000000..e3a8ff0d --- /dev/null +++ b/ci/deps.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# 下载 ABI 依赖(deps.json: repo → tag)到 libso/。本地与 CI 共用。 +# 需 gh 已登录;CI 中 GH_TOKEN 自动可用。 +set -euo pipefail +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +mkdir -p "$ROOT/libso" +for repo in $(jq -r 'keys[]' "$ROOT/deps.json"); do + ver=$(jq -r ".\"$repo\"" "$ROOT/deps.json") + tmp="$(mktemp -d)" + gh release download "$ver" -R "array2d/$repo" -p "${repo}-abi-*-linux-x86_64.tar.gz" -D "$tmp" + tar xzf "$tmp"/*.tar.gz -C "$ROOT/libso" + rm -rf "$tmp" +done +echo "✅ ABI deps → libso/: $(ls "$ROOT/libso" 2>/dev/null | tr '\n' ' ')" diff --git a/deps.json b/deps.json new file mode 100644 index 00000000..425172e2 --- /dev/null +++ b/deps.json @@ -0,0 +1,4 @@ +{ + "kvspace-c": "v0.2.0", + "kvspace-durable": "v0.2.0" +}