Skip to content

Commit 09bfea0

Browse files
committed
ref main
1 parent 397f2a0 commit 09bfea0

48 files changed

Lines changed: 1899 additions & 852 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- 'v*'
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
include:
16+
- goos: linux
17+
goarch: amd64
18+
- goos: linux
19+
goarch: arm64
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version-file: 'go.mod'
30+
31+
- name: Build
32+
env:
33+
GOOS: ${{ matrix.goos }}
34+
GOARCH: ${{ matrix.goarch }}
35+
CGO_ENABLED: '0'
36+
run: |
37+
VERSION=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo dev)
38+
REVISION=$(git rev-parse HEAD)
39+
BUILTAT=$(date +%Y-%m-%dT%H:%M:%S)
40+
LDFLAGS="-s -X github.com/projecteru2/cocoon/version.VERSION=${VERSION} \
41+
-X github.com/projecteru2/cocoon/version.REVISION=${REVISION} \
42+
-X github.com/projecteru2/cocoon/version.BUILTAT=${BUILTAT}"
43+
go build -ldflags "${LDFLAGS}" -o cocoon-${{ matrix.goos }}-${{ matrix.goarch }} .
44+
45+
- name: Upload binary artifact
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: cocoon-${{ matrix.goos }}-${{ matrix.goarch }}
49+
path: cocoon-${{ matrix.goos }}-${{ matrix.goarch }}
50+
retention-days: 30

.github/workflows/goreleaser.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Extract VERSION
21+
run: echo "VERSION=$(git describe --tags --always)" >> $GITHUB_ENV
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version-file: 'go.mod'
27+
28+
- name: Run GoReleaser
29+
uses: goreleaser/goreleaser-action@v6
30+
with:
31+
version: latest
32+
args: release --clean
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
VERSION: ${{ env.VERSION }}

.github/workflows/lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: golangci-lint
2+
3+
on:
4+
push:
5+
tags:
6+
- '!v*'
7+
branches:
8+
- '*'
9+
pull_request:
10+
11+
jobs:
12+
golangci:
13+
name: lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version-file: 'go.mod'
23+
24+
- name: golangci-lint
25+
uses: golangci/golangci-lint-action@v7
26+
with:
27+
version: v2.9.0

.github/workflows/test.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: test
2+
3+
on:
4+
push:
5+
tags:
6+
- '!v*'
7+
branches:
8+
- '*'
9+
pull_request:
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version-file: 'go.mod'
22+
23+
- name: Download dependencies
24+
run: go mod download
25+
26+
- name: Vet
27+
run: go vet ./...
28+
29+
- name: Test with coverage
30+
run: go test -race -timeout 120s -count=1 -cover -coverprofile=coverage.out ./...
31+
32+
- name: Upload coverage artifact
33+
continue-on-error: true
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: coverage
37+
path: coverage.out
38+
retention-days: 7
39+
40+
- name: Build binary
41+
run: CGO_ENABLED=0 go build -o cocoon .

.goreleaser.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
5+
builds:
6+
- id: cocoon-debug
7+
binary: cocoon.dbg
8+
env:
9+
- CGO_ENABLED=0
10+
ldflags:
11+
- -X github.com/projecteru2/cocoon/version.REVISION={{.Commit}}
12+
- -X github.com/projecteru2/cocoon/version.VERSION={{.Env.VERSION}}
13+
- -X github.com/projecteru2/cocoon/version.BUILTAT={{.Date}}
14+
goos:
15+
- darwin
16+
- linux
17+
goarch:
18+
- amd64
19+
main: .
20+
21+
- id: cocoon-linux
22+
binary: cocoon
23+
env:
24+
- CGO_ENABLED=0
25+
ldflags:
26+
- -s
27+
- -X github.com/projecteru2/cocoon/version.REVISION={{.Commit}}
28+
- -X github.com/projecteru2/cocoon/version.VERSION={{.Env.VERSION}}
29+
- -X github.com/projecteru2/cocoon/version.BUILTAT={{.Date}}
30+
goos:
31+
- linux
32+
goarch:
33+
- amd64
34+
- arm64
35+
main: .
36+
37+
- id: cocoon-darwin
38+
binary: cocoon
39+
env:
40+
- CGO_ENABLED=0
41+
ldflags:
42+
- -w -s
43+
- -X github.com/projecteru2/cocoon/version.REVISION={{.Commit}}
44+
- -X github.com/projecteru2/cocoon/version.VERSION={{.Env.VERSION}}
45+
- -X github.com/projecteru2/cocoon/version.BUILTAT={{.Date}}
46+
goos:
47+
- darwin
48+
goarch:
49+
- amd64
50+
- arm64
51+
main: .
52+
53+
archives:
54+
- id: cocoon
55+
name_template: >-
56+
{{- .ProjectName }}_{{- .Version }}_
57+
{{- title .Os }}_
58+
{{- if eq .Arch "amd64" }}x86_64
59+
{{- else if eq .Arch "386" }}i386
60+
{{- else }}{{ .Arch }}{{ end }}
61+
{{- if .Arm }}v{{ .Arm }}{{ end -}}
62+
63+
checksum:
64+
name_template: 'checksums.txt'
65+
66+
release:
67+
prerelease: auto
68+
69+
snapshot:
70+
name_template: "{{ .Tag }}-next"
71+
72+
changelog:
73+
sort: asc
74+
filters:
75+
exclude:
76+
- '^docs:'
77+
- '^test:'

Makefile

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
.PHONY: all build build-linux test test-race test-short lint vet fmt fmt-check \
2+
clean deps install check ci coverage verify help
3+
4+
REPO_PATH := github.com/projecteru2/cocoon
5+
REVISION := $(shell git rev-parse HEAD || echo unknown)
6+
BUILTAT := $(shell date +%Y-%m-%dT%H:%M:%S)
7+
VERSION := $(shell git describe --tags $(shell git rev-list --tags --max-count=1) 2>/dev/null || echo dev)
8+
GO_LDFLAGS ?= -X $(REPO_PATH)/version.REVISION=$(REVISION) \
9+
-X $(REPO_PATH)/version.BUILTAT=$(BUILTAT) \
10+
-X $(REPO_PATH)/version.VERSION=$(VERSION)
11+
12+
ifneq ($(KEEP_SYMBOL), 1)
13+
GO_LDFLAGS += -s
14+
endif
15+
16+
## Location to install dependencies to
17+
LOCALBIN ?= $(shell pwd)/bin
18+
$(LOCALBIN):
19+
mkdir -p $(LOCALBIN)
20+
21+
## Tool versions
22+
GOLANGCILINT_VERSION ?= v2.9.0
23+
GOLANGCILINT_ROOT := $(LOCALBIN)/golangci-lint-$(GOLANGCILINT_VERSION)
24+
GOLANGCILINT := $(GOLANGCILINT_ROOT)/golangci-lint
25+
26+
GOFMT := $(LOCALBIN)/gofumpt
27+
GOIMPORTS := $(LOCALBIN)/goimports
28+
29+
## Tool download targets
30+
.PHONY: golangci-lint
31+
golangci-lint: $(GOLANGCILINT)
32+
$(GOLANGCILINT):
33+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOLANGCILINT_ROOT) $(GOLANGCILINT_VERSION)
34+
35+
.PHONY: gofumpt
36+
gofumpt: $(GOFMT)
37+
$(GOFMT): | $(LOCALBIN)
38+
GOBIN=$(LOCALBIN) go install mvdan.cc/gofumpt@latest
39+
40+
.PHONY: goimports
41+
goimports: $(GOIMPORTS)
42+
$(GOIMPORTS): | $(LOCALBIN)
43+
GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@latest
44+
45+
# --- Primary targets ---
46+
47+
all: deps lint test build ## Run deps, lint, test, and build
48+
49+
ci: fmt-check vet lint test build ## Run all CI checks
50+
51+
verify: lint fmt-check ## Verify code is lint-clean and formatted
52+
@if ! git diff --quiet HEAD; then \
53+
git diff; \
54+
echo "files are out of date, run 'make fmt' and commit"; exit 1; \
55+
fi
56+
57+
# --- Dependencies ---
58+
59+
deps: ## Tidy Go modules
60+
go mod tidy
61+
62+
# --- Build ---
63+
64+
build: ## Build cocoon binary
65+
CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o cocoon .
66+
67+
build-linux: ## Cross-compile for linux/amd64
68+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$(GO_LDFLAGS)" -o cocoon-linux-amd64 .
69+
70+
install: ## Install cocoon binary to GOPATH/bin
71+
go install -ldflags "$(GO_LDFLAGS)" .
72+
73+
# --- Testing ---
74+
75+
test: vet ## Run tests with race detection and coverage
76+
go test -race -timeout 120s -count=1 -cover -coverprofile=coverage.out ./...
77+
78+
test-race: ## Run tests with race detector only
79+
go test -race -timeout 120s -count=1 ./...
80+
81+
test-short: ## Run short tests (skip long-running tests)
82+
go test -short ./...
83+
84+
coverage: test ## Generate and display coverage report
85+
go tool cover -func=coverage.out
86+
@echo ""
87+
@echo "To view HTML coverage report: go tool cover -html=coverage.out"
88+
89+
# --- Code quality ---
90+
91+
vet: ## Run go vet for all target platforms
92+
GOOS=linux GOARCH=amd64 go vet ./...
93+
GOOS=darwin GOARCH=amd64 go vet ./...
94+
95+
lint: golangci-lint ## Run golangci-lint for all target platforms
96+
GOOS=linux GOARCH=amd64 $(GOLANGCILINT) run
97+
GOOS=darwin GOARCH=amd64 $(GOLANGCILINT) run
98+
99+
fmt: gofumpt goimports ## Format code with gofumpt and goimports
100+
$(GOFMT) -l -w .
101+
$(GOIMPORTS) -l -w --local 'github.com/projecteru2/cocoon' .
102+
103+
fmt-check: gofumpt goimports ## Check formatting (fails if files need formatting)
104+
@test -z "$$($(GOFMT) -l .)" || { echo "Files need formatting (gofumpt):"; $(GOFMT) -l .; exit 1; }
105+
@test -z "$$($(GOIMPORTS) -l .)" || { echo "Files need formatting (goimports):"; $(GOIMPORTS) -l .; exit 1; }
106+
107+
check: vet lint test ## Run vet, lint, and test
108+
109+
# --- Maintenance ---
110+
111+
clean: ## Remove build artifacts, coverage files, and test cache
112+
rm -f cocoon cocoon-linux-* cocoon-darwin-*
113+
rm -rf bin/ dist/
114+
rm -f coverage.out coverage.html coverage.txt
115+
go clean -testcache
116+
117+
cloc: ## Count lines of code (requires cloc)
118+
cloc --exclude-dir=vendor,dist --exclude-ext=json .
119+
120+
# --- Help ---
121+
122+
help: ## Show this help message
123+
@echo "Cocoon Makefile targets:"
124+
@echo ""
125+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
126+
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
127+
@echo ""

0 commit comments

Comments
 (0)