Skip to content

Go

Go #3098

Workflow file for this run

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.19', '1.20', '1.21', '1.22', '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@v5
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@v4
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@v5
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@v4
- 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