diff --git a/.asf.yaml b/.asf.yaml index 71146f6..f761fc7 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -52,6 +52,10 @@ github: required_status_checks: # strict means "Require branches to be up to date before merging". strict: true + + contexts: + - test + - build required_pull_request_reviews: dismiss_stale_reviews: false required_approving_review_count: 1 diff --git a/.github/workflows/code-check.yml b/.github/workflows/code-check.yml index 3dbaf66..b821aae 100644 --- a/.github/workflows/code-check.yml +++ b/.github/workflows/code-check.yml @@ -1,15 +1,77 @@ ---- +# -------------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to You under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. See the License for the specific language governing +# permissions and limitations under the License. +# +# -------------------------------------------------------------------- name: code-style-check on: pull_request: - branches: [master] + branches: [main] + types: [opened, synchronize, reopened, edited] + workflow_dispatch: jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: run check run: | - make lint + set +e # Don't exit on error + make lint 2>&1 | tee lint_output.txt + echo "LINT_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV + continue-on-error: true + + - name: Code Check Summary + if: always() + run: | + echo "## ๐Ÿ“‹ Code Quality Check Results" >> $GITHUB_STEP_SUMMARY + if [ "${LINT_EXIT_CODE}" == "0" ]; then + echo "โœ… All code quality checks passed!" >> $GITHUB_STEP_SUMMARY + echo "- โœ… Code formatting (gofmt)" >> $GITHUB_STEP_SUMMARY + echo "- โœ… Import organization (goimports)" >> $GITHUB_STEP_SUMMARY + echo "- โœ… Static analysis (golangci-lint)" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + if [ -f lint_output.txt ]; then + echo "### ๐Ÿ” Lint Details" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + # Show successful completion messages + grep -E "(SUCCESS|PASS|โœ“|completed)" lint_output.txt | tail -n 10 >> $GITHUB_STEP_SUMMARY || echo "All checks completed successfully" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + fi + else + echo "โŒ Code quality checks failed. Please fix the issues above." >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Run \`make lint\` locally to check and fix issues." >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + if [ -f lint_output.txt ]; then + echo "### ๐Ÿšจ Issues Found" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + # Show the last part of output which usually contains the errors + tail -n 30 lint_output.txt >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + fi + fi + + - name: Fail workflow if lint failed + if: env.LINT_EXIT_CODE != '0' + run: | + echo "Code quality checks failed. Please fix the issues and try again." + exit 1 \ No newline at end of file diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..ee35a8d --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -0,0 +1,127 @@ +# -------------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to You under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. See the License for the specific language governing +# permissions and limitations under the License. +# +# -------------------------------------------------------------------- +name: CI Pipeline + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + types: [ opened, synchronize, reopened, edited ] + workflow_dispatch: + +env: + GO_VERSION: '1.21' + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - name: Download dependencies + run: make depend + + - name: Run tests + run: | + set +e # Don't exit on error + make unit 2>&1 | tee test_output.txt + echo "TEST_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV + continue-on-error: true + + - name: Generate coverage report + if: env.TEST_EXIT_CODE == '0' + run: | + echo "Generating code coverage report..." + make coverage 2>&1 | tee coverage_output.txt || true + + - name: Test Summary + if: always() + run: | + echo "## ๐Ÿงช Test Results" >> $GITHUB_STEP_SUMMARY + if [ "${TEST_EXIT_CODE}" == "0" ]; then + echo "โœ… All tests passed successfully!" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + + # Extract and display test summary + if [ -f test_output.txt ]; then + echo "### ๐ŸŽฏ Test Execution Summary" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + # Extract the final summary lines + tail -n 10 test_output.txt | grep -E "(Ginkgo ran|Test Suite)" >> $GITHUB_STEP_SUMMARY || echo "Test summary not found" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + fi + + echo "### ๐Ÿ“Š Code Coverage Report" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + if [ -f coverage_output.txt ]; then + cat coverage_output.txt >> $GITHUB_STEP_SUMMARY + else + echo "Coverage report not available" >> $GITHUB_STEP_SUMMARY + fi + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + else + echo "โŒ Some tests failed. Check the logs above for details." >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + if [ -f test_output.txt ]; then + echo "### ๐Ÿ“‹ Test Output" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + tail -n 20 test_output.txt >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + fi + fi + + build: + name: Build + runs-on: ubuntu-latest + needs: [test] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - name: Build + run: go build -v ./... + + - name: Build Summary + if: always() + run: | + echo "## ๐Ÿ”จ Build Results" >> $GITHUB_STEP_SUMMARY + if [ ${{ job.status }} == 'success' ]; then + echo "โœ… Build completed successfully!" >> $GITHUB_STEP_SUMMARY + else + echo "โŒ Build failed. Check the logs above for details." >> $GITHUB_STEP_SUMMARY + fi diff --git a/.golangci.yml b/.golangci.yml index 5ab6a77..eb1d4a4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,29 +1,86 @@ +# -------------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to You under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. See the License for the specific language governing +# permissions and limitations under the License. +# +# -------------------------------------------------------------------- +# golangci-lint configuration file +# See https://golangci-lint.run/docs/product/migration-guide for migration instructions + +run: + timeout: 5m + go: "1.21" + +output: + format: colored-line-number + print-issued-lines: true + print-linter-name: true + +linters-settings: + govet: + check-shadowing: true + revive: + min-confidence: 0 + gocyclo: + min-complexity: 15 + dupl: + threshold: 100 + goconst: + min-len: 2 + min-occurrences: 2 + linters: - # please, do not use `enable-all`: it's deprecated and will be removed soon. - # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint - disable-all: true enable: - - golint - - vet - - varcheck - - unparam + - govet - errcheck + - staticcheck + - unused + - gosimple + - ineffassign + - typecheck + - revive + - gocyclo + - gofmt + - goimports + - misspell + - lll + - unparam + - nakedret + - prealloc + - gocritic + disable: + - golint # deprecated, replaced by revive + - structcheck # deprecated since v1.49.0 + - varcheck # deprecated since v1.49.0 + - deadcode # deprecated since v1.49.0 + - scopelint # deprecated since v1.39.0 issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` - exclude: - - "don't use ALL_CAPS in Go names; use CamelCase" - - "should not use dot imports" - + exclude-use-default: false exclude-rules: - - path: _test\.go - text: "don't use underscores in Go names" - linters: - - golint - + # Exclude some linters from running on tests files. - path: _test\.go linters: + - gocyclo - errcheck + - dupl + - gosec + # Exclude known linters from partially hard-to-fix issues + - linters: + - lll + source: "^//go:generate " + max-issues-per-linter: 0 + max-same-issues: 0 \ No newline at end of file diff --git a/Makefile b/Makefile index d5cf195..4209f70 100644 --- a/Makefile +++ b/Makefile @@ -22,13 +22,13 @@ goimports: docker run --rm -i -v "${PWD}":/data -w /data unibeautify/goimports -w -l /data golangci-lint: - docker run --rm -v ${PWD}:/data -w /data golangci/golangci-lint golangci-lint run -v + docker run --rm -v ${PWD}:/data -w /data golangci/golangci-lint:v1.64.8 golangci-lint run -v gofmt: docker run --rm -v ${PWD}:/data cytopia/gofmt --ci . $(GINKGO): - go install github.com/onsi/ginkgo/v2/ginkgo@latest + go install github.com/onsi/ginkgo/v2/ginkgo@v2.13.0 unit: $(GINKGO) ginkgo -r --keep-going --randomize-suites --randomize-all \ @@ -56,18 +56,4 @@ clean : rm -rf /tmp/cover* rm -rf /tmp/unit* -##### Pipeline targets ##### -set-dev: - fly --target dev set-pipeline --check-creds \ - --pipeline=dev-gp-common-go-libs-${BRANCH}-${USER} \ - -c ci/pipeline.yml \ - --var=branch=${BRANCH} \ - --var=golang-version=${GOLANG_VERSION} - -set-prod: - fly --target prod set-pipeline --check-creds \ - --pipeline=gp-common-go-libs \ - -c ci/pipeline.yml \ - --var=branch=main\ - --var=golang-version=${GOLANG_VERSION} diff --git a/ci/pipeline.yml b/ci/pipeline.yml deleted file mode 100644 index c99e9ea..0000000 --- a/ci/pipeline.yml +++ /dev/null @@ -1,35 +0,0 @@ ---- -resources: -- name: cloudberry-go-libs - type: git - source: - uri: https://github.com/apache/cloudberry-go-libs - branch: ((branch)) - -jobs: -- name: unit-tests - plan: - - in_parallel: - - get: cloudberry-go-libs - trigger: true - - task: unit-tests - config: - platform: linux - image_resource: - type: registry-image - source: - repository: golang - tag: ((golang-version))-buster - inputs: - - name: cloudberry-go-libs - path: go/src/github.com/apache/cloudberry-go-libs - run: - path: bash - args: - - -c - - | - set -ex - export GOPATH=$PWD/go - export PATH=$GOPATH/bin:$PATH - cd $GOPATH/src/github.com/apache/cloudberry-go-libs - make depend unit diff --git a/cluster/cluster_test.go b/cluster/cluster_test.go index 4e612e6..6f03a06 100644 --- a/cluster/cluster_test.go +++ b/cluster/cluster_test.go @@ -500,7 +500,8 @@ var _ = Describe("cluster/cluster tests", func() { It("kills the command if it runs beyond the timeout", func() { testCluster := cluster.Cluster{} commandStr := "while true; do echo Keep running; sleep 0.1; done" - ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() testCluster.Executor = &cluster.GPDBExecutor{} output, err := testCluster.ExecuteLocalCommandWithContext(commandStr, ctx) Expect(ctx.Err()).To(Equal(context.DeadlineExceeded))