Update README.md #595
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
# DOCS: | |
# 1. https://help.github.com/en/articles/workflow-syntax-for-github-actions | |
# 2. https://github.com/mvdan/github-actions-golang/issues/22 | |
# 3. https://github.com/stellar/go/blob/master/.github/actions/setup-go/action.yml | |
# 4. https://github.com/stellar/go/blob/master/.github/workflows/go.yml | |
# 5. https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds | |
# 6. https://github.com/golang/go/issues/58571 | |
name: ote ci | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
jobs: | |
check_release_notes: | |
name: check_release_notes | |
timeout-minutes: 1 | |
strategy: | |
matrix: | |
go-version: ['>=1.21.0'] | |
platform: [ubuntu-22.04] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
# checkout main branch and the current branch so that we are able to do diff operations. | |
- name: checkout main branch too. | |
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 | |
run_tests: | |
name: run_tests | |
timeout-minutes: 7 | |
strategy: | |
matrix: | |
go-version: ['>=1.21.0'] | |
platform: [ubuntu-22.04] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 # since v4, it added cache by default. | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: tests and benchmarks | |
run: | | |
ulimit -a | |
env | |
set -x | |
go test -timeout 1m -race -run=XXXX -bench=. ./... | |
go test -timeout 4m -race -cover -coverprofile=coverage.out -shuffle on ./... | |
go tool cover -html=coverage.out -o coverage.html | |
go tool cover -func=coverage.out | |
wget -nc --output-document=/tmp/codecov https://github.com/codecov/uploader/releases/download/v0.3.5/codecov-linux | |
chmod +x /tmp/codecov | |
/tmp/codecov | |
- name: dummy run | |
run: | | |
go build -trimpath -race -o ote . | |
./ote -h | |
./ote -f testdata/modfiles/mod1 -r | |
run_analysis: | |
name: run_analysis | |
timeout-minutes: 6 | |
strategy: | |
matrix: | |
go-version: ['>=1.21.0'] | |
platform: [ubuntu-22.04] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: install apt and pip deps | |
run: | | |
pwd; ls -lsha | |
sudo apt -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/quasilyte/go-ruleguard/cmd/ruleguard@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 golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@latest | |
go install github.com/kisielk/errcheck@latest | |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | |
go install mvdan.cc/gofumpt@latest | |
go install golang.org/x/vuln/cmd/govulncheck@latest | |
go install github.com/mdempsky/unconvert@latest | |
go install github.com/zricethezav/gitleaks/v8@latest | |
# go install gvisor.dev/gvisor/tools/checklocks/cmd/checklocks@latest | |
go install gvisor.dev/gvisor/tools/checklocks/cmd/[email protected] | |
/home/runner/go/bin/staticcheck -version | |
env: | |
SOME_ENV_VAR: '2020.1.6' | |
- name: static analysis | |
run: | | |
set -x | |
diff <(gofmt -d .) <(printf "") | |
diff <(gofumpt -extra -w -d .) <(printf "") | |
diff <(goimports -d .) <(printf "") | |
go vet -all ./... | |
go vet -vettool=/home/runner/go/bin/shadow -strict ./... | |
go vet -vettool=/home/runner/go/bin/nilness -test ./... | |
/home/runner/go/bin/checklocks -test=false ./... | |
/home/runner/go/bin/staticcheck -tests ./... | |
govulncheck ./... | |
# /home/runner/go/bin/gosec ./... # does not seem to work with Go1.21 | |
# /home/runner/go/bin/structslop ./... # does not seem to work with Go1.21 | |
/home/runner/go/bin/httperroryzer ./... | |
# see: https://github.com/golang/go/commit/a98589711da5e9d935e8d690cfca92892e86d557 | |
/home/runner/go/bin/errcheck -ignoregenerated -ignoretests -asserts ./... | |
/home/runner/go/bin/unconvert -v ./... | |
/home/runner/go/bin/gitleaks detect . -v --no-git --baseline-path .gitleaksignore | |
# To create the gitleaksignore file, run; | |
# rm -rf .gitleaksignore; gitleaks detect . --no-git --report-path .gitleaksignore | |
# 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` in the errors package. | |
# | |
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 ./... # does not seem to work with Go1.21 | |
go mod tidy | |
python -m venv /tmp/.venv | |
. /tmp/.venv/bin/activate | |
python -m pip install --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org semgrep | |
semgrep -f /tmp/semgrep-go/semgrep-go-master/ --error . | |
deactivate | |
# An alternative it to do: | |
# semgrep -f https://semgrep.dev/r/dgryski.semgrep-go --exclude="*_test.go" . | |
# 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 | |
# TODO: add https://github.com/system-pclub/GCatch | |
do_acceptance: | |
name: do_acceptance | |
timeout-minutes: 8 | |
strategy: | |
matrix: | |
go-version: ['>=1.21.0'] | |
platform: [ubuntu-22.04] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v3 | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Checkout hashicorp/nomad | |
uses: actions/checkout@v3 | |
with: | |
repository: hashicorp/nomad | |
ref: v1.1.0-beta1 | |
path: stuff_to_test/nomad | |
- name: Checkout juju/juju | |
uses: actions/checkout@v3 | |
with: | |
repository: juju/juju | |
ref: juju-2.9.0 | |
path: stuff_to_test/juju | |
- name: do acceptance | |
run: | | |
set -x | |
ls -lsha stuff_to_test/ | |
go build -trimpath -race -o ote . | |
RES=$(./ote -r -f stuff_to_test/nomad/) | |
num_nomad_test_modules=$(echo "$RES" | grep '// test' | wc -l | tr -d ' ') | |
if [ "$num_nomad_test_modules" != "3" ]; then | |
printf "\n\t wrong number of test comments reported for hashicorp/nomad. reported: ${num_nomad_test_modules} \n" && \ | |
printf "\n\n" && \ | |
printf "$RES" && \ | |
printf "\n\n" && \ | |
exit 77 | |
fi | |
RES=$(./ote -r -f stuff_to_test/juju) | |
num_juju_test_modules=$(echo "$RES" | grep '// test' | wc -l | tr -d ' ') | |
if [ "$num_juju_test_modules" != "0" ]; then | |
printf "\n\t wrong number of test comments reported for juju/juju. reported: ${num_juju_test_modules} \n" && \ | |
printf "\n\n" && \ | |
printf "$RES" && \ | |
printf "\n\n" && \ | |
exit 77 | |
fi | |
# run_stress_test: | |
# name: run_stress_test | |
# timeout-minutes: 2 | |
# strategy: | |
# matrix: | |
# go-version: ['>=1.21.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: stress test | |
# run: | | |
# go install golang.org/x/tools/cmd/stress@latest | |
# go test -o ote.test -c -race | |
# /home/runner/go/bin/stress -timeout 10s ./ote.test |