Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
ci,version: add statically linked versioned binary
Browse files Browse the repository at this point in the history
The release binaries are also uploaded to GitHub releases page.
  • Loading branch information
Alex Vaghin committed Sep 20, 2016
1 parent 632f1d9 commit 848fc1f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions .drone.sec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.SytNdB4wH1wYUiVY5gORAvJCiHovYJ0mlnPCwYv6ClytsRuZkJZsVW5PTkSMH7Xt4idQATISPvagxZaizxYme-bAgJqsoERzvQV3g4l5NrwbI2AR0zZr2ZXWoqEa-LiuRfFNeAAaY8xhtFjmOlL-aNcfR8nDgJQLD9Lhs2VPCdTdrqYGrIYvASo-lVkzhhBSD8DzPx8qIHEUsp_3QtFWLYa-X3C-eWBgefF0fN7nz_SqrHyT82YXX1uCc9qCQx3dlSxYUSNBU6UMiTnF-mwykDC0GoVcQ3RImDHCIrafNAneAC5QgpgDzS9uK0liw28mAaPVdBIISEdvlUYmBfystg.-hI9dcTpYd9mIaly.KlOqcJAceQ4KfhzagQvf9andq6KF_vh1reYM3OgHNEJB5DRexGAVd9LY_X81Wiynv-d5ZSFeGm2PbWne9LtlOW-R8bakf-H-9oL1HqgCMKgDt5qrl08LiFjBBWr7m6HWcEW7ZRLj-pVUuwpltfhxBrHXcNzekaaMTn9cstXBPhPHdEI6ZMZF6T0n992CXZE.zOUAbIwC29tgYOofC8GwRg
8 changes: 8 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.drone.sec.yml
*.pem
bin
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 848fc1f

Please sign in to comment.