From 7ed35aaf3765e121298829d143748807a587995f Mon Sep 17 00:00:00 2001 From: ShiranAvidov Date: Mon, 24 Jul 2023 17:24:41 +0300 Subject: [PATCH] add windows zip --- .goreleaser.yaml | 60 ++++++++++++++++++++++++++-- cmd/goreleaser/internal/configure.go | 40 +++++++++++++++++-- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index c3b6a04c..5e13fd2a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,12 +1,9 @@ -partial: - by: target project_name: opentelemetry-collector-releases builds: - id: otelcol goos: - darwin - linux - - windows goarch: - "386" - amd64 @@ -20,6 +17,27 @@ builds: goarch: "386" - goos: darwin goarch: arm + dir: distributions/otelcol/_build + binary: otelcol + ldflags: + - -s + - -w + flags: + - -trimpath + env: + - CGO_ENABLED=0 + - id: otelcol-windows + goos: + - windows + goarch: + - "386" + - amd64 + - arm + - arm64 + - ppc64le + goarm: + - "7" + ignore: - goos: windows goarch: arm - goos: windows @@ -37,7 +55,6 @@ builds: goos: - darwin - linux - - windows goarch: - "386" - amd64 @@ -51,6 +68,27 @@ builds: goarch: "386" - goos: darwin goarch: arm + dir: distributions/otelcol-contrib/_build + binary: otelcol-contrib + ldflags: + - -s + - -w + flags: + - -trimpath + env: + - CGO_ENABLED=0 + - id: otelcol-contrib-windows + goos: + - windows + goarch: + - "386" + - amd64 + - arm + - arm64 + - ppc64le + goarm: + - "7" + ignore: - goos: windows goarch: arm - goos: windows @@ -68,11 +106,25 @@ archives: - id: otelcol builds: - otelcol + - otelcol-windows + name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' + format: tar.gz + - id: otelcol-windows + builds: + - otelcol-windows name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' + format: zip - id: otelcol-contrib builds: - otelcol-contrib + - otelcol-contrib-windows + name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' + format: tar.gz + - id: otelcol-contrib-windows + builds: + - otelcol-contrib-windows name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}' + format: zip nfpms: - package_name: otelcol contents: diff --git a/cmd/goreleaser/internal/configure.go b/cmd/goreleaser/internal/configure.go index 38c9d222..6d6bb6c9 100644 --- a/cmd/goreleaser/internal/configure.go +++ b/cmd/goreleaser/internal/configure.go @@ -53,7 +53,7 @@ func Generate(imagePrefixes []string, dists []string) config.Project { func Builds(dists []string) (r []config.Build) { for _, dist := range dists { - r = append(r, Build(dist)) + r = append(r, Build(dist), WindowsBuild(dist)) } return } @@ -70,12 +70,32 @@ func Build(dist string) config.Build { Flags: []string{"-trimpath"}, Ldflags: []string{"-s", "-w"}, }, - Goos: []string{"darwin", "linux", "windows"}, + Goos: []string{"darwin", "linux"}, Goarch: Architectures, Goarm: ArmVersions, Ignore: []config.IgnoredBuild{ {Goos: "darwin", Goarch: "386"}, {Goos: "darwin", Goarch: "arm"}, + }, + } +} + +// WindowsBuild configures a goreleaser build. +// https://goreleaser.com/customization/build/ +func WindowsBuild(dist string) config.Build { + return config.Build{ + ID: fmt.Sprintf("%s-windows", dist), + Dir: path.Join("distributions", dist, "_build"), + Binary: dist, + BuildDetails: config.BuildDetails{ + Env: []string{"CGO_ENABLED=0"}, + Flags: []string{"-trimpath"}, + Ldflags: []string{"-s", "-w"}, + }, + Goos: []string{"windows"}, + Goarch: Architectures, + Goarm: ArmVersions, + Ignore: []config.IgnoredBuild{ {Goos: "windows", Goarch: "arm"}, {Goos: "windows", Goarch: "arm64"}, }, @@ -84,7 +104,7 @@ func Build(dist string) config.Build { func Archives(dists []string) (r []config.Archive) { for _, dist := range dists { - r = append(r, Archive(dist)) + r = append(r, Archive(dist), WindowsZipArchive(dist)) } return } @@ -95,7 +115,19 @@ func Archive(dist string) config.Archive { return config.Archive{ ID: dist, NameTemplate: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}", - Builds: []string{dist}, + Builds: []string{dist, fmt.Sprintf("%s-windows", dist)}, + Format: "tar.gz", + } +} + +// WindowsZipArchive configures a goreleaser archive (tarball). +// https://goreleaser.com/customization/archive/ +func WindowsZipArchive(dist string) config.Archive { + return config.Archive{ + ID: fmt.Sprintf("%s-windows", dist), + NameTemplate: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}", + Builds: []string{fmt.Sprintf("%s-windows", dist)}, + Format: "zip", } }