-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathbuild.yaml
132 lines (105 loc) · 3.61 KB
/
build.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
name: Run a build using the go compiler
needs:
packages:
- ${{inputs.go-package}}
- busybox
- ca-certificates-bundle
inputs:
go-package:
description: |
The go package to install
default: go
packages:
description: |
List of space-separated packages to compile. Files con also be specified.
This value is passed as an argument to go build. All paths are relative
to inputs.modroot.
required: true
tags:
description: |
A comma-separated list of build tags to append to the go compiler
toolchaintags:
description: |
A comma-separated list of default toolchain go build tags
default: "netgo,osusergo"
output:
description: |
Filename to use when writing the binary. The final install location inside
the apk will be in prefix / install-dir / output
required: true
vendor:
description: |
If true, the go mod command will also update the vendor directory
default: "false"
modroot:
default: "."
required: false
description: |
Top directory of the go module, this is where go.mod lives. Before buiding
the go pipeline wil cd into this directory.
prefix:
description: |
Prefix to relocate binaries
default: usr
ldflags:
description:
List of [pattern=]arg to append to the go compiler with -ldflags
strip:
description:
Set of strip ldflags passed to the go compiler
# Note symbols tables are useful for cryptography audits and govulncheck
default: "-w"
install-dir:
description: |
Directory where binaries will be installed
default: bin
deps:
description: |
space separated list of go modules to update before building. example: github.com/foo/bar@v1.2.3
experiments:
description: |
A comma-separated list of Golang experiment names (ex: loopvar) to use
when building the binary.
default: ""
amd64:
description: |
GOAMD64 microarchitecture level to use
default: "v2"
arm64:
description: |
GOARM64 microarchitecture level to use
default: "v8.0"
buildmode:
description: |
The -buildmode flag value. See "go help buildmode" for more information.
default: "default"
tidy:
description: |
If true, "go mod tidy" will run before the build
default: "false"
pipeline:
- runs: |
cd "${{inputs.modroot}}"
# check if modroot is set correctly by checking go.mod file exist
if [ ! -e go.mod ]; then
echo "go.mod not found in ${{inputs.modroot}}"
exit 1
fi
"${{inputs.tidy}}" && go mod tidy
LDFLAGS="${{inputs.strip}} ${{inputs.ldflags}}"
BASE_PATH="${{inputs.prefix}}/${{inputs.install-dir}}/${{inputs.output}}"
# Take advantage of melange's buid cache for downloaded modules
export GOMODCACHE=/var/cache/melange/gomodcache
# Install any specified dependencies
if [ ! "${{inputs.deps}}" == "" ]; then
for dep in ${{inputs.deps}}; do
go get $dep
done
go mod tidy
# If vendor is specified, update the vendor directory
"${{inputs.vendor}}" && go mod vendor
fi
# Install go mod overlay if it exists.
[ -e /home/build/go.mod.local ] && cp /home/build/go.mod.local go.mod
[ -e /home/build/go.sum.local ] && cp /home/build/go.sum.local go.sum
GOAMD64="${{inputs.amd64}}" GOARM64="${{inputs.arm64}}" GOEXPERIMENT="${{inputs.experiments}}" go build -o "${{targets.contextdir}}"/${BASE_PATH} -tags "${{inputs.toolchaintags}},${{inputs.tags}}" -ldflags "${LDFLAGS}" -trimpath -buildmode ${{inputs.buildmode}} ${{inputs.packages}}