Skip to content

Add release scripts for the Go client #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ install:
- go get -u github.com/client9/misspell/cmd/misspell
before_script:
- $(exit $(go fmt ./... | wc -l))
- go vet ./...
- if [[ ! -f 'go_test.mod' ]]; then cp go.mod go_test.mod; cp go.sum go_test.sum; fi
- go vet -modfile=go_test.mod ./...
- find . -type f -name "*.go" | xargs misspell -error -locale US
- staticcheck ./...
script:
- go test -i -race ./...
- go test -v -run=TestNoRace -p=1 ./...
- if [[ "$TRAVIS_GO_VERSION" =~ 1.16 ]]; then ./scripts/cov.sh TRAVIS; else go test -race -v -p=1 ./... --failfast; fi
- go test -modfile=go_test.mod -race ./...
- go test -modfile=go_test.mod -v -run=TestNoRace -p=1 ./...
- if [[ "$TRAVIS_GO_VERSION" =~ 1.16 ]]; then ./scripts/cov.sh TRAVIS; else go test -modfile=go_test.mod -race -v -p=1 ./... --failfast; fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: we use -modfile here and line above, but ./scripts/cov.sh is not. Is that a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes those entries were missing -modfile so have updated now.

8 changes: 4 additions & 4 deletions scripts/cov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

rm -rf ./cov
mkdir cov
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/nats.out
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/test.out -coverpkg=github.com/nats-io/nats.go ./test
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/builtin.out -coverpkg=github.com/nats-io/nats.go/encoders/builtin ./test -run EncBuiltin
go test --failfast -v -race -covermode=atomic -coverprofile=./cov/protobuf.out -coverpkg=github.com/nats-io/nats.go/encoders/protobuf ./test -run EncProto
go test -modfile=go_test.mod --failfast -v -race -covermode=atomic -coverprofile=./cov/nats.out
go test -modfile=go_test.mod --failfast -v -race -covermode=atomic -coverprofile=./cov/test.out -coverpkg=github.com/nats-io/nats.go ./test
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
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
gocovmerge ./cov/*.out > acc.out
rm -rf ./cov

Expand Down
35 changes: 35 additions & 0 deletions scripts/post-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail

tag=${1:-}
if [[ -z "${tag}" ]]; then
echo "missing tag"
echo "usage: post-release.sh <tag>"
exit 1
fi

WC='\033[0;36m'
NC='\033[0m'
echo -e "${WC}=== Cleaning up === ${NC}"

# Return master to development mode once again.
mv go_test.mod go.mod
mv go_test.sum go.sum

go test ./... -p=1 -v

echo
echo -e "${WC}=== Run the following commands to finish the release === ${NC}"
echo
echo " git add go.mod go.sum"
echo " git rm go_test.mod go_test.sum"
echo " git commit -s -m 'Post Release ${tag} steps'"
echo " git checkout master"
echo " git merge --no-ff 'release/${tag}'"
echo " git push origin master"
echo
echo " # Delete release branch"
echo " git push origin :release/${tag}"
echo
echo
echo
64 changes: 64 additions & 0 deletions scripts/pre-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -euo pipefail

tag=${1:-}
if [[ -z "${tag}" ]]; then
echo "missing tag"
echo "usage: pre-release.sh <tag>"
exit 1
fi

WC='\033[0;36m'
NC='\033[0m'
echo -e "${WC}=== Creating release branch === ${NC}"

releaseBranch="release/${tag}"
git checkout -b "${releaseBranch}"
mv go.mod go_test.mod
mv go.sum go_test.sum

# Start with empty go.mod file
go mod init

# Build example with the minimal go.mod, this will leave out test dependencies.
# -mod flag instructs to fetch dependencies as needed.
echo -e "${WC}=== Building minimal go.mod === ${NC}"
go build -mod=mod examples/nats-sub/main.go

# Run the tests locally and confirm they pass.
echo -e "${WC}=== Running tests === ${NC}"
sleep 1

# Use readonly to ensure that dependencies are not changed while running tests.
go test ./... -p=1 -v -modfile=go_test.mod -mod=readonly

# Confirm the different in dependencies. go_test.mod should only have test
# dependencies.
modDiff=$(diff go.mod go_test.mod || true)
if [[ -z "${modDiff}" ]]; then
echo "go.mod and go_test.mod are the same"
echo "confirm that test dependencies are being left out and try again"
exit 1
fi

echo
echo -e "${WC}=== diff go.mod go_test.mod === ${NC}"
echo
echo "${modDiff}"
echo
echo
read -e -r -p "Are the test dependencies left out? [y/n] " diffOk
if ! [[ "$diffOk" =~ ^(yes|y)$ ]]; then
echo "diff not ok, aborting"
exit 1
fi

echo
echo -e "${WC}=== Run the following commands to tag the release === ${NC}"
echo
echo " git add go.mod go.sum go_test.mod go_test.sum"
echo " git commit -s -m 'Release ${tag}'"
echo " git tag -m '${tag}' -a ${tag}"
echo " git push origin ${releaseBranch} --tags"
echo
echo