Skip to content

Commit 94f8211

Browse files
nsurferwallyqs
authored andcommitted
Add release scripts for the Go client
Signed-off-by: Waldemar Quevedo <[email protected]> Signed-off-by: Jaime Piña <[email protected]>
1 parent e0d6a6a commit 94f8211

File tree

4 files changed

+108
-8
lines changed

4 files changed

+108
-8
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ install:
1111
- go get -u github.com/client9/misspell/cmd/misspell
1212
before_script:
1313
- $(exit $(go fmt ./... | wc -l))
14-
- go vet ./...
14+
- if [[ ! -f 'go_test.mod' ]]; then cp go.mod go_test.mod; cp go.sum go_test.sum; fi
15+
- go vet -modfile=go_test.mod ./...
1516
- find . -type f -name "*.go" | xargs misspell -error -locale US
1617
- staticcheck ./...
1718
script:
18-
- go test -i -race ./...
19-
- go test -v -run=TestNoRace -p=1 ./...
20-
- if [[ "$TRAVIS_GO_VERSION" =~ 1.16 ]]; then ./scripts/cov.sh TRAVIS; else go test -race -v -p=1 ./... --failfast; fi
19+
- go test -modfile=go_test.mod -race ./...
20+
- go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./...
21+
- if [[ "$TRAVIS_GO_VERSION" =~ 1.16 ]]; then ./scripts/cov.sh TRAVIS; else go test -modfile=go_test.mod -race -v -p=1 ./... --failfast; fi

scripts/cov.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
rm -rf ./cov
55
mkdir cov
6-
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/nats.out
7-
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/test.out -coverpkg=github.com/nats-io/nats.go ./test
8-
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/builtin.out -coverpkg=github.com/nats-io/nats.go/encoders/builtin ./test -run EncBuiltin
9-
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/protobuf.out -coverpkg=github.com/nats-io/nats.go/encoders/protobuf ./test -run EncProto
6+
go test -modfile=go_test.mod --failfast -v -race -covermode=atomic -coverprofile=./cov/nats.out
7+
go test -modfile=go_test.mod --failfast -v -race -covermode=atomic -coverprofile=./cov/test.out -coverpkg=github.com/nats-io/nats.go ./test
8+
go test -modfile=go_test.mod --failfast -v -race -covermode=atomic -coverprofile=./cov/builtin.out -coverpkg=github.com/nats-io/nats.go/encoders/builtin ./test -run EncBuiltin
9+
go test -modfile=go_test.mod --failfast -v -race -covermode=atomic -coverprofile=./cov/protobuf.out -coverpkg=github.com/nats-io/nats.go/encoders/protobuf ./test -run EncProto
1010
gocovmerge ./cov/*.out > acc.out
1111
rm -rf ./cov
1212

scripts/post-release.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
tag=${1:-}
5+
if [[ -z "${tag}" ]]; then
6+
echo "missing tag"
7+
echo "usage: post-release.sh <tag>"
8+
exit 1
9+
fi
10+
11+
WC='\033[0;36m'
12+
NC='\033[0m'
13+
echo -e "${WC}=== Cleaning up === ${NC}"
14+
15+
# Return master to development mode once again.
16+
mv go_test.mod go.mod
17+
mv go_test.sum go.sum
18+
19+
go test ./... -p=1 -v
20+
21+
echo
22+
echo -e "${WC}=== Run the following commands to finish the release === ${NC}"
23+
echo
24+
echo " git add go.mod go.sum"
25+
echo " git rm go_test.mod go_test.sum"
26+
echo " git commit -s -m 'Post Release ${tag} steps'"
27+
echo " git checkout master"
28+
echo " git merge --no-ff 'release/${tag}'"
29+
echo " git push origin master"
30+
echo
31+
echo " # Delete release branch"
32+
echo " git push origin :release/${tag}"
33+
echo
34+
echo
35+
echo

scripts/pre-release.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
tag=${1:-}
5+
if [[ -z "${tag}" ]]; then
6+
echo "missing tag"
7+
echo "usage: pre-release.sh <tag>"
8+
exit 1
9+
fi
10+
11+
WC='\033[0;36m'
12+
NC='\033[0m'
13+
echo -e "${WC}=== Creating release branch === ${NC}"
14+
15+
releaseBranch="release/${tag}"
16+
git checkout -b "${releaseBranch}"
17+
mv go.mod go_test.mod
18+
mv go.sum go_test.sum
19+
20+
# Start with empty go.mod file
21+
go mod init
22+
23+
# Build example with the minimal go.mod, this will leave out test dependencies.
24+
# -mod flag instructs to fetch dependencies as needed.
25+
echo -e "${WC}=== Building minimal go.mod === ${NC}"
26+
go build -mod=mod examples/nats-sub/main.go
27+
28+
# Run the tests locally and confirm they pass.
29+
echo -e "${WC}=== Running tests === ${NC}"
30+
sleep 1
31+
32+
# Use readonly to ensure that dependencies are not changed while running tests.
33+
go test ./... -p=1 -v -modfile=go_test.mod -mod=readonly
34+
35+
# Confirm the different in dependencies. go_test.mod should only have test
36+
# dependencies.
37+
modDiff=$(diff go.mod go_test.mod || true)
38+
if [[ -z "${modDiff}" ]]; then
39+
echo "go.mod and go_test.mod are the same"
40+
echo "confirm that test dependencies are being left out and try again"
41+
exit 1
42+
fi
43+
44+
echo
45+
echo -e "${WC}=== diff go.mod go_test.mod === ${NC}"
46+
echo
47+
echo "${modDiff}"
48+
echo
49+
echo
50+
read -e -r -p "Are the test dependencies left out? [y/n] " diffOk
51+
if ! [[ "$diffOk" =~ ^(yes|y)$ ]]; then
52+
echo "diff not ok, aborting"
53+
exit 1
54+
fi
55+
56+
echo
57+
echo -e "${WC}=== Run the following commands to tag the release === ${NC}"
58+
echo
59+
echo " git add go.mod go.sum go_test.mod go_test.sum"
60+
echo " git commit -s -m 'Release ${tag}'"
61+
echo " git tag -m '${tag}' -a ${tag}"
62+
echo " git push origin ${releaseBranch} --tags"
63+
echo
64+
echo

0 commit comments

Comments
 (0)