{{if or (eq .Values.category "fips") (eq .Values.category "fips-static")}}
requires:
  - name: "toolchain-go-ubuntu"
    category: "fips"
    version: ">=0"
{{else}}
requires:
  - name: "toolchain-go-ubuntu"
    category: "development"
    version: ">=0"
{{end}}
prelude:
  - apt-get update && apt-get install -y gcc libssl-dev
  - mkdir go/src/github.com/${GITHUB_ORG}/ -p
  - cd go/src/github.com/${GITHUB_ORG}/ && git clone https://github.com/${GITHUB_ORG}/{{ .Values.name }}.git
env:
  - GOPATH=/luetbuild/go/
  - DEBIAN_FRONTEND=noninteractive
  - CGO_LDFLAGS="-ldl"
  - GITHUB_ORG={{ ( index .Values.labels "github.owner" ) }}
{{if or (eq .Values.category "fips") (eq .Values.category "fips-static")}}
  - CGO_ENABLED=1
  - GOEXPERIMENT=boringcrypto
  - LDFLAGS="-w {{with .Values.ldflags}}{{.}}{{end}}"
{{else}}
  - CGO_ENABLED=0
  - LDFLAGS="-s -w {{with .Values.ldflags}}{{.}}{{end}}"
{{end}}

steps:
  - |
    PACKAGE_VERSION=${PACKAGE_VERSION%\+*} && \
    mkdir -p /system/discovery && \
    cd go/src/github.com/${GITHUB_ORG}/{{ .Values.name }}/ && go build -ldflags="${LDFLAGS}" -o {{ .Values.binary_name }}  ./cmd/discovery/main.go && mv {{ .Values.binary_name }} /system/discovery
{{if or (eq .Values.category "fips") (eq .Values.category "fips-static")}}
  {{ if .Values.arch }}
    {{ if eq .Values.arch "amd64" }}
  - go tool nm /system/discovery/{{ .Values.binary_name }} | grep -i "FIPS_mode"
    {{end}}
  {{end}}
  - upx -1 /system/discovery/{{ .Values.binary_name }}
  - chmod +x /system/discovery/{{ .Values.binary_name }}
{{end}}
includes:
  - /system/discovery/{{ .Values.binary_name }}
