Skip to content

Commit

Permalink
all: run go generate during ci builds to check all files updated (#2372)
Browse files Browse the repository at this point in the history
### What
Run `go generate` during ci builds.

### Why
We use `go generate` to trigger builds of our bindata files for SQL
migrations but we don't have any broad checks on CI that ensure that the
generated files are up to date. This ensures whenever we make a change
to an input file to code generation that the generated file is updated
in the same change/pull-request.

We achieve this to some degree in some apps, like Horizon, where we have
a test that checks that the generated data bytes match the bytes on
disk, but this is only in one app, requires us to write a test in each
app, and doesn't prevent diffs caused by environmental changes like us
upgrading the version of the go-bindata tool.
  • Loading branch information
leighmcculloch authored Mar 9, 2020
1 parent a991284 commit 99e8232
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ commands:
name: Run gofmt
command: ./gofmt.sh

# gogenerate validates that any generated code has been updated if needed.
gogenerate:
steps:
- checkout
- run:
name: Check generated code
command: ./gogenerate.sh

# govet does govet checks in the entire codebase.
govet:
steps:
Expand Down Expand Up @@ -144,6 +152,7 @@ jobs:
- install_go_deps
- check_go_deps
- gofmt
- gogenerate
- govet
- staticcheck

Expand Down
17 changes: 17 additions & 0 deletions gogenerate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /bin/bash
set -e

# Check if go-bindata is installed, if not install it.
command -v go-bindata >/dev/null 2>&1 || (
dir=$(mktemp -d)
pushd $dir
go mod init tool
go get github.com/kevinburke/go-bindata/[email protected]+incompatible
popd
)

printf "Running go generate...\n"
go generate ./...

printf "Checking for no diff...\n"
git diff --exit-code || (echo "Files changed after running go generate. Run go generate ./... locally and update generated files." && exit 1)

0 comments on commit 99e8232

Please sign in to comment.