Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: make go workflow faster #3664

Merged
merged 14 commits into from Dec 19, 2022
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
*.go text eol=lf
17 changes: 13 additions & 4 deletions .github/workflows/beekeeper.yml
Expand Up @@ -45,8 +45,17 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
cache: true
cache: false
go-version-file: go.mod
- name: Cache Go Modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get Commit Message
id: commit
run: |
Expand Down Expand Up @@ -119,15 +128,15 @@ jobs:
- name: Set local cluster
run: |
timeout ${TIMEOUT} make deploylocal BEEKEEPER_CLUSTER=local-dns
- name: Test staking
id: stake
run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks ci-stake
- name: Test pingpong
id: pingpong
run: timeout ${TIMEOUT} bash -c 'until beekeeper check --cluster-name local-dns --checks ci-pingpong; do echo "waiting for pingpong..."; sleep .3; done'
- name: Test fullconnectivity
id: fullconnectivity
run: timeout ${TIMEOUT} bash -c 'until beekeeper check --cluster-name local-dns --checks=ci-full-connectivity; do echo "waiting for full connectivity..."; sleep .3; done'
- name: Test staking
id: stake
run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks ci-stake
- name: Test settlements
id: settlements
run: timeout ${TIMEOUT} beekeeper check --cluster-name local-dns --checks=ci-settlements
Expand Down
86 changes: 59 additions & 27 deletions .github/workflows/go.yml
Expand Up @@ -2,72 +2,104 @@ name: Go

on:
push:
paths-ignore:
- packaging/**
branches:
- 'master'
pull_request:
paths-ignore:
- packaging/**
branches:
- '**'

jobs:
build:
name: Build
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
if: matrix.os == 'ubuntu-latest'
uses: actions/setup-go@v3
with:
cache: false
cache: true
go-version-file: go.mod
- name: Build
run: make build
- name: Test with race detector (Ubuntu and MacOS)
if: matrix.os != 'windows-latest'
run: make test-race-ci
- name: Test without race detector (Windows)
if: matrix.os == 'windows-latest'
run: make test-ci
golangci-lint:
name: GolangCI-Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
if: matrix.os == 'macos-latest' || matrix.os == 'windows-latest'
uses: actions/setup-go@v3
with:
cache: true
cache: false
go-version-file: go.mod
- name: Set git to use LF
# make sure that line endings are not converted on windows
# as gofmt linter will report that they need to be changed
run: git config --global core.autocrlf false
- name: Commit linting
if: matrix.os == 'ubuntu-latest' && github.ref != 'refs/heads/master'
if: github.ref != 'refs/heads/master'
uses: wagoid/commitlint-github-action@v5
- name: GolangCI-Lint
if: matrix.os == 'ubuntu-latest'
uses: golangci/golangci-lint-action@v3
with:
skip-cache: false
version: v1.49
- name: Build
run: make build
- name: Test whitespaces, race detector & code coverage
if: matrix.os == 'ubuntu-latest'
# only generate code coverage profile on ubuntu
coverage:
name: Coverage Report
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
cache: false
go-version-file: go.mod
- name: Cache Go Modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-coverage-${{ hashFiles('**/go.sum') }}
- name: Test whitespaces and code coverage
run: |
make check-whitespace
make cover=1 test-race
- name: Test with race detector (MacOS)
if: matrix.os == 'macos-latest'
run: make test-race
- name: Test without race detector (Windows)
if: matrix.os == 'windows-latest'
run: make test
make cover=1 test-ci
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ./cover.out
trigger-beekeeper:
name: Trigger Beekeeper
runs-on: ubuntu-latest
needs: [build, golangci-lint, coverage]
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
with:
cache: false
go-version-file: go.mod
- name: Trigger Beekeeper
if: github.ref == 'refs/heads/master' && matrix.os == 'ubuntu-latest' && success()
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GHA_PAT_BASIC }}
Expand Down
37 changes: 22 additions & 15 deletions Makefile
Expand Up @@ -12,12 +12,6 @@ BEEKEEPER_BRANCH ?= master
REACHABILITY_OVERRIDE_PUBLIC ?= false
BATCHFACTOR_OVERRIDE_PUBLIC ?= 5

GO_MIN_VERSION ?= "1.17"
GO_BUILD_VERSION ?= "1.17.2"
GO_MOD_ENABLED_VERSION ?= "1.12"
GO_MOD_VERSION ?= "$(shell go mod edit -print | awk '/^go[ \t]+[0-9]+\.[0-9]+(\.[0-9]+)?[ \t]*$$/{print $$2}')"
GO_SYSTEM_VERSION ?= "$(shell go version | awk '{ gsub(/go/, "", $$3); print $$3 }')"

BEE_API_VERSION ?= "$(shell grep '^ version:' openapi/Swarm.yaml | awk '{print $$2}')"
BEE_DEBUG_API_VERSION ?= "$(shell grep '^ version:' openapi/SwarmDebug.yaml | awk '{print $$2}')"

Expand Down Expand Up @@ -112,26 +106,39 @@ else
$(GO) test -race -failfast -v ./...
endif

.PHONY: test-race-ci
test-race-ci:
ifdef cover
$(GO) test -race -coverprofile=cover.out -v ./...
else
$(GO) test -race -v ./...
endif

.PHONY: test-integration
test-integration:
$(GO) test -tags=integration -v ./...

.PHONY: test
test:
$(GO) test -v -failfast ./...
ifdef cover
$(GO) test -failfast -coverprofile=cover.out -v ./...
else
$(GO) test -failfast -v ./...
endif

.PHONY: test-ci
test-ci:
ifdef cover
$(GO) test -coverprofile=cover.out -v ./...
else
$(GO) test -v ./...
endif

.PHONY: build
build: CGO_ENABLED=0
build: check-version
build: export CGO_ENABLED=0
build:
$(GO) build -trimpath -ldflags "$(LDFLAGS)" ./...

.PHONY: check-version
check-version:
[ ${GO_SYSTEM_VERSION} \< ${GO_MOD_ENABLED_VERSION} ] && echo "The version of Golang on the system (${GO_SYSTEM_VERSION}) is too old and does not support go modules. Please use at least ${GO_MIN_VERSION}." && exit 1; exit 0
[ ${GO_SYSTEM_VERSION} \< ${GO_MIN_VERSION} ] && echo "The version of Golang on the system (${GO_SYSTEM_VERSION}) is below the minimum required version (${GO_MIN_VERSION}) and therefore will not build correctly." && exit 1; exit 0
if ! expr ${GO_BUILD_VERSION} : ^${GO_MOD_VERSION} 1>/dev/null; then echo "The version of Golang mod (${GO_MOD_VERSION}) does not match required version (${GO_BUILD_VERSION})." && exit 1; fi

.PHONY: githooks
githooks:
ln -f -s ../../.githooks/pre-push.bash .git/hooks/pre-push
Expand Down