Go #2727
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
go: ['1.18', '1.19', '1.20', '1.x'] | |
steps: | |
- name: Install protobuf | |
uses: arduino/setup-protoc@v1 | |
with: | |
version: '3.x' | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go }} | |
id: go | |
- name: Install protoc-gen-go, goimports, Staticcheck | |
run: | | |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | |
go install golang.org/x/tools/cmd/goimports@latest | |
- name: Check out code | |
uses: actions/checkout@v3 | |
with: | |
path: go/src/github.com/openconfig/ygot | |
- name: Get dependencies | |
run: | | |
go get -v -t -d ./... | |
working-directory: go/src/github.com/openconfig/ygot | |
- name: Generate dependencies | |
run: make generate | |
working-directory: go/src/github.com/openconfig/ygot | |
- name: Build packages | |
run: go build -v ./... | |
working-directory: go/src/github.com/openconfig/ygot | |
- name: Run Tests | |
run: go test -v ./... | |
working-directory: go/src/github.com/openconfig/ygot | |
- name: Run race tests | |
run: go test -race -v ./... | |
working-directory: go/src/github.com/openconfig/ygot | |
- name: Check that Go integration test files compile | |
working-directory: go/src/github.com/openconfig/ygot | |
run: | | |
function test-go-build() { | |
cwd=$(pwd) | |
tmpdir=$(mktemp -d -p $cwd) | |
for f in "$@"; do | |
name=$(basename $f) | |
cp "$f" "$tmpdir"/"${name}.go" | |
done | |
cd $tmpdir | |
goimports -w *.go | |
go build | |
cd $cwd | |
rm -r $tmpdir | |
} | |
skipped=( | |
# fake ygot and ytype paths specified in generation options. | |
"openconfig-options-explicit.formatted-txt.go" | |
) | |
for f in gogen/testdata/schema/*.formatted-txt; do | |
if [[ ${skipped[@]} =~ $(basename $f) ]]; then | |
continue | |
fi | |
test-go-build $f | |
done | |
skipped=( | |
) | |
for f in gogen/testdata/structs/*.formatted-txt; do | |
if [[ ${skipped[@]} =~ $(basename $f) ]]; then | |
continue | |
fi | |
test-go-build $f | |
done | |
skipped=( | |
# GoStructs in a separate package, harder to set-up. | |
"openconfig-augmented.path-txt" | |
"openconfig-withlist-separate-package.path-txt" | |
) | |
for f in ypathgen/testdata/structs/*.path-txt; do | |
if [[ ${skipped[@]} =~ $(basename $f) ]]; then | |
continue | |
fi | |
filename=$(basename $f) | |
f_prefix="${filename%%.*}" | |
go_file="gogen/testdata/structs/${f_prefix}.formatted-txt" | |
test-go-build $f $go_file | |
done | |
- name: Make sure exampleoc doesn't error or panic | |
run: | | |
go install golang.org/x/tools/cmd/stringer@latest | |
go generate ./... | |
working-directory: go/src/github.com/openconfig/ygot | |
static_analysis: | |
name: Static Analysis | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.x' | |
id: go | |
- name: Install required static analysis tools | |
run: | | |
go install github.com/mattn/goveralls@latest | |
go install honnef.co/go/tools/cmd/staticcheck@latest | |
- name: Check out ygot code | |
uses: actions/checkout@v3 | |
- name: Get dependencies | |
run: | | |
go get -v -t -d ./... | |
- name: Run coverage | |
run: | | |
pkgs="$(go list ./... | grep -v 'github.com/openconfig/ygot/exampleoc' | grep -v 'github.com/openconfig/ygot/uexampleoc' | grep -v 'github.com/openconfig/ygot/proto/' | grep -v 'github.com/openconfig/ygot/demo/' | grep -v 'github.com/openconfig/ygot/integration_tests' | grep -v 'github.com/openconfig/ygot/generator' | grep -v 'github.com/openconfig/ygot/gnmidiff/cmd' | tr '\n' ' ')" | |
for p in $pkgs; do | |
dir=$(echo $p | sed -e 's/^github\.com\/openconfig\/ygot\///') | |
go test -covermode count -coverprofile profile.coverprofile -outputdir $dir $p | |
done | |
# Overwrite results for gogen/protogen since they also cover ygen's | |
# and testutil's code. | |
go test -covermode count -coverprofile profile.coverprofile -outputdir gogen -coverpkg github.com/openconfig/ygot/gogen,github.com/openconfig/ygot/ygen,github.com/openconfig/ygot/testutil github.com/openconfig/ygot/gogen | |
go test -covermode count -coverprofile profile.coverprofile -outputdir protogen -coverpkg github.com/openconfig/ygot/protogen,github.com/openconfig/ygot/ygen,github.com/openconfig/ygot/testutil github.com/openconfig/ygot/protogen | |
# Also cover testutil,yreflect from util, ytypes and ygot packages | |
go test -covermode count -coverprofile profile.coverprofile -outputdir util -coverpkg github.com/openconfig/ygot/util,github.com/openconfig/ygot/testutil,github.com/openconfig/ygot/internal/yreflect github.com/openconfig/ygot/util | |
go test -covermode count -coverprofile profile.coverprofile -outputdir ygot -coverpkg github.com/openconfig/ygot/ygot,github.com/openconfig/ygot/testutil,github.com/openconfig/ygot/internal/yreflect github.com/openconfig/ygot/ygot | |
go test -covermode count -coverprofile profile.coverprofile -outputdir ytypes -coverpkg github.com/openconfig/ygot/ytypes,github.com/openconfig/ygot/testutil,github.com/openconfig/ygot/internal/yreflect github.com/openconfig/ygot/ytypes | |
echo 'mode: count' > concatenated.coverprofile | |
for p in $pkgs; do | |
dir=$(echo $p | sed -e 's/^github\.com\/openconfig\/ygot\///') | |
tail -n +2 $dir/profile.coverprofile >> concatenated.coverprofile | |
done | |
- name: Submit coverage | |
uses: shogo82148/actions-goveralls@v1 | |
with: | |
path-to-profile: concatenated.coverprofile | |
- name: Go vet | |
run: | | |
for i in util ygen ytypes ygot/pathtranslate ypathgen; do | |
go vet ./$i | |
done | |
for j in ygot testcmp testutil; do | |
go vet -composites=false ./$j | |
done | |
- name: Gofmt | |
run: | | |
for i in `find . -type d | egrep -v "exampleoc|demo|proto|uexampleoc"`; do | |
diff -u <(echo -n) <(gofmt -d -s ./$i) | |
done | |
- name: Go Mod should be tidy | |
run: | | |
go mod tidy | |
diff -u <(echo -n) <(git diff) | |
- name: Staticcheck | |
run: | | |
checkstr="" | |
for i in util ygot ygen ytypes ygot/pathtranslate testutil testcmp ypathgen; do | |
checkstr="$checkstr github.com/openconfig/ygot/$i/..." | |
done | |
staticcheck $checkstr |