-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
164 lines (149 loc) · 4.13 KB
/
Taskfile.yaml
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
version: "3"
vars:
GOLANG_CI_LINT_VERSION: v1.55.2
GO_VERSION:
sh: sed -En 's/^go (.*)$/\1/p' go.mod
GO_MOD_CACHE_VOLUME: go-module-cache
GIT_REPO_NAME:
sh: basename $(git rev-parse --show-toplevel)
GIT_REPO_OWNER: Y0sh1dk
GIT_REPO_FULL: "{{ .GIT_REPO_OWNER }}/{{ .GIT_REPO_NAME }}"
tasks:
create-go-mod-cache-volume:
internal: true
silent: true
desc: Create the module cache volume
cmds:
- |
docker volume create {{ .GO_MOD_CACHE_VOLUME }} > /dev/null 2>&1
_go-docker: &go-docker
internal: true
deps:
- task: create-go-mod-cache-volume
cmds:
- |
docker run \
--rm \
-e GOOS={{ .GOOS }} \
-e GOARCH={{ .GOARCH }} \
-v $(pwd):/app \
-v {{ .GO_MOD_CACHE_VOLUME }}:/go/pkg/mod \
-w /app \
golang:{{ .GO_VERSION }} \
{{ .COMMAND }}
_gomplate-docker: &gomplate-docker
internal: true
cmds:
- |
docker run \
--rm \
-e WORKFLOW_NAME={{ .WORKFLOW_NAME }} \
-e ACTION_VERSION={{ .ACTION_VERSION }} \
-v $(pwd):/app \
-w /app \
hairyhenderson/gomplate:stable \
{{ .COMMAND }}
_yq-docker: &yq-docker
internal: true
cmds:
- |
docker run \
--rm \
-e WORKFLOW_NAME={{ .WORKFLOW_NAME }} \
-e ACTION_VERSION={{ .ACTION_VERSION }} \
-v $(pwd):/app \
--user="root" \
-w /app \
mikefarah/yq:latest \
{{ .COMMAND }}
build:
<<: *go-docker
internal: false
desc: Build the application
sources:
- "*.go"
- "go.mod"
- "go.sum"
generates:
- "bin/{{ .GIT_REPO_NAME }}-{{ .GOOS }}-{{ .GOARCH }}"
vars:
GOOS: "{{ .GOOS | default OS }}"
GOARCH: "{{ .GOARCH | default ARCH}}"
COMMAND: go build -ldflags="-w -s" -o bin/{{ .GIT_REPO_NAME }}-{{ .GOOS }}-{{ .GOARCH }} *.go {{ .CLI_ARGS }}
gen-tests:
<<: *yq-docker
internal: false
desc: Generate test workflows
requires:
vars: [ACTION_VERSION]
vars:
ACTION_VERSION: "{{ .GIT_REPO_FULL}}@{{ .ACTION_VERSION }}"
COMMAND: |
-i '.jobs.[].steps[] |= (select(has("uses") and .uses == "{{ .GIT_REPO_FULL }}@*") | .uses = env(ACTION_VERSION))' .github/workflows/test.yaml
build-all:
desc: Build the application for all platforms
vars:
ALL_OS: linux darwin
ALL_ARCH: amd64 arm64
cmds:
- |
for os in {{ .ALL_OS }}; do
for arch in {{ .ALL_ARCH }}; do
echo "Building binary for $os/$arch..."
GOOS=$os GOARCH=$arch task build &
done
done
wait
run:
<<: *go-docker
internal: false
desc: Run the application
vars:
COMMAND: go run *.go
format:
<<: *go-docker
internal: false
desc: Format the application
vars:
COMMAND: go fmt ./...
check-format:
<<: *go-docker
internal: false
desc: Format the application
vars:
COMMAND: bash -c 'if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi'
lint:
desc: Lint the application
deps:
- task: create-go-mod-cache-volume
cmds:
- |
docker run \
--rm \
-v $(pwd):/app \
-w /app \
-v {{ .GO_MOD_CACHE_VOLUME }}:/go/pkg/mod \
golangci/golangci-lint:{{ .GOLANG_CI_LINT_VERSION }} \
golangci-lint run -v
local-registry-up:
desc: Start local registry
env:
REGISTRY_PORT: "{{ .REGISTRY_PORT | default 5000 }}"
REGISTRY_USERNAME: '{{ .REGISTRY_USERNAME | default "admin" }}'
REGISTRY_PASSWORD: '{{ .REGISTRY_PASSWORD | default "password" }}'
cmds:
- |
docker-compose -f test/docker-compose.yml up -d
local-registry-down:
desc: Step local registry
env:
REGISTRY_PORT: "{{ .REGISTRY_PORT | default 5000 }}"
REGISTRY_USERNAME: "{{ .REGISTRY_USERNAME | default admin }}"
REGISTRY_PASSWORD: "{{ .REGISTRY_PASSWORD | default password }}"
cmds:
- |
docker-compose -f test/docker-compose.yml down -v
default:
silent: true
cmds:
- task --list