Skip to content

issues/70: Support older versions of Go #682

issues/70: Support older versions of Go

issues/70: Support older versions of Go #682

Workflow file for this run

# DOCS: https://help.github.com/en/articles/workflow-syntax-for-github-actions
name: kama ci
on:
pull_request:
push:
branches:
- main
jobs:
check_release_notes:
name: check_release_notes
timeout-minutes: 1
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4 # since v4, it added cache by default.
with:
go-version: ${{ matrix.go-version }}
- name: checkout main branch too. # so that it is also available for diff operations
uses: actions/checkout@v3
with:
ref: main
- name: Check out code into the Go module directory
uses: actions/checkout@v3
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions
- name: check if changes have release notes
if: github.ref != 'refs/heads/main'
env:
GIT_BRANCH: ${{ github.ref }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_BASE_REF: ${{ github.base_ref }}
run: |
printf "GIT_BRANCH: $GIT_BRANCH \n"
printf "GITHUB_HEAD_REF: $GITHUB_HEAD_REF \n"
printf "GITHUB_BASE_REF: $GITHUB_BASE_REF \n"
printf "list git branches: \n"
git branch --list --all
if [[ "$GIT_BRANCH" == "refs/heads/main" ]]
then
printf "\n $GIT_BRANCH branch, ignoring check for relese notes \n"
elif [[ "$GIT_BRANCH" == *"refs/tags/"* ]]
then
printf "\n $GIT_BRANCH branch, ignoring check for relese notes \n"
else
ChangedFiles=`git diff --name-only remotes/origin/main`
echo $ChangedFiles
case "$ChangedFiles" in
*CHANGELOG.*)
printf "\n Thanks, your commits include update to release notes. \n";;
*)
printf "\n You should add release notes to CHANGELOG.md \n" && exit 77;;
esac
fi
check_go_compatibility:
name: check_go_compatibility
timeout-minutes: 7
strategy:
matrix:
go-version: [1.20.x, 1.21.x, 1.22.x]
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: tests and benchmarks
run: |
go test -count=1 -timeout 1m --exec=/bin/true ./...
run_tests:
name: run_tests
timeout-minutes: 7
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: tests and benchmarks
run: |
go test -timeout 1m -race -run=XXXX -bench=. ./...
go test -timeout 4m -race ./...
- name: test coverage
run: |
set -x
# check integrity of codecov
curl -s https://codecov.io/bash > codecov;
VERSION=$(grep -o 'VERSION=\"[0-9\.]*\"' codecov | cut -d'"' -f2);
shasum --algorithm 512 --check <(curl -s "https://raw.githubusercontent.com/codecov/codecov-bash/${VERSION}/SHA512SUM" | grep codecov)
rm -rf codecov
go test -timeout 4m -race -cover -coverprofile=coverage.out ./... && bash <(curl -s https://codecov.io/bash)
go tool cover -html=coverage.out -o coverage.html
go tool cover -func=coverage.out
run_analysis:
name: run_analysis
timeout-minutes: 5
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: install apt and pip deps
run: |
pwd; ls -lsha
sudo apt-get -y update
sudo apt -y install wget
- name: install tools
run: |
set -x
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/securego/gosec/cmd/gosec@latest
go install github.com/orijtech/structslop/cmd/structslop@latest
go install github.com/orijtech/httperroryzer/cmd/httperroryzer@latest
go install golang.org/x/tools/cmd/stress@latest
go install golang.org/x/tools/cmd/goimports@latest
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
go install github.com/kisielk/errcheck@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
/home/runner/go/bin/staticcheck -version
env:
SOME_ENV_VAR: '2020.1.6'
- name: static analysis
run: |
set -x
diff <(gofmt -d .) <(printf "")
go vet -all ./...
go vet -vettool=/home/runner/go/bin/shadow -strict ./...
/home/runner/go/bin/staticcheck -tests -go 1.20 ./...
# /home/runner/go/bin/gosec ./... # does not yet support generics.
# /home/runner/go/bin/structslop ./... # does not yet support generics.
# /home/runner/go/bin/httperroryzer ./... # re-enable after https://github.com/komuw/kama/issues/63
# see: https://github.com/golang/go/commit/a98589711da5e9d935e8d690cfca92892e86d557
/home/runner/go/bin/errcheck -ignoregenerated -ignoretests -asserts ./...
# dont use golangci-lint
# see: https://twitter.com/dominikhonnef/status/1394766501157167112
#
# In our case we need to use it so that we can be able to use `nolint:gocritic`
# Since `go-ruleguard` does not have a way to ignore per line, see: https://github.com/quasilyte/go-ruleguard/issues/248 .
#
wget -nc --output-document=/tmp/semgrep-go.zip https://github.com/dgryski/semgrep-go/archive/refs/heads/master.zip
unzip -o /tmp/semgrep-go.zip -d /tmp/semgrep-go
go get github.com/quasilyte/go-ruleguard/dsl
golangci-lint run --config .golangci.yml ./...
go mod tidy
# deadlock detection
# https://github.com/cockroachdb/cockroach/issues/7972
go get github.com/sasha-s/go-deadlock
find . -name "*.go" | xargs -n 1 sed -i.backup 's/sync.RWMutex/deadlock.RWMutex/'
find . -name "*.go" | xargs -n 1 sed -i.backup 's/sync.Mutex/deadlock.Mutex/'
find . -name '*.backup' -delete
/home/runner/go/bin/goimports -w .
go test -timeout 4m -race ./...
go mod tidy
# error shadowing
num_err_shadows=$(grep -irSn 'err = ' *.go | wc -l | tr -d ' ')
if [ "$num_err_shadows" != "0" ]; then
printf "\n\t fix error shadowing \n" && \
grep -irSn 'err = ' *.go
exit 77
fi
# TODO: add https://github.com/system-pclub/GCatch
do_acceptance:
name: do_acceptance
timeout-minutes: 3
strategy:
matrix:
go-version: ['>=1.22.0']
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: dummy run
run: |
go build -trimpath -race -o kama cmd/kama/main.go
./kama -h
# run_stress_test:
# name: run_stress_test
# timeout-minutes: 2
# strategy:
# matrix:
# go-version: ['>=1.22.0']
# platform: [ubuntu-22.04]
# runs-on: ${{ matrix.platform }}
# steps:
# - name: Set up Go
# uses: actions/setup-go@v4
# with:
# go-version: ${{ matrix.go-version }}
# - name: Check out code into the Go module directory
# uses: actions/checkout@v3
# - name: stress test
# run: |
# go install golang.org/x/tools/cmd/stress@latest
# go test -o kama.test -c -race
# /home/runner/go/bin/stress -timeout 10s ./kama.test