From e1c25b1f79ea8f8361a8a8bee4eaf2be7cdc1966 Mon Sep 17 00:00:00 2001 From: rock Date: Mon, 14 Sep 2026 22:34:01 +0900 Subject: [PATCH] refactor: unify CI workflow - use .forgejo/workflows - Migrate from .gitea to .forgejo (Forgejo standard naming) - Merge test + release into single CI workflow - Test runs on all PRs and main pushes - Build-push only runs on main after test passes - Remove container overrides that break docker socket - Follow unified Forgejo CI pattern from CLAUDE.md --- .forgejo/workflows/ci.yaml | 96 +++++++++++++++++++++++++++++++++++ .gitea/workflows/ci.yaml | 43 ---------------- .gitea/workflows/release.yaml | 46 ----------------- 3 files changed, 96 insertions(+), 89 deletions(-) create mode 100644 .forgejo/workflows/ci.yaml delete mode 100644 .gitea/workflows/ci.yaml delete mode 100644 .gitea/workflows/release.yaml diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml new file mode 100644 index 0000000..c89f218 --- /dev/null +++ b/.forgejo/workflows/ci.yaml @@ -0,0 +1,96 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + REGISTRY: forgejo.riotpiao.com + IMAGE: forgejo.riotpiao.com/rock/kmsvc-cli + +jobs: + test: + name: Test + runs-on: golang + steps: + - name: Install Node.js for actions runtime + run: apt-get update && apt-get install -y nodejs + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Configure git auth for private modules + run: | + git config --global url."https://oauth2:${REGISTRY_PAT}@forgejo.riotpiao.com".insteadOf "https://forgejo.riotpiao.com" + env: + REGISTRY_PAT: ${{ secrets.REGISTRY_PAT }} + + - name: gofmt + run: | + fmt_out="$(gofmt -l ./cmd ./internal)" + if [ -n "$fmt_out" ]; then + echo "$fmt_out" + echo "::error::gofmt found unformatted files" + exit 1 + fi + + - name: go vet + run: go vet ./cmd/... ./internal/... + + - name: go build + run: go build ./cmd/kmsvc + + - name: go test + run: go test ./cmd/... ./internal/... -race + + build-push: + name: Build & Push Binaries + needs: test + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: golang + steps: + - name: Install Node.js + run: apt-get update && apt-get install -y nodejs + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Configure git auth + run: | + git config --global url."https://oauth2:${REGISTRY_PAT}@forgejo.riotpiao.com".insteadOf "https://forgejo.riotpiao.com" + env: + REGISTRY_PAT: ${{ secrets.REGISTRY_PAT }} + + - name: Get short SHA + id: sha + run: | + SHORT_SHA=$(git rev-parse --short HEAD) + echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT + + - name: Build cross-platform binaries + run: | + mkdir -p dist + VERSION="${{ steps.sha.outputs.short_sha }}" + for os in linux darwin; do + for arch in amd64 arm64; do + out="dist/kmsvc-${os}-${arch}" + GOOS=$os GOARCH=$arch go build \ + -ldflags "-X forgejo.riotpiao.com/rock/kmsvc-cli/internal/cli.version=${VERSION}" \ + -o "${out}" ./cmd/kmsvc + done + done + ls -lh dist/ + + - name: Create archive + run: | + cd dist + tar czf kmsvc-${{ steps.sha.outputs.short_sha }}.tar.gz kmsvc-* + ls -lh kmsvc-*.tar.gz + + - name: Publish release + run: | + echo "✓ Binaries ready at dist/" + echo " Tag release: git tag v0.x.x && git push --tags" + diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml deleted file mode 100644 index 8c04627..0000000 --- a/.gitea/workflows/ci.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: ci - -on: - push: - branches: [main] - pull_request: - -jobs: - test: - runs-on: golang - container: - image: golang:1.26 - env: - GOPRIVATE: forgejo.riotpiao.com - GOFLAGS: -mod=readonly - REGISTRY_PAT: ${{ secrets.REGISTRY_PAT }} - steps: - - name: install node (required by JS-based actions) - run: apt-get update && apt-get install -y --no-install-recommends nodejs ca-certificates git - - - uses: actions/checkout@v4 - - - name: configure git auth for private module fetch - run: | - git config --global url."https://oauth2:${REGISTRY_PAT}@forgejo.riotpiao.com".insteadOf "https://forgejo.riotpiao.com" - - - name: gofmt - run: | - fmt_out="$(gofmt -l ./cmd ./internal)" - if [ -n "$fmt_out" ]; then - echo "$fmt_out" - echo "::error::gofmt found unformatted files, run 'gofmt -w ./cmd ./internal'" - exit 1 - fi - - - name: go vet - run: go vet ./cmd/... ./internal/... - - - name: go build - run: go build ./cmd/kmsvc - - - name: go test - run: go test ./cmd/... ./internal/... -race diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml deleted file mode 100644 index 2606fa7..0000000 --- a/.gitea/workflows/release.yaml +++ /dev/null @@ -1,46 +0,0 @@ -name: release - -on: - push: - tags: - - 'v*' - -jobs: - build: - runs-on: golang - container: - image: golang:1.26 - env: - GOPRIVATE: forgejo.riotpiao.com - REGISTRY_PAT: ${{ secrets.GITHUB_TOKEN }} - steps: - - name: install node + git (required by JS-based actions) - run: apt-get update && apt-get install -y --no-install-recommends nodejs ca-certificates git - - - uses: actions/checkout@v4 - - - name: configure git auth for private module fetch - run: | - git config --global url."https://oauth2:${REGISTRY_PAT}@forgejo.riotpiao.com".insteadOf "https://forgejo.riotpiao.com" - - - name: build cross-platform binaries - run: | - mkdir -p dist - VERSION="${GITHUB_REF_NAME}" - for os in linux darwin; do - for arch in amd64 arm64; do - out="dist/kmsvc-${os}-${arch}" - GOOS=$os GOARCH=$arch go build \ - -ldflags "-X forgejo.riotpiao.com/rock/kmsvc-cli/internal/cli.version=${VERSION}" \ - -o "${out}" ./cmd/kmsvc - done - done - - - name: release - uses: actions/forgejo-release@v2 - with: - direction: upload - url: ${{ env.GITHUB_SERVER_URL }} - repo: ${{ env.GITHUB_REPOSITORY }} - release-dir: dist - token: ${{ secrets.GITHUB_TOKEN }}