瀏覽代碼

Use goreleaser for v1

tags/v1.0.11^2
9seconds 4 年之前
父節點
當前提交
a587f85dd2
共有 3 個文件被更改,包括 78 次插入20 次删除
  1. 1
    1
      .gitignore
  2. 65
    0
      .goreleaser.yml
  3. 12
    19
      Makefile

+ 1
- 1
.gitignore 查看文件

@@ -7,5 +7,5 @@
7 7
 *.out
8 8
 mtg
9 9
 vendor/
10
-ccbuilds/
11 10
 .bin/
11
+dist/

+ 65
- 0
.goreleaser.yml 查看文件

@@ -0,0 +1,65 @@
1
+---
2
+
3
+project_name: mtg
4
+
5
+before:
6
+  hooks:
7
+    - go mod tidy
8
+    - go generate ./...
9
+
10
+builds:
11
+  - binary: '{{ .ProjectName }}'
12
+    goos:
13
+      - darwin
14
+      - freebsd
15
+      - linux
16
+      - netbsd
17
+      - openbsd
18
+    goarch:
19
+      - 386
20
+      - amd64
21
+      - arm
22
+      - arm64
23
+    goarm:
24
+      - 6
25
+      - 7
26
+    env:
27
+      - CGO_ENABLED=0
28
+    flags:
29
+      - -trimpath
30
+      - -mod=readonly
31
+    ldflags: -s -w -X main.version={{ .Version }}
32
+    ignore:
33
+      - goos: darwin
34
+        goarch: 386
35
+      - goos: freebsd
36
+        goarch: arm64
37
+      - goos: netbsd
38
+        goarch: arm64
39
+      - goos: openbsd
40
+        goarch: arm64
41
+
42
+archives:
43
+  - name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
44
+    format: tar.gz
45
+    wrap_in_directory: true
46
+    format_overrides:
47
+      - goos: windows
48
+        format: zip
49
+    files:
50
+      - LICENSE
51
+      - README.md
52
+      - SECURITY.md
53
+
54
+gomod:
55
+  proxy: true
56
+
57
+snapshot:
58
+  name_template: '{{ .Version }}'
59
+
60
+checksum:
61
+  name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt'
62
+
63
+source:
64
+  enabled: true
65
+  name_template: '{{ .ProjectName }}-sources'

+ 12
- 19
Makefile 查看文件

@@ -2,14 +2,12 @@ ROOT_DIR     := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2 2
 IMAGE_NAME   := mtg
3 3
 APP_NAME     := $(IMAGE_NAME)
4 4
 
5
-CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
6
-
7 5
 GOLANGCI_LINT_VERSION := v1.45.0
8 6
 
9 7
 VERSION_GO         := $(shell go version)
10 8
 VERSION_DATE       := $(shell date -Ru)
11 9
 VERSION_TAG        := $(shell git describe --tags --always)
12
-COMMON_BUILD_FLAGS := -mod=readonly -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
10
+COMMON_BUILD_FLAGS := -trimpath -mod=readonly -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
13 11
 
14 12
 GOBIN  := $(ROOT_DIR)/.bin
15 13
 GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)"
@@ -29,18 +27,6 @@ $(APP_NAME): build
29 27
 static:
30 28
 	@env CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo $(COMMON_BUILD_FLAGS) -o "$(APP_NAME)"
31 29
 
32
-$(APP_NAME)-%: GOOS=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f1 -d-)
33
-$(APP_NAME)-%: GOARCH=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f2 -d-)
34
-$(APP_NAME)-%: ccbuilds
35
-	@env "GOOS=$(GOOS)" "GOARCH=$(GOARCH)" \
36
-		go build \
37
-		$(COMMON_BUILD_FLAGS) \
38
-		-o "./ccbuilds/$(APP_NAME)-$(GOOS)-$(GOARCH)"
39
-
40
-.PHONY: ccbuilds
41
-ccbuilds:
42
-	@rm -rf ./ccbuilds && mkdir -p ./ccbuilds
43
-
44 30
 vendor: go.mod go.sum
45 31
 	@$(MOD_ON) go mod vendor
46 32
 
@@ -52,9 +38,6 @@ test:
52 38
 citest:
53 39
 	@go test -coverprofile=coverage.txt -covermode=atomic -race -v ./...
54 40
 
55
-.PHONY: crosscompile
56
-crosscompile: $(CC_BINARIES)
57
-
58 41
 .PHONY: clean
59 42
 clean:
60 43
 	@git clean -xfd && \
@@ -77,8 +60,14 @@ doc:
77 60
 fmt:
78 61
 	@$(GOTOOL) gofumpt -w -extra "$(ROOT_DIR)"
79 62
 
63
+.PHONY: release
64
+release:
65
+	@$(GOTOOL) goreleaser release --snapshot --rm-dist && \
66
+		find "$(ROOT_DIR)/dist" -type d | grep -vP "dist$$" | xargs -r rm -rf && \
67
+		rm -f "$(ROOT_DIR)/dist/config.yaml"
68
+
80 69
 .PHONY: install-tools
81
-install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt
70
+install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt install-tools-goreleaser
82 71
 
83 72
 .PHONY: install-tools-lint
84 73
 install-tools-lint:
@@ -95,6 +84,10 @@ install-tools-godoc:
95 84
 install-tools-gofumpt: .bin
96 85
 	@$(GOTOOL) go install mvdan.cc/gofumpt@latest
97 86
 
87
+.PHONY: goreleaser
88
+install-tools-goreleaser: .bin
89
+	@$(GOTOOL) go install github.com/goreleaser/goreleaser@latest
90
+
98 91
 .PHONY: update-deps
99 92
 update-deps:
100 93
 	@go get -u && go mod tidy -go=1.18

Loading…
取消
儲存