From 848fc1f6cc34249872d5750df5cc4e59812547d0 Mon Sep 17 00:00:00 2001 From: Alex Vaghin Date: Tue, 20 Sep 2016 17:27:28 +0200 Subject: [PATCH] ci,version: add statically linked versioned binary The release binaries are also uploaded to GitHub releases page. --- .drone.sec | 1 + .drone.yml | 8 ++++++++ .gitignore | 2 ++ Makefile | 34 ++++++++++++++++++++++++++++++++++ version.go | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 .drone.sec create mode 100644 Makefile create mode 100644 version.go diff --git a/.drone.sec b/.drone.sec new file mode 100644 index 0000000..37724c6 --- /dev/null +++ b/.drone.sec @@ -0,0 +1 @@ +eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.SytNdB4wH1wYUiVY5gORAvJCiHovYJ0mlnPCwYv6ClytsRuZkJZsVW5PTkSMH7Xt4idQATISPvagxZaizxYme-bAgJqsoERzvQV3g4l5NrwbI2AR0zZr2ZXWoqEa-LiuRfFNeAAaY8xhtFjmOlL-aNcfR8nDgJQLD9Lhs2VPCdTdrqYGrIYvASo-lVkzhhBSD8DzPx8qIHEUsp_3QtFWLYa-X3C-eWBgefF0fN7nz_SqrHyT82YXX1uCc9qCQx3dlSxYUSNBU6UMiTnF-mwykDC0GoVcQ3RImDHCIrafNAneAC5QgpgDzS9uK0liw28mAaPVdBIISEdvlUYmBfystg.-hI9dcTpYd9mIaly.KlOqcJAceQ4KfhzagQvf9andq6KF_vh1reYM3OgHNEJB5DRexGAVd9LY_X81Wiynv-d5ZSFeGm2PbWne9LtlOW-R8bakf-H-9oL1HqgCMKgDt5qrl08LiFjBBWr7m6HWcEW7ZRLj-pVUuwpltfhxBrHXcNzekaaMTn9cstXBPhPHdEI6ZMZF6T0n992CXZE.zOUAbIwC29tgYOofC8GwRg \ No newline at end of file diff --git a/.drone.yml b/.drone.yml index f6c4ac3..3094523 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,3 +5,11 @@ build: commands: - go get ./... - go test ./... + - make -j2 +publish: + github_release: + when: + event: tag + api_key: $$GH_API_KEY + files: bin/acme-* + checksum: sha1 diff --git a/.gitignore b/.gitignore index cfaad76..53f2cd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +.drone.sec.yml *.pem +bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..31cac4f --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +# Copyright 2016 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +RELEASES=bin/acme-darwin-amd64 \ + bin/acme-linux-amd64 \ + bin/acme-linux-386 \ + bin/acme-linux-arm \ + bin/acme-windows-amd64.exe \ + bin/acme-windows-386.exe + +all: $(RELEASES) + +bin/acme-%: GOOS=$(firstword $(subst -, ,$*)) +bin/acme-%: GOARCH=$(subst .exe,,$(word 2,$(subst -, ,$*))) +bin/acme-%: $(wildcard *.go) + GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build \ + -ldflags "-X main.osarch=$(GOOS)/$(GOARCH) -s -w" \ + -buildmode=exe \ + -tags release \ + -o $@ + +clean: + rm -rf bin diff --git a/version.go b/version.go new file mode 100644 index 0000000..5f59eab --- /dev/null +++ b/version.go @@ -0,0 +1,40 @@ +// Copyright 2015 Google Inc. All Rights Reserved. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build release + +package main + +import "fmt" + +var ( + version = "1.0.0" + osarch string // set by ldflags + + cmdVersion = &command{ + run: runVersion, + UsageLine: "version", + Short: "display acme tool version", + Long: ` +The version command is available only for releases. +The binary built with "go get" will not have the version subcommand. + `, + } +) + +func init() { + // Insert "acme version" at the top of the commands. + commands = append([]*command{cmdVersion}, commands...) +} + +func runVersion(args []string) { + fmt.Println(version, osarch) +}