Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .asf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 66 additions & 4 deletions .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
@@ -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
127 changes: 127 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -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
97 changes: 77 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 2 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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}
Loading
Loading