Skip to content

Commit c5cc58d

Browse files
committed
build: switch to goreleaser for release management
1 parent ffbf84d commit c5cc58d

File tree

5 files changed

+101
-48
lines changed

5 files changed

+101
-48
lines changed

.github/workflows/release.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- name: Fetch tags
20+
run: git fetch --force --tags
21+
- name: Setup go 1.19
22+
uses: actions/setup-go@v3
23+
with:
24+
go-version: 1.19
25+
check-latest: true
26+
cache: true
27+
- name: Build release
28+
uses: goreleaser/goreleaser-action@v2
29+
with:
30+
distribution: goreleaser
31+
version: latest
32+
args: release --rm-dist
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ name: test
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: ['main']
76
pull_request:
8-
branches:
9-
- main
7+
branches: ['main']
108

119
jobs:
1210
test:
@@ -25,10 +23,3 @@ jobs:
2523
cache: true
2624
- name: Run tests
2725
run: go test -v ./pkg/taon/...
28-
- name: Make build
29-
run: go build -ldflags "-s -w -X main.version=$VERSION" ./cmd/taon/...
30-
env:
31-
VERSION: v0.0.0
32-
- name: Check build
33-
shell: bash
34-
run: "echo '{\"int\": 1, \"str\": \"one\", \"bool\": true}' | ./taon"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818

1919
# Output of the go coverage tool
2020
*.out
21+
22+
dist/

.goreleaser.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
project_name: taon
2+
before:
3+
hooks:
4+
- go mod tidy
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- windows
11+
- darwin
12+
main: ./cmd/taon
13+
archives:
14+
- replacements:
15+
darwin: Darwin
16+
linux: Linux
17+
windows: Windows
18+
386: i386
19+
amd64: x86_64
20+
checksum:
21+
name_template: 'checksums.txt'
22+
snapshot:
23+
name_template: "{{ incpatch .Version }}-next"
24+
release:
25+
prerelease: auto
26+
changelog:
27+
sort: asc
28+
filters:
29+
exclude:
30+
- '^docs:'
31+
- '^chore:'
32+
- '^test:'
33+
- '^ci:'
34+
groups:
35+
- title: Features
36+
regexp: "^.*feat[(\\w)]*:+.*$"
37+
order: 0
38+
- title: 'Bug fixes'
39+
regexp: "^.*fix[(\\w)]*:+.*$"
40+
order: 1
41+
- title: 'Refactorings'
42+
regexp: "^.*refactor[(\\w)]*:+.*$"
43+
order: 2
44+
- title: Others
45+
order: 999

Makefile

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,43 @@
1-
.DEFAULT_GOAL := all
2-
1+
.DEFAULT_GOAL := test
32
NAME := taon
4-
VERSION := $(shell git describe --tags)
5-
PLATFORMS := windows linux darwin
6-
os = $(word 1, $@)
7-
8-
.PHONY: help
9-
help: ## this help message
10-
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
11-
12-
.PHONY: all
13-
all: deps test build ## test and build
3+
SRC := $(wildcard ./cmd/$(NAME)/*.go ./pkg/$(NAME)/*.go)
144

155
.PHONY: build
16-
build: ## build the binary
17-
go build -ldflags "-s -w -X main.version=$(VERSION)" -v ./cmd/$(NAME)/...
6+
build: $(NAME)
7+
8+
$(NAME): $(SRC)
9+
go build -o $(NAME) ./cmd/$(NAME)/...
1810

1911
.PHONY: test
20-
test: ## run tests
12+
test:
2113
go test -v ./...
2214

2315
coverage.out:
2416
go test -covermode=count -coverprofile=coverage.out ./pkg/$(NAME)/...
2517

2618
.PHONY: cover
27-
cover: coverage.out ## run test coverage
19+
cover: coverage.out
2820
go tool cover -html=coverage.out
2921

3022
.PHONY: clean
31-
clean: ## clean up
23+
clean:
3224
go clean
3325
rm -f $(NAME)
3426
rm -f coverage.out
35-
rm -rf release
36-
37-
.PHONY: format
38-
format: ## format code
39-
go fmt -x ./...
27+
rm -rf dist
4028

4129
.PHONY: run
42-
run: build ## run for debug
43-
@$(CURDIR)/$(NAME) -c seq,name,bool $(CURDIR)/pkg/taon/testdata/data.json
30+
run: $(NAME)
31+
./$(NAME) -c seq,name,bool $(CURDIR)/pkg/taon/testdata/data.json
4432
@echo
45-
@$(CURDIR)/$(NAME) $(CURDIR)/pkg/taon/testdata/misc-array.json
33+
./$(NAME) $(CURDIR)/pkg/taon/testdata/misc-array.json
4634
@echo
47-
@cat $(CURDIR)/pkg/taon/testdata/all_docs.json | jq .rows | $(CURDIR)/$(NAME) -c key,doc._id,doc._rev,doc.name,doc.rank
35+
cat $(CURDIR)/pkg/taon/testdata/all_docs.json | jq .rows | ./$(NAME) -c key,doc._id,doc._rev,doc.name,doc.rank
4836
@echo
49-
@$(CURDIR)/$(NAME) $(CURDIR)/pkg/taon/testdata/long-field.json
37+
./$(NAME) $(CURDIR)/pkg/taon/testdata/long-field.json
5038
@echo
5139

52-
.PHONY: deps
53-
deps: ## install deps
54-
go get -t ./...
55-
5640
.PHONY: release
57-
release: windows linux darwin ## build binaries for release
58-
59-
.PHONY: $(PLATFORMS)
60-
$(PLATFORMS):
61-
mkdir -p release
62-
CGO_ENABLED=0 GOOS=$(os) GOARCH=amd64 go build -ldflags "-s -w -X main.version=$(VERSION)" -o release/$(NAME)-$(VERSION)-$(os)-amd64 && gzip -9 release/$(NAME)-$(VERSION)-$(os)-amd64
41+
release:
42+
goreleaser check
43+
goreleaser build --snapshot --rm-dist

0 commit comments

Comments
 (0)