#!/bin/bash

set -e

git clone bosh-utils bumped-bosh-utils

cd bumped-bosh-utils

go get -u ./...
go mod tidy
go mod vendor

if [ "$(git status --porcelain)" != "" ]; then
  git status
  git add vendor go.sum go.mod
  git config user.name "CI Bot"
  git config user.email "cf-bosh-eng@pivotal.io"
  git commit -m "Update vendored dependencies"
fi


#!/bin/bash

set -e

git clone bosh-utils bumped-bosh-utils

cd bumped-bosh-utils

#intentionally cause an explicit commit if the underlying go version in our compiled Dockerfile changes. 
#assume the go-dep-bumper and bosh-utils are bumping at the same cadence.
NEW_GO_MINOR=$(go version | sed 's/go version go1\.\([0-9]\+\)\..*$/\1/g')
CURRENT_GO_MINOR=$(cat go.mod | grep -E "^go 1.*" | sed "s/^\(go 1.\)\([0-9]\+\)/\2/")
sed -i "s/^\(go 1.\)\([0-9]\+\)/\1$NEW_GO_MINOR/" go.mod

go get -u ./...
go mod tidy
go mod vendor

if [ "$(git status --porcelain)" != "" ]; then
  git status
  git add vendor go.sum go.mod
  git config user.name "CI Bot"
  git config user.email "cf-bosh-eng@pivotal.io"
  if [ $CURRENT_GO_MINOR == $NEW_GO_MINOR ]; then
    git commit -m "Update vendored dependencies"
  else
    git commit -m "Bump to go version 1.$NEW_GO_MINOR\n\n- (and update vendored dependencies)"
  fi
fi


Update go.mod when go version changes.
Update go.mod when go version changes.

- The go version which we use to compile bosh-utils is the latest minor
  that appears in the golang docker image.
- We pull the minor version from the 'go version' statement and if it
  differs from the version currently in go.mod, we alter go.mod + change
  the commit text.
- Dependencies are updated in either case.
- As a team, we've decided to always update go.mod to reflect the latest
  version of go we are using. This gives folks a hint as to what verison
  we're using to compile + ensures that all of our dependencies are
  similarly as up to date as possible (if we leave the go.mod as a
  minimum version, it's possible some dependencies might not update).
- We assume that we will be on the Go 1.x line indefinitely. Work will
  need to happen when Go 2 comes out (we won't auto-bump major
  versions).

Signed-off-by: Rajan Agaskar <88955f44d2c8b2f41a6080176378df0ad984a07e@vmware.com>
