chore(go): golangci-lint 静态分析门禁——11 linter 接入 + 修复 83 处问题 #40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test Build | |
| on: | |
| push: | |
| branches: [main-go] | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| # ── Build Docker images (tagged with commit SHA) ── | |
| docker: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| matrix: | |
| target: [prod, dev] | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=sha,prefix=${{ matrix.target }}- | |
| type=raw,value=${{ matrix.target }}-edge | |
| - name: Build & push | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| target: ${{ matrix.target }} | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| platforms: linux/amd64 | |
| # ── Build migrate binaries ── | |
| migrate: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| goos: [linux, darwin] | |
| goarch: [amd64, arm64] | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: stable | |
| cache-dependency-path: vault/go.sum | |
| - name: Build | |
| working-directory: vault | |
| env: | |
| GOPROXY: direct | |
| GONOSUMDB: "*" | |
| run: | | |
| GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} CGO_ENABLED=0 \ | |
| go build -ldflags="-s -w" -o bin/migrate-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/migrate | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: migrate-${{ matrix.goos }}-${{ matrix.goarch }} | |
| path: vault/bin/migrate-* | |
| retention-days: 7 | |
| # ── Lint Go backend (go vet -all + golangci-lint gate) ── | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version: stable | |
| cache-dependency-path: vault/go.sum | |
| - name: go vet -all | |
| working-directory: vault | |
| run: go vet -all ./... | |
| - name: golangci-lint | |
| uses: golangci/golangci-lint-action@v6 | |
| with: | |
| version: v1.64.8 | |
| working-directory: vault | |
| args: run ./... |