2020-12-12 03:06:59 +03:00
|
|
|
name: Go
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
name: Build and Lint
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2020-12-12 15:23:33 +03:00
|
|
|
|
|
|
|
# Setup
|
2020-12-12 03:06:59 +03:00
|
|
|
- name: Setup Go
|
|
|
|
uses: actions/setup-go@v2
|
|
|
|
with:
|
|
|
|
go-version: '^1.15'
|
2020-12-12 15:23:33 +03:00
|
|
|
- name: Install Protoc
|
|
|
|
uses: arduino/setup-protoc@v1
|
|
|
|
- name: Checkout code
|
2020-12-12 03:06:59 +03:00
|
|
|
uses: actions/checkout@v2
|
2020-12-12 15:23:33 +03:00
|
|
|
|
|
|
|
# Formatting, go mod tidy, and re-generate proto extension code
|
2020-12-12 12:28:25 +03:00
|
|
|
- name: Run go fmt on all modules
|
2020-12-12 12:25:35 +03:00
|
|
|
run: find . -name go.mod -execdir go fmt ./... \;
|
2020-12-12 03:06:59 +03:00
|
|
|
- name: Run go mod tidy on all modules
|
|
|
|
run: find . -name go.mod -execdir go mod tidy \;
|
2020-12-12 15:23:33 +03:00
|
|
|
- name: Run go generate
|
|
|
|
run: go generate
|
|
|
|
|
|
|
|
# If there are any diffs from go fmt, go mod tidy, or go generate then fail.
|
|
|
|
- name: Verify no changes from go fmt, go mod tidy, go generate. If you're reading this please re-run locally before PR.
|
2020-12-12 03:06:59 +03:00
|
|
|
run: |
|
|
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
|
|
git status # Show the files that failed to pass the check.
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-12-12 15:23:33 +03:00
|
|
|
|
|
|
|
# Linting check
|
2020-12-12 03:06:59 +03:00
|
|
|
- name: go vet
|
|
|
|
# Use find to build all modules. '-execdir ... ;' doesn't set an exit code
|
|
|
|
# based on command results. So, create a file if a build fails and check
|
|
|
|
# if the file exists to set the right exit code.
|
|
|
|
run: |
|
|
|
|
ROOT_DIR=$(pwd) \
|
|
|
|
find . -name go.mod -execdir sh -c 'go vet ./... || touch $ROOT_DIR/vet_failed.txt' \; ; \
|
|
|
|
test ! -f vet_failed.txt
|
2020-12-12 15:23:33 +03:00
|
|
|
|
|
|
|
# Build
|
2020-12-12 03:06:59 +03:00
|
|
|
- name: Build code
|
|
|
|
# Use find to build all modules. '-execdir ... ;' doesn't set an exit code
|
|
|
|
# based on command results. So, create a file if a build fails and check
|
|
|
|
# if the file exists to set the right exit code.
|
|
|
|
run: |
|
|
|
|
ROOT_DIR=$(pwd) \
|
|
|
|
find . -name go.mod -execdir sh -c 'go build ./... || touch $ROOT_DIR/build_failed.txt' \; ; \
|
|
|
|
test ! -f build_failed.txt
|
2020-12-12 15:23:33 +03:00
|
|
|
|
|
|
|
# Verify examples are pristine
|
|
|
|
- name: Run examples
|
|
|
|
run: protoc --plugin=protoc-gen-bq-schema --bq-schema_out=examples examples/foo.proto
|
|
|
|
- name: Verify examples are working
|
|
|
|
run: |
|
|
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
|
|
git status # Show the files that failed to pass the check.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-12-12 03:06:59 +03:00
|
|
|
test:
|
|
|
|
name: Root tests
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Setup Go
|
|
|
|
uses: actions/setup-go@v2
|
|
|
|
with:
|
|
|
|
go-version: '^1.15'
|
|
|
|
- name: Check code
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
- run: go test -v
|