Skip to content
name: Static Code Checks, Etc.
on:
- pull_request
- push
permissions: read-all
jobs:
build:
name: Static Code Checks Etc
runs-on: ubuntu-latest
steps:
- name: Skip CI
run: |
if [[ "${{contains( github.event.pull_request.labels.*.name, 'Skip CI')}}" == "true" ]]; then
echo "skipping CI due to the 'Skip CI' label"
exit 1
fi
- name: Check if workflow needs to be skipped
id: skip-workflow
run: |
skip='false'
if [[ "${{github.event.pull_request}}" == "" ]] && [[ "${{github.ref}}" != "refs/heads/main" ]] && [[ ! "${{github.ref}}" =~ ^refs/heads/release-[0-9]+\.[0-9]$ ]] && [[ ! "${{github.ref}}" =~ "refs/tags/.*" ]]; then
skip='true'
fi
echo Skip ${skip}
echo "skip-workflow=${skip}" >> $GITHUB_OUTPUT
- name: Checkout code
if: steps.skip-workflow.outputs.skip-workflow == 'false'
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Run FOSSA scan and upload build data
uses: fossa-contrib/fossa-action@v3
with:
# This is a push-only API token: https://github.com/fossa-contrib/fossa-action#push-only-api-token
fossa-api-key: f62c11ef0c249fef239947f01279aa0f
github-token: ${{ github.token }}
- name: Check for changes in Go files
if: steps.skip-workflow.outputs.skip-workflow == 'false'
uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a # v3.0.1
id: changes
with:
token: ''
filters: |
go_files:
- '**/*.go'
- '*.go'
- 'go.sum'
- 'go.mod'
- '.github/workflows/static_checks_etc.yml'
parser_changes:
- 'go/vt/sqlparser/**'
- 'go.sum'
- 'go.mod'
- 'build.env'
- 'bootstrap.sh'
- 'tools/**'
- '.github/workflows/static_checks_etc.yml'
proto_changes:
- 'bootstrap.sh'
- 'tools/**'
- 'build.env'
- 'go.sum'
- 'go.mod'
- 'Makefile'
- 'go/vt/proto/**'
- 'proto/*.proto'
- '.github/workflows/static_checks_etc.yml'
sizegen:
- 'go/**/*.go'
- 'test.go'
- 'Makefile'
- 'build.env'
- 'go.sum'
- 'go.mod'
- 'tools/**'
- 'bootstrap.sh'
- '.github/workflows/static_checks_etc.yml'
visitor:
- 'go/tools/asthelpergen/**'
- 'go/vt/sqlparser/**'
- 'Makefile'
- 'build.env'
- 'go.sum'
- 'go.mod'
- 'tools/**'
- 'bootstrap.sh'
- 'misc/git/hooks/asthelpers'
- '.github/workflows/static_checks_etc.yml'
astfmt:
- 'go/tools/astfmtgen/**'
- 'go/vt/sqlparser/**'
- 'Makefile'
- 'build.env'
- 'go.sum'
- 'go.mod'
- 'tools/**'
- 'bootstrap.sh'
- '.github/workflows/static_checks_etc.yml'
end_to_end:
- 'docker/**'
- 'test.go'
- 'Makefile'
- 'bootstrap.sh'
- '.github/workflows/static_checks_etc.yml'
ci_config:
- 'test/config.json'
- '.github/workflows/static_checks_etc.yml'
release_notes:
- 'changelog/**'
- './go/tools/releases/**'
- '.github/workflows/static_checks_etc.yml'
workflows:
- '.github/**'
- 'Makefile'
- 'test/ci_workflow_gen.go'
- '.github/workflows/static_checks_etc.yml'
- name: Set up Go
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.go_files == 'true' || steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.proto_changes == 'true')
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: go.mod
- name: Tune the OS
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
sudo sysctl -w net.ipv4.ip_local_port_range="22768 65535"
- name: Run go fmt
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
gofmt -l . | grep -vF vendor/ && exit 1 || echo "All files formatted correctly"
- name: Install goimports
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.go_files == 'true' || steps.changes.outputs.visitor == 'true')
run: |
go install golang.org/x/tools/cmd/goimports@latest
- name: Run goimports
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
out=$(goimports -local vitess.io/vitess -l -w $(find . -name "*.go" | grep -v ".pb.go"))
echo $out | grep go > /dev/null && echo -e "The following files are malformatted:\n$out" && exit 1 || echo "All the files are formatted correctly"
- name: Get dependencies
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.go_files == 'true')
run: |
sudo apt-get update
sudo apt-get install -y make unzip g++ etcd curl git wget
sudo service etcd stop
go mod download
- name: Run make minimaltools
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.go_files == 'true')
run: |
make minimaltools
- name: check_go_versions
if: steps.skip-workflow.outputs.skip-workflow == 'false'
run:
tools/check_go_versions.sh || exit 1
- name: check_make_parser
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.parser_changes == 'true' || steps.changes.outputs.go_files == 'true')
run: |
tools/check_make_parser.sh || exit 1
- name: check_make_sizegen
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.sizegen == 'true' || steps.changes.outputs.go_files == 'true')
run: |
tools/check_make_sizegen.sh || exit 1
- name: check_make_visitor
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.visitor == 'true' || steps.changes.outputs.go_files == 'true')
run: |
misc/git/hooks/asthelpers || exit 1
- name: check_ast_format_fast
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.astfmt == 'true' || steps.changes.outputs.go_files == 'true')
run: |
./tools/check_astfmtgen.sh || exit 1
- name: run ensure_bootstrap_version
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true'
run: |
make ensure_bootstrap_version
git status
test -z "$(git diff-index --name-only HEAD --)" || exit 1
- name: Install golangci-lint
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: go install github.com/golangci/golangci-lint/cmd/[email protected]
- name: Clean Env
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: $(go env GOPATH)/bin/golangci-lint cache clean
- name: Print linter version
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: $(go env GOPATH)/bin/golangci-lint --version
- name: Run golangci-lint
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: $(go env GOPATH)/bin/golangci-lint run go/... --timeout 10m || exit 1
- name: Run go mod tidy
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.go_files == 'true'
run: |
set -e
go mod tidy
output=$(git status -s)
if [ -z "${output}" ]; then
exit 0
fi
echo 'We wish to maintain a tidy state for go mod. Please run `go mod tidy` on your branch, commit and push again.'
echo 'Running `go mod tidy` on this CI test yields with the following changes:'
echo "$output"
exit 1
- name: Setup Node
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.proto_changes == 'true'
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
# make proto requires newer node than the pre-installed one
node-version: '20.12.2'
- name: check_make_proto
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.proto_changes == 'true'
run: |
tools/check_make_proto.sh || exit 1
- name: Check test/config.json
if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.go_files == 'true' || steps.changes.outputs.ci_config == 'true')
run: |
go run ./go/tools/ci-config/main.go || exit 1
- name: Check changelog
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.release_notes == 'true'
run: |
set -e
go run ./go/tools/releases/releases.go
output=$(git status -s)
if [ -z "${output}" ]; then
exit 0
fi
echo 'We wish to maintain a consistent changelog directory, please run `go run ./go/tools/releases/releases.go`, commit and push again.'
echo 'Running `go run ./go/tools/releases/releases.go` on CI yields the following changes:'
echo "$output"
echo ""
exit 1
- name: Check make generate_ci_workflows
if: steps.skip-workflow.outputs.skip-workflow == 'false'
run: |
set -e
make generate_ci_workflows
output=$(git status -s)
if [ -z "${output}" ]; then
exit 0
fi
echo 'Please run `make generate_ci_workflows`, commit and push again.'
echo 'Running `make generate_ci_workflows` on CI yields the following changes:'
echo "$output"
echo ""
exit 1