Skip to content

Commit 240fa90

Browse files
committed
chore: add release scripts
1 parent ea5bcbd commit 240fa90

File tree

6 files changed

+78
-20
lines changed

6 files changed

+78
-20
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.idea
22
vcheck
3+
build
4+
dist

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ COPY go.mod .
55
COPY go.sum .
66
RUN go mod download
77
COPY . .
8-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /app/vcheck
8+
ARG VERSION
9+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-X main.Version=$VERSION" -o /app/vcheck
910

1011
FROM alpine
1112
RUN apk update && apk add ca-certificates

Makefile

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1-
VERSION:=$(shell git describe --tags --always --dirty)
2-
IMAGE:=anjmao/vcheck:$(VERSION)
1+
GHACCOUNT := anjmao
2+
NAME := vcheck
3+
VERSION := $(shell git describe --tags --always --dirty)
4+
DOCKER_IMAGE_NAME := $(GHACCOUNT)/$(NAME):$(VERSION)
5+
LATFORM := $(shell go env | grep GOHOSTOS | cut -d '"' -f 2)
6+
ARCH := $(shell go env | grep GOARCH | cut -d '"' -f 2)
7+
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
8+
LDFLAGS := -ldflags "-X main.Version=$(VERSION)"
39

410
container:
5-
@docker build -t $(IMAGE) .
11+
@docker build --build-arg VERSION=$(VERSION) -t $(DOCKER_IMAGE_NAME) .
612

713
push:
8-
@docker push $(IMAGE)
14+
@docker push $(DOCKER_IMAGE_NAME)
15+
16+
compile:
17+
@rm -rf build/
18+
@gox $(LDFLAGS) \
19+
-osarch="darwin/amd64" \
20+
-osarch="linux/amd64" \
21+
-osarch="windows/amd64" \
22+
-output "build/$(NAME)_$(VERSION)_{{.OS}}_{{.Arch}}/$(NAME)" \
23+
./...
24+
25+
dist: compile
26+
$(eval FILES := $(shell ls build))
27+
@rm -rf dist && mkdir dist
28+
@for f in $(FILES); do \
29+
(cd $(shell pwd)/build/$$f && tar -cvzf ../../dist/$$f.tar.gz *); \
30+
(cd $(shell pwd)/dist && shasum -a 512 $$f.tar.gz > $$f.sha512); \
31+
echo $$f; \
32+
done
33+
34+
release: dist
35+
@latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \
36+
comparison="$$latest_tag..HEAD"; \
37+
if [ -z "$$latest_tag" ]; then comparison=""; fi; \
38+
changelog=$$(git log $$comparison --oneline --no-merges --reverse); \
39+
github-release $(GHACCOUNT)/$(NAME) $(VERSION) $(BRANCH) "**Changelog**<br/>$$changelog" 'dist/*'; \
40+
git pull

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ vcheck \
2828
--target=staging.my.grpcapi.net:443 \
2929
--method=/version.Version/GetVersion \
3030
--client=grpc \
31-
--version=${MY_CI_BUILD_NUMBER} \
31+
--expect=${MY_CI_BUILD_NUMBER} \
3232
--count=12 \
3333
--sleep=5
3434
```
@@ -43,7 +43,7 @@ vcheck \
4343
--target=http://staging.my.grpcapi.net \
4444
--method=/api/version \
4545
--client=http \
46-
--version=${MY_CI_BUILD_NUMBER} \
46+
--expect=${MY_CI_BUILD_NUMBER} \
4747
--count=12 \
4848
--sleep=5
4949
```
@@ -55,3 +55,15 @@ vheck util is also available as a docker image
5555
```bash
5656
docker run --rm anjmao:vcheck --help
5757
```
58+
59+
### Release
60+
61+
Before release install gox and github-release tools
62+
```bash
63+
go GO111MODULE=off go get github.com/mitchellh/gox
64+
go GO111MODULE=off go get github.com/c4milo/github-release
65+
```
66+
67+
```bash
68+
make release
69+
```

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPF
1010
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
1111
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
1212
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
13+
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE=
1314
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
1415
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
1516
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

main.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,33 @@ import (
1111
)
1212

1313
var (
14-
target = flag.String("target", "", "-target staging.mpost-api.guardtek.net:443")
15-
expectedVersion = flag.String("version", "", "Expected version")
16-
method = flag.String("method", "/version.Version/GetVersion", "Version check endpoint path")
17-
clientType = flag.String("client", "grpc", "Version check client type")
18-
checkCount = flag.Int("count", 12, "Check count")
19-
sleepAfterCheck = flag.Int("sleep", 5, "Sleep after check in seconds")
20-
showHelp = flag.Bool("help", false, "Show help")
14+
target = flag.String("target", "", "Version check endpoint target")
15+
expectedBuildVersion = flag.String("expect", "", "Expected version")
16+
method = flag.String("method", "/version.Version/GetVersion", "Version check endpoint path")
17+
clientType = flag.String("client", "grpc", "Version check client type")
18+
checkCount = flag.Int("count", 12, "Check count")
19+
sleepAfterCheck = flag.Int("sleep", 5, "Sleep after check in seconds")
20+
printHelp = flag.Bool("help", false, "Print help")
21+
printVersion = flag.Bool("version", false, "Print vcheck version")
2122
)
2223

24+
var Version = "dev"
25+
2326
const checkTimeout = 10 * time.Second
2427

2528
const usageStr = `
2629
Usage: vcheck [options]
2730
Options:
2831
--target <target> Target host including port. (e.g --target service.mydomain.com:443)
29-
--version <version> Expected version (e.g -v 1.2.3)
32+
--expect <version> Expected version (e.g -v 1.2.3)
3033
--method <method> Version check endpoint (default: /debug.Debug/GetVersion)
3134
--client <client> Client type (grpc, http)
3235
--count <count> Check count (default: 12)
3336
--sleep <sleep> Sleep duration after check in seconds (default: 5)
3437
3538
Other options:
36-
--help
39+
--help Print help
40+
--version Print vcheck util version
3741
`
3842

3943
func usage() {
@@ -43,7 +47,13 @@ func usage() {
4347

4448
func main() {
4549
flag.Parse()
46-
if *showHelp || *target == "" || *expectedVersion == "" {
50+
51+
if *printVersion {
52+
fmt.Println(Version)
53+
os.Exit(0)
54+
}
55+
56+
if *printHelp || *target == "" || *expectedBuildVersion == "" {
4757
usage()
4858
}
4959

@@ -59,16 +69,16 @@ func main() {
5969
continue
6070
}
6171
actualVersion = v.BuildVersion
62-
fmt.Printf("expected version %s, got %s\n", *expectedVersion, actualVersion)
63-
if actualVersion == *expectedVersion {
72+
fmt.Printf("expected version %s, got %s\n", *expectedBuildVersion, actualVersion)
73+
if actualVersion == *expectedBuildVersion {
6474
fmt.Println("deployment successful")
6575
return
6676
}
6777

6878
time.Sleep(sleep)
6979
}
7080

71-
log.Fatalf("deployment failed: expected version %s, got %s\n", *expectedVersion, actualVersion)
81+
log.Fatalf("deployment failed: expected version %s, got %s\n", *expectedBuildVersion, actualVersion)
7282
}
7383

7484
func getVersion(c client.Client) (*client.GetVersionReply, error) {

0 commit comments

Comments
 (0)