Skip to content

Go

Go #27123

Workflow file for this run

name: Go
on:
push:
branches: [ main ]
pull_request:
schedule:
- cron: "0 0 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Go & staticcheck build cache require a lot of disk space. Reclaim extra
# space for the container by removing unnecessary tooling.
- name: Free additional disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/hostedtoolcache/CodeQL
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: Move cache
run: |
sudo mv "${HOME}/.cache" /mnt/cache
ln -s /mnt/cache "${HOME}/.cache"
# Dependency for Go module github.com/google/gopacket
- name: Install libpcap-dev
run: sudo apt-get -y install libpcap-dev
- name: Build
run: go build -v ./...
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Go & staticcheck build cache require a lot of disk space. Reclaim extra
# space for the container by removing unnecessary tooling.
- name: Free additional disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/hostedtoolcache/CodeQL
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: Move cache
run: |
sudo mv "${HOME}/.cache" /mnt/cache
ln -s /mnt/cache "${HOME}/.cache"
# Dependency for Go module github.com/google/gopacket
- name: Install libpcap-dev
run: sudo apt-get -y install libpcap-dev
- run: go test -v -coverprofile=profile.cov $(go list ./... | grep -v /.*test.*)
- name: Send coverage
continue-on-error: true
uses: shogo82148/actions-goveralls@7b1bd2871942af030d707d6574e5f684f9891fb2
with:
path-to-profile: profile.cov
static_analysis:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Free additional disk space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/hostedtoolcache/CodeQL
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: Move cache
run: |
sudo mv "${HOME}/.cache" /mnt/cache
ln -s /mnt/cache "${HOME}/.cache"
# Dependency for Go module github.com/google/gopacket
- name: Install libpcap-dev
run: sudo apt-get -y install libpcap-dev
# === THIS IS THE ONLY CHANGE ===
- name: Clean Go build cache before analysis
run: go clean -cache
# ===============================
- name: Go vet
run: GOGC=30 go vet ./...
- name: Gofmt
run: |
# gofmt always returns true, so we use grep '^' which returns
# true on non-empty output, but will otherwise passthrough all
# output lines.
if gofmt -d -s . | grep '^'; then
exit 1
fi
- name: Get goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Goimports
run: |
# goimports always returns true, so we use grep '^' which returns
# true on non-empty output, but will otherwise passthrough all
# output lines.
#
# goimports does not support "gofmt -s" so both goimports and gofmt are
# required.
find . -name "*.go" | egrep -v "pb.go$" | while read l; do
if goimports -d $l | grep '^'; then
exit 1;
fi;
done
- name: Get revive
run: go install github.com/mgechev/[email protected]
- name: Run revive
run: revive ./...
- name: Get staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Run staticcheck
run: GOGC=30 staticcheck ./...