-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
166 lines (140 loc) · 3.78 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
ARCH = $(or $(shell printenv ARCH),$(shell echo linux/amd64,linux/arm64))
BUILD_FLAGS = $(or $(shell printenv BUILD_FLAGS),--pull)
CGO_ENABLED = 1
CODECOV_TOKEN = $(or $(shell printenv CODECOV_TOKEN),"UNSET")
CREATED = $(or $(shell printenv CREATED),$(shell date --rfc-3339=seconds))
DOCKER_INTERACTIVE = $(if $(shell printenv GITHUB_ACTIONS),-t,-it)
GITHUB_TOKEN = $(or $(shell printenv GITHUB_TOKEN),"UNSET")
GIT_REVISION = $(or $(shell printenv GIT_REVISION), $(shell git describe --match= --always --abbrev=7 --dirty))
IMAGE = $(or $(shell printenv IMAGE),cewood/csv2beancount)
IMAGE_TAG = $(or $(shell printenv IMAGE_TAG),${TAG_REVISION})
TAG_REVISION = $(or $(shell printenv TAG_REVISION),${GIT_REVISION})
VERSION = snapshot
.PHONY: all-docker
all-docker: docker-do-all
.PHONY: all
all:
make build \
&& make test \
&& make lint \
&& make reportcard \
&& make release-snapshot
.dockerimage-builder: Dockerfile-builder
docker \
build \
--tag csv2beancount-builder \
--file Dockerfile-builder \
.
touch .dockerimage-builder
.PHONY: docker-do-%
docker-do-%: .dockerimage-builder
docker run \
--rm \
${DOCKER_INTERACTIVE} \
-e CGO_ENABLED=${CGO_ENABLED} \
-e CODECOV_TOKEN=${CODECOV_TOKEN} \
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
-v ${PWD}:/workdir \
-w /workdir \
csv2beancount-builder \
make $*
.PHONY: build
build:
CGO_ENABLED=${CGO_ENABLED} \
go \
build
.PHONY: build-docker
build-docker: docker-do-build
.PHONY: test
test:
go \
test \
-cover \
-covermode=atomic \
-coverprofile=coverage.txt \
-race \
-v \
github.com/cewood/csv2beancount/...
.PHONY: test-docker
test-docker: docker-do-test
.PHONY: test-ci-docker
test-ci-docker: docker-do-test docker-do-codecov-upload
.PHONY: reportcard
reportcard:
goreportcard-cli -v
.PHONY: reportcard-docker
reportcard-docker: docker-do-reportcard
.PHONY: lint
lint:
golangci-lint run --verbose
.PHONY: lint-docker
lint-docker: docker-do-lint
.PHONY: release-snapshot
release-snapshot:
CGO_ENABLED=${CGO_ENABLED} \
GIT_REVISION=${GIT_REVISION} \
VERSION=${VERSION} \
goreleaser \
--snapshot \
--skip-publish \
--rm-dist
.PHONY: release-snapshot-docker
release-snapshot-docker: docker-do-release-snapshot
.PHONY: release
release:
CGO_ENABLED=${CGO_ENABLED} \
GIT_REVISION=${GIT_REVISION} \
GITHUB_TOKEN=${GITHUB_TOKEN} \
VERSION=${VERSION} \
goreleaser \
release \
--rm-dist
.PHONY: release-docker
release-docker: docker-do-release
.PHONY: codecov-upload
codecov-upload: SHELL := /bin/bash
codecov-upload:
bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'
.PHONY: load
load:
$(MAKE) build-dockerimages BUILD_FLAGS=--load
.PHONY: inspect
inspect:
docker inspect ${IMAGE}:${IMAGE_TAG}
.PHONY: binfmt-setup
binfmt-setup:
docker \
run \
--rm \
--privileged \
docker/binfmt:66f9012c56a8316f9244ffd7622d7c21c1f6f28d
.PHONY: buildx-setup
buildx-setup:
DOCKER_CLI_EXPERIMENTAL=enabled \
docker \
buildx \
create \
--use \
--name multiarch
.PHONY: dive
dive:
docker run --rm -it \
-e CI=true \
-v /var/run/docker.sock:/var/run/docker.sock \
wagoodman/dive:v0.9.2 ${IMAGE}:${IMAGE_TAG}
.PHONY: build-dockerimages
build-dockerimages:
DOCKER_CLI_EXPERIMENTAL=enabled \
docker \
buildx build \
${BUILD_FLAGS} \
--build-arg CREATED="${CREATED}" \
--build-arg REVISION="${GIT_REVISION}" \
--platform ${ARCH} \
--tag ${IMAGE}:${IMAGE_TAG} \
-f Dockerfile \
.
.PHONY: build-and-push-dockerimages
build-and-push-dockerimages:
$(MAKE) build-dockerimages BUILD_FLAGS=$(if $(findstring tags,${GITHUB_REF}),--push,--pull)
$(MAKE) build-dockerimages BUILD_FLAGS=$(if $(findstring tags,${GITHUB_REF}),--push,--pull) TAG_REVISION=latest