Skip to content

Commit 63a4824

Browse files
Wrap up release automation
1 parent 8e7180c commit 63a4824

File tree

12 files changed

+183
-28
lines changed

12 files changed

+183
-28
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ workflows:
2828
- build:
2929
filters:
3030
tags:
31-
only: /^[0-9].*/
31+
only: /.*/

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66

77
# Test binary, build with `go test -c`
88
*.test
9+
10+
# Release config file backups
11+
.goreleaser.floating.yml.bak
12+
.goreleaser.permalink.yml.bak

.goreleaser.floating.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
release: {name_template: ""}
2+
3+
builds:
4+
- main: ./cmd/eksctl
5+
binary: eksctl
6+
flags:
7+
- -tags
8+
- release
9+
ldflags:
10+
# gitTag set from a generated file (see ./tag_release.sh)
11+
- -s -w -X main.builtAt={{.Date}} -X main.gitCommit={{.Commit}}
12+
goos:
13+
- windows
14+
- darwin
15+
- linux
16+
goarch:
17+
- amd64
18+
19+
archive:
20+
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
21+
replacements:
22+
darwin: Darwin
23+
linux: Linux
24+
windows: Windows
25+
format: tar.gz
26+
format_overrides:
27+
- goos: windows
28+
format: zip
29+
files:
30+
- none*
31+
32+
checksum:
33+
name_template: "{{ .ProjectName }}_checksums.txt"

.goreleaser.permalink.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
release: {name_template: ""}
2+
3+
builds:
4+
- main: ./cmd/eksctl
5+
binary: eksctl
6+
flags:
7+
- -tags
8+
- release
9+
ldflags:
10+
# gitTag set from a generated file (see ./tag_release.sh)
11+
- -s -w -X main.builtAt={{.Date}} -X main.gitCommit={{.Commit}}
12+
goos:
13+
- windows
14+
- darwin
15+
- linux
16+
goarch:
17+
- amd64
18+
19+
archive:
20+
name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
21+
replacements:
22+
darwin: Darwin
23+
linux: Linux
24+
windows: Windows
25+
format: tar.gz
26+
format_overrides:
27+
- goos: windows
28+
format: zip
29+
files:
30+
- none*
31+
32+
checksum:
33+
name_template: "{{ .ProjectName }}_checksums.txt"

.goreleaser.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
COMMIT:=$(shell git describe --dirty --always)
1+
builtAt := $(shell date +%s)
2+
gitCommit := $(shell git describe --dirty --always)
3+
gitTag := $(shell git describe --tags --abbrev=0)
24

35
build: update-bindata
4-
go build -ldflags "-X main.commit=$(COMMIT)" ./cmd/eksctl
6+
go build -ldflags "-X main.gitCommit=$(gitCommit) -X main.builtAt=$(builtAt)" ./cmd/eksctl
57

68
update-bindata:
79
go generate ./pkg/eks
@@ -18,7 +20,18 @@ eksctl_image: eksctl_build_image
1820
release: eksctl_build_image
1921
docker run \
2022
--env=GITHUB_TOKEN \
23+
--env=CIRCLE_TAG \
2124
--volume=$(CURDIR):/go/src/github.com/weaveworks/eksctl \
2225
--workdir=/go/src/github.com/weaveworks/eksctl \
2326
eksctl_build \
24-
goreleaser release
27+
make do_release
28+
29+
do_release:
30+
@if [ $(CIRCLE_TAG) = latest_release ] ; then \
31+
git tag -d $(gitTag) ; \
32+
github-release info --user weaveworks --repo eksctl --tag latest_release > /dev/null 2>&1 && \
33+
github-release delete --user weaveworks --repo eksctl --tag latest_release ; \
34+
goreleaser release --skip-validate --config=./.goreleaser.floating.yml ; \
35+
else \
36+
goreleaser release --config=./.goreleaser.permalink.yml ; \
37+
fi

build/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ WORKDIR $EKSCTL_BUILD
2020

2121
RUN dep ensure
2222

23+
WORKDIR $EKSCTL_BUILD
24+
2325
RUN go install ./vendor/github.com/jteeuwen/go-bindata/go-bindata
26+
RUN go install ./vendor/github.com/weaveworks/github-release
2427
RUN go install ./vendor/golang.org/x/tools/cmd/stringer
2528

2629
WORKDIR $EKSCTL_BUILD/vendor/github.com/goreleaser/goreleaser
2730
RUN make build && go install
2831

32+
2933
WORKDIR $GOPATH

build/Gopkg.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
required = [
2-
"github.com/jteeuwen/go-bindata/go-bindata",
32
"github.com/goreleaser/goreleaser",
3+
"github.com/jteeuwen/go-bindata/go-bindata",
4+
"github.com/weaveworks/github-release",
45
"golang.org/x/tools/cmd/stringer",
56
]

cmd/eksctl/version.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
package main
22

33
import (
4-
"fmt"
5-
64
"github.com/spf13/cobra"
7-
)
85

9-
var (
10-
version = "dev"
11-
commit = "none"
12-
date = "unknown"
6+
"github.com/kubicorn/kubicorn/pkg/logger"
137
)
148

9+
//go:generate go run version_generate.go
10+
1511
func versionCmd() *cobra.Command {
1612
return &cobra.Command{
1713
Use: "version",
1814
Short: "Output the version of eksctl",
19-
RunE: func(cmd *cobra.Command, args []string) error {
20-
fmt.Println(fmt.Sprintf("%v, commit %v, built at %v", version, commit, date))
21-
return nil
15+
Run: func(_ *cobra.Command, _ []string) {
16+
versionInfo := map[string]string{
17+
"builtAt": builtAt,
18+
"gitCommit": gitCommit,
19+
}
20+
21+
if gitTag != "" {
22+
versionInfo["gitTag"] = gitTag
23+
}
24+
25+
logger.Info("versionInfo = %#v", versionInfo)
2226
},
2327
}
2428
}

cmd/eksctl/version_generate.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"os"
8+
"strings"
9+
)
10+
11+
func main() {
12+
lines := []string{
13+
"// +build release",
14+
"",
15+
"package main",
16+
"// this file was generated by version_generate.go",
17+
`var builtAt = "" // will be set by goreleaser tool`,
18+
`var gitCommit = "" // will be set by goreleaser tool`,
19+
fmt.Sprintf("var gitTag = %q", os.Getenv("RELEASE_GIT_TAG")),
20+
}
21+
22+
f, err := os.Create("version_release.go")
23+
if err != nil {
24+
os.Exit(1)
25+
}
26+
27+
defer f.Close()
28+
29+
if _, err := fmt.Fprintln(f, strings.Join(lines, "\n")); err != nil {
30+
os.Exit(2)
31+
}
32+
}

0 commit comments

Comments
 (0)