From ce0e2949afe2b929ca966d6d5010690a75a6ca85 Mon Sep 17 00:00:00 2001 From: Christopher Broglie Date: Wed, 30 Oct 2019 19:36:54 -0700 Subject: [PATCH] Support building/releasing binaries with goreleaser Since this project requires cgo, the builds are performed in a container which includes the MinGW compiler (for Windows) and an OSX SDK. --- .goreleaser.yml | 279 ++++++++++++++++++++++++++++++++++++ Makefile | 20 +++ cli/version/version.go | 16 +-- cli/version/version_dev.go | 7 - cli/version/version_test.go | 7 - 5 files changed, 303 insertions(+), 26 deletions(-) create mode 100644 .goreleaser.yml delete mode 100644 cli/version/version_dev.go diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 000000000..15409199a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,279 @@ +env: + - GO111MODULE=on + - CGO_ENABLED=1 + - GOFLAGS=-mod=vendor + - GOPROXY=off +builds: + - id: cfssl-darwin + binary: cfssl + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/cfssl + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-linux + binary: cfssl + goos: + - linux + goarch: + - amd64 + main: ./cmd/cfssl + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-windows + binary: cfssl + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/cfssl + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-bundle-darwin + binary: cfssl-bundle + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/cfssl-bundle + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-bundle-linux + binary: cfssl-bundle + goos: + - linux + goarch: + - amd64 + main: ./cmd/cfssl-bundle + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-bundle-windows + binary: cfssl-bundle + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/cfssl-bundle + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-certinfo-darwin + binary: cfssl-certinfo + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/cfssl-certinfo + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-certinfo-linux + binary: cfssl-certinfo + goos: + - linux + goarch: + - amd64 + main: ./cmd/cfssl-certinfo + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-certinfo-windows + binary: cfssl-certinfo + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/cfssl-certinfo + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-newkey-darwin + binary: cfssl-newkey + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/cfssl-newkey + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-newkey-linux + binary: cfssl-newkey + goos: + - linux + goarch: + - amd64 + main: ./cmd/cfssl-newkey + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-newkey-windows + binary: cfssl-newkey + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/cfssl-newkey + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-scan-darwin + binary: cfssl-scan + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/cfssl-scan + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-scan-linux + binary: cfssl-scan + goos: + - linux + goarch: + - amd64 + main: ./cmd/cfssl-scan + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssl-scan-windows + binary: cfssl-scan + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/cfssl-scan + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssljson-darwin + binary: cfssljson + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/cfssljson + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssljson-linux + binary: cfssljson + goos: + - linux + goarch: + - amd64 + main: ./cmd/cfssljson + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: cfssljson-windows + binary: cfssljson + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/cfssljson + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: mkbundle-darwin + binary: mkbundle + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/mkbundle + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: mkbundle-linux + binary: mkbundle + goos: + - linux + goarch: + - amd64 + main: ./cmd/mkbundle + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: mkbundle-windows + binary: mkbundle + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/mkbundle + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: multirootca-darwin + binary: multirootca + env: + - CC=o64-clang + - CXX=o64-clang++ + goos: + - darwin + goarch: + - amd64 + main: ./cmd/multirootca + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: multirootca-linux + binary: multirootca + goos: + - linux + goarch: + - amd64 + main: ./cmd/multirootca + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} + - id: multirootca-windows + binary: multirootca + env: + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ + goos: + - windows + goarch: + - amd64 + main: ./cmd/multirootca + ldflags: + - -s -w -X github.com/cloudflare/cfssl/cli/version.version={{.Version}} +archives: + - format: binary +release: + github: + owner: cloudflare + name: cfssl + prerelease: auto +changelog: + sort: asc diff --git a/Makefile b/Makefile index 1920bfc57..1f7206d26 100644 --- a/Makefile +++ b/Makefile @@ -30,3 +30,23 @@ bin/goose: $(shell find . -type f -name '*.go') .PHONY: clean clean: rm -rf bin + +# Check that given variables are set and all have non-empty values, +# die with an error otherwise. +# +# Params: +# 1. Variable name(s) to test. +# 2. (optional) Error message to print. +# +# cf: https://stackoverflow.com/questions/10858261/abort-makefile-if-variable-not-set +check_defined = \ + $(strip $(foreach 1,$1, \ + $(call __check_defined,$1,$(strip $(value 2))))) +__check_defined = \ + $(if $(value $1),, \ + $(error Undefined $1$(if $2, ($2)))) + +.PHONY: release +release: + @:$(call check_defined, GITHUB_TOKEN) + docker run -e GITHUB_TOKEN=$(GITHUB_TOKEN) --rm -v $(PWD):/workdir -w /workdir cbroglie/goreleaser-cgo:1.12.12 goreleaser --rm-dist diff --git a/cli/version/version.go b/cli/version/version.go index d874cae5a..d991808ef 100644 --- a/cli/version/version.go +++ b/cli/version/version.go @@ -8,17 +8,9 @@ import ( "github.com/cloudflare/cfssl/cli" ) -// Version stores the semantic versioning information for CFSSL. -var version = struct { - Major int - Minor int - Patch int - Revision string -}{1, 3, 4, "release"} - -func versionString() string { - return fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch) -} +var ( + version = "dev" +) // Usage text for 'cfssl version' var versionUsageText = `cfssl version -- print out the version of CF SSL @@ -29,7 +21,7 @@ Usage of version: // FormatVersion returns the formatted version string. func FormatVersion() string { - return fmt.Sprintf("Version: %s\nRevision: %s\nRuntime: %s\n", versionString(), version.Revision, runtime.Version()) + return fmt.Sprintf("Version: %s\nRuntime: %s\n", version, runtime.Version()) } // The main functionality of 'cfssl version' is to print out the version info. diff --git a/cli/version/version_dev.go b/cli/version/version_dev.go deleted file mode 100644 index 6420062af..000000000 --- a/cli/version/version_dev.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build !release - -package version - -func init() { - version.Revision = "dev" -} diff --git a/cli/version/version_test.go b/cli/version/version_test.go index 83fb1a863..90683f861 100644 --- a/cli/version/version_test.go +++ b/cli/version/version_test.go @@ -6,13 +6,6 @@ import ( "github.com/cloudflare/cfssl/cli" ) -func TestVersionString(t *testing.T) { - version := versionString() - if version != "1.3.4" { - t.Fatal("version string is not returned correctly") - } -} - func TestVersionMain(t *testing.T) { args := []string{"cfssl", "version"} err := versionMain(args, cli.Config{})