Skip to content

Commit

Permalink
Add release scripts for the Go client
Browse files Browse the repository at this point in the history
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
Signed-off-by: Jaime Piña <jaime@synadia.com>
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
  • Loading branch information
nsurfer authored and wallyqs committed Apr 2, 2021
1 parent e0d6a6a commit af4d3ab
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 4 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
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 -i -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
35 changes: 35 additions & 0 deletions scripts/post-release.sh
@@ -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
@@ -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

0 comments on commit af4d3ab

Please sign in to comment.