-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DistTasks.yml
299 lines (269 loc) · 11.7 KB
/
DistTasks.yml
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/release-go-task/DistTasks.yml
version: "3"
# This taskfile is ideally meant to be project agnostic and could be dropped in
# on other Go projects with minimal or no changes.
#
# To use it simply add the following lines to your main taskfile:
# includes:
# dist: ./DistTasks.yml
#
# The following variables must be declared in the including taskfile for the
# build process to work correctly:
# * DIST_DIR: the folder that will contain the final binaries and packages
# * PROJECT_NAME: the name of the project, used in package name
# * VERSION: the version of the project, used in package name and checksum file
# * LD_FLAGS: flags used at build time
#
# The project MUST contain a LICENSE.txt file in the root folder or packaging will fail.
vars:
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
GO_VERSION: "1.20.5"
tasks:
Windows_32bit:
desc: Builds Windows 32 bit binaries
dir: "{{.DIST_DIR}}"
cmds:
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.PLATFORM_DIR}}/LICENSE.txt
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_386"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}
BUILD_PLATFORM: "windows/386"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Windows_32bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip"
Windows_64bit:
desc: Builds Windows 64 bit binaries
dir: "{{.DIST_DIR}}"
cmds:
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
zip {{.PACKAGE_NAME}} {{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.PLATFORM_DIR}}/LICENSE.txt
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_windows_amd64"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}}.exe {{.LDFLAGS}}
BUILD_PLATFORM: "windows/amd64"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Windows_64bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip"
Linux_32bit:
desc: Builds Linux 32 bit binaries
dir: "{{.DIST_DIR}}"
cmds:
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz {{.PLATFORM_DIR}} -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd32"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
BUILD_PLATFORM: "linux/386"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Linux_32bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
Linux_64bit:
desc: Builds Linux 64 bit binaries
dir: "{{.DIST_DIR}}"
cmds:
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz {{.PLATFORM_DIR}} -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_amd64"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
BUILD_PLATFORM: "linux/amd64"
CONTAINER_TAG: "{{.GO_VERSION}}-main"
PACKAGE_PLATFORM: "Linux_64bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
Linux_ARMv7:
desc: Builds Linux ARMv7 binaries
dir: "{{.DIST_DIR}}"
cmds:
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz {{.PLATFORM_DIR}} -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_7"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
BUILD_PLATFORM: "linux/armv7"
CONTAINER_TAG: "{{.GO_VERSION}}-armhf"
PACKAGE_PLATFORM: "Linux_ARMv7"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
Linux_ARMv6:
desc: Builds Linux ARMv6 binaries
dir: "{{.DIST_DIR}}"
cmds:
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz {{.PLATFORM_DIR}} -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_6"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
BUILD_PLATFORM: "linux/armv6"
CONTAINER_TAG: "{{.GO_VERSION}}-armel-debian9"
PACKAGE_PLATFORM: "Linux_ARMv6"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
Linux_ARM64:
desc: Builds Linux ARM64 binaries
dir: "{{.DIST_DIR}}"
cmds:
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "{{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz {{.PLATFORM_DIR}} -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_linux_arm_64"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
BUILD_PLATFORM: "linux/arm64"
CONTAINER_TAG: "{{.GO_VERSION}}-arm"
PACKAGE_PLATFORM: "Linux_ARM64"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
macOS_64bit:
desc: Builds Mac OS X 64 bit binaries
dir: "{{.DIST_DIR}}"
cmds:
# "git config safe.directory" is required until this is fixed https://github.com/elastic/golang-crossbuild/issues/232
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "git config --global --add safe.directory /home/build && {{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz {{.PLATFORM_DIR}} -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_amd64"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
BUILD_PLATFORM: "darwin/amd64"
CONTAINER_TAG: "{{.GO_VERSION}}-darwin-debian10"
PACKAGE_PLATFORM: "macOS_64bit"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
macOS_ARM64:
desc: Builds Mac OS X ARM64 binaries
dir: "{{.DIST_DIR}}"
cmds:
# "git config safe.directory" is required until this is fixed https://github.com/elastic/golang-crossbuild/issues/232
- |
mkdir {{.PLATFORM_DIR}}
cp ../LICENSE.txt {{.PLATFORM_DIR}}/
docker run -v `pwd`/..:/home/build -w /home/build \
-e CGO_ENABLED=1 \
{{.CONTAINER}}:{{.CONTAINER_TAG}} \
--build-cmd "git config --global --add safe.directory /home/build && {{.BUILD_COMMAND}}" \
-p "{{.BUILD_PLATFORM}}"
tar cz {{.PLATFORM_DIR}} -f {{.PACKAGE_NAME}}
vars:
PLATFORM_DIR: "{{.PROJECT_NAME}}_osx_darwin_arm64"
BUILD_COMMAND: >
go build -o {{.DIST_DIR}}/{{.PLATFORM_DIR}}/{{.PROJECT_NAME}} {{.LDFLAGS}}
BUILD_PLATFORM: "darwin/arm64"
CONTAINER_TAG: "{{.GO_VERSION}}-darwin-arm64-debian10"
PACKAGE_PLATFORM: "macOS_ARM64"
PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz"
generate-index-data:
desc: Generates json for platform index
vars:
WINDOWS32_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Windows_32bit.zip | cut -f1 -d " "
WINDOWS64_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Windows_64bit.zip | cut -f1 -d " "
LINUX32_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_32bit.tar.gz | cut -f1 -d " "
LINUX64_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_64bit.tar.gz | cut -f1 -d " "
LINUXARM_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_ARMv6.tar.gz | cut -f1 -d " "
LINUXARM64_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_ARM64.tar.gz | cut -f1 -d " "
OSX64_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_macOS_64bit.tar.gz | cut -f1 -d " "
OSXARM64_SHA:
sh: sha256sum {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_macOS_ARM64.tar.gz | cut -f1 -d " "
WINDOWS32_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Windows_32bit.zip | cut -f5 -d " "
WINDOWS64_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Windows_64bit.zip | cut -f5 -d " "
LINUX32_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_32bit.tar.gz | cut -f5 -d " "
LINUX64_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_64bit.tar.gz | cut -f5 -d " "
LINUXARM_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_ARMv6.tar.gz | cut -f5 -d " "
LINUXARM64_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_Linux_ARM64.tar.gz | cut -f5 -d " "
OSX64_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_macOS_64bit.tar.gz | cut -f5 -d " "
OSXARM64_SIZE:
sh: ls -la {{ .DIST_DIR }}/{{ .PROJECT_NAME }}_{{ .VERSION }}_macOS_ARM64.tar.gz | cut -f5 -d " "
cmds:
- |
cat extras/package_index.json.template |
sed "s/%%VERSION%%/{{ .VERSION }}/" |
sed "s/%%FILENAME%%/{{ .PROJECT_NAME }}/" |
sed "s/%%LINUX64_SHA%%/{{ .LINUX64_SHA }}/" |
sed "s/%%LINUX64_SIZE%%/{{ .LINUX64_SIZE }}/" |
sed "s/%%LINUX32_SHA%%/{{ .LINUX32_SHA }}/" |
sed "s/%%LINUX32_SIZE%%/{{ .LINUX32_SIZE }}/" |
sed "s/%%LINUXARM_SHA%%/{{ .LINUXARM_SHA }}/" |
sed "s/%%LINUXARM_SIZE%%/{{ .LINUXARM_SIZE }}/" |
sed "s/%%LINUXARM64_SHA%%/{{ .LINUXARM64_SHA }}/" |
sed "s/%%LINUXARM64_SIZE%%/{{ .LINUXARM64_SIZE }}/" |
sed "s/%%OSX64_SHA%%/{{ .OSX64_SHA }}/" |
sed "s/%%OSX64_SIZE%%/{{ .OSX64_SIZE }}/" |
sed "s/%%OSXARM64_SHA%%/{{ .OSXARM64_SHA }}/" |
sed "s/%%OSXARM64_SIZE%%/{{ .OSXARM64_SIZE }}/" |
sed "s/%%WINDOWS32_SHA%%/{{ .WINDOWS32_SHA }}/" |
sed "s/%%WINDOWS32_SIZE%%/{{ .WINDOWS32_SIZE }}/" |
sed "s/%%WINDOWS64_SHA%%/{{ .WINDOWS64_SHA }}/" |
sed "s/%%WINDOWS64_SIZE%%/{{ .WINDOWS64_SIZE }}/" \
> {{ .DIST_DIR }}/package_index.json