# Beta 分支自动构建流水线 # # 触发:push 到 beta 分支 / PR 到 beta / 手动触发。 # 产出: # 1. 前端 + 后端编译验证(go vet / go test / go build) # 2. 多平台可执行二进制 artifact(linux/amd64、linux/arm64、windows/amd64) # 3. ghcr.io/{owner}/mebox:beta 多架构 Docker 镜像(linux/amd64 + linux/arm64) # # 与 main 分支的发布流(Auto-docker-publish.yml)隔离:beta 不做版本递增、 # 不打 release tag,只构建带 -beta 标识的产物供测试。 name: Beta Build on: push: branches: [beta] pull_request: branches: [beta] workflow_dispatch: permissions: contents: read packages: write env: BETA_VERSION_PREFIX: beta jobs: # ───────────────────────────────────────────────────────────────────────────── # 1) 编译验证 + 多平台二进制产物 # ───────────────────────────────────────────────────────────────────────────── test-and-build: name: Test & build artifacts runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Resolve beta version id: version run: | BASE_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0") SHA_SHORT=${GITHUB_SHA:0:7} echo "full_version=${BASE_VERSION}-beta.${SHA_SHORT}" >> "$GITHUB_OUTPUT" # The binary embeds the SPA (web/dist) via go:embed, so dist must exist # before the Go toolchain touches the web package. - uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' cache-dependency-path: web/package-lock.json - name: Build SPA working-directory: web run: | npm ci npm run build - uses: actions/setup-go@v5 with: go-version: '1.25' cache: true - name: go vet run: go vet ./... - name: go test run: go test ./... - name: go build (host) run: go build ./... # 多平台可执行文件(嵌入刚构建的 web/dist) - name: Build linux/amd64 run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w -X main.version=${{ steps.version.outputs.full_version }}" -o dist/mebox-beta-linux-amd64 ./cmd/server - name: Build linux/arm64 run: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags="-s -w -X main.version=${{ steps.version.outputs.full_version }}" -o dist/mebox-beta-linux-arm64 ./cmd/server - name: Build windows/amd64 run: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags="-s -w -X main.version=${{ steps.version.outputs.full_version }}" -o dist/mebox-beta-windows-amd64.exe ./cmd/server - name: Upload artifacts uses: actions/upload-artifact@v4 with: name: mebox-beta-binaries path: dist/* if-no-files-found: error # ───────────────────────────────────────────────────────────────────────────── # 2) Beta Docker 镜像(ghcr.io/{owner}/mebox:beta) # ───────────────────────────────────────────────────────────────────────────── docker-beta: name: Build & push beta Docker image needs: test-and-build runs-on: ubuntu-latest # PR 事件不推送镜像,仅 push beta / 手动触发时推送 if: github.event_name != 'pull_request' steps: - uses: actions/checkout@v4 - name: Resolve beta version id: version run: | BASE_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0") SHA_SHORT=${GITHUB_SHA:0:7} echo "full_version=${BASE_VERSION}-beta.${SHA_SHORT}" >> "$GITHUB_OUTPUT" - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - name: Log in to GHCR uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build & push uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64 push: true provenance: false sbom: false tags: ghcr.io/${{ github.repository_owner }}/mebox:beta labels: | org.opencontainers.image.revision=${{ github.sha }} org.opencontainers.image.source=${{ github.repository }} build-args: | VERSION=${{ steps.version.outputs.full_version }} cache-from: type=gha cache-to: type=gha,mode=max