Skip to content
Merged
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
73 changes: 67 additions & 6 deletions .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,76 @@
---
name: code-style-check
# --------------------------------------------------------------------
#
# 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 Quality Check

on:
pull_request:
branches: [master]
branches: [ main ]
types: [ opened, synchronize, reopened, edited ]
workflow_dispatch:

permissions:
contents: read

jobs:
lint:
name: Code Quality
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: run check
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
cache: true

- name: Run code quality checks
run: |
make lint
set +e
make lint 2>&1 | tee lint_output.txt
LINT_EXIT_CODE=${PIPESTATUS[0]}

# Generate lint summary
{
echo "## Code Quality Check Results"
if [ ${LINT_EXIT_CODE} -eq 0 ]; then
echo "PASS: All code quality checks passed!"
echo ""
echo "### Checks Performed"
echo "- Static analysis (golangci-lint)"
else
echo "FAIL: Code quality checks failed. Please fix the issues above."
echo ""
echo "### How to Fix"
echo "Run \`make lint\` locally to see the issues."
echo "Run \`make format\` to auto-fix formatting issues."
echo ""
if [ -f lint_output.txt ]; then
echo "### Lint Output"
echo "\`\`\`"
tail -n 30 lint_output.txt
echo "\`\`\`"
fi
fi
} >> "$GITHUB_STEP_SUMMARY"

exit ${LINT_EXIT_CODE}
134 changes: 134 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# --------------------------------------------------------------------
#
# 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:

permissions:
contents: read

env:
GO_VERSION: '1.25'

jobs:
ci:
name: ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [test, build]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Download dependencies
run: make depend

- name: Run CI target
env:
CI_TARGET: ${{ matrix.target }}
run: |
set +e
case "${CI_TARGET}" in
test)
echo "Running tests..."
make unit 2>&1 | tee test_output.txt
TEST_EXIT_CODE=${PIPESTATUS[0]}

if [ ${TEST_EXIT_CODE} -eq 0 ]; then
echo "Generating code coverage report..."
make coverage 2>&1 | tee coverage_output.txt || true
fi

# Generate test summary
{
echo "## Test Results"
if [ ${TEST_EXIT_CODE} -eq 0 ]; then
echo "PASS: All tests passed successfully!"
echo ""

if [ -f test_output.txt ]; then
echo "### Test Execution Summary"
echo "\`\`\`"
tail -n 10 test_output.txt | grep -E "(Ginkgo ran|Test Suite)" || echo "Test summary not found"
echo "\`\`\`"
echo ""
fi

echo "### Code Coverage Report"
echo "\`\`\`"
if [ -f coverage_output.txt ]; then
cat coverage_output.txt
else
echo "Coverage report not available"
fi
echo "\`\`\`"
else
echo "FAIL: Some tests failed. Check the logs above for details."
echo ""
if [ -f test_output.txt ]; then
echo "### Test Output"
echo "\`\`\`"
tail -n 20 test_output.txt
echo "\`\`\`"
fi
fi
} >> "$GITHUB_STEP_SUMMARY"

exit ${TEST_EXIT_CODE}
;;

build)
echo "Building..."
go build -v ./...
BUILD_EXIT_CODE=$?

# Generate build summary
{
echo "## Build Results"
if [ ${BUILD_EXIT_CODE} -eq 0 ]; then
echo "PASS: Build completed successfully!"
else
echo "FAIL: Build failed. Check the logs above for details."
fi
} >> "$GITHUB_STEP_SUMMARY"

exit ${BUILD_EXIT_CODE}
;;

*)
echo "Unknown CI target: ${CI_TARGET}"
exit 1
;;
esac
90 changes: 65 additions & 25 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
# 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.

version: "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
default: none
enable:
- golint
- vet
- varcheck
- unparam
- errcheck
- govet
- revive
- unparam
- unused
settings:
govet:
enable:
- shadow
revive:
confidence: 0.1
exclusions:
generated: lax
rules:
- linters:
- revive
text: should have comment
- linters:
- revive
text: comment on exported
- linters:
- revive
text: should not use dot imports
- linters:
- revive
text: don't use ALL_CAPS in Go names; use CamelCase
- linters:
- revive
text: and that stutters
- linters:
- revive
text: don't use an underscore in package name
- linters:
- govet
text: "shadow:"
path: _test\.go
- linters:
- errcheck
path: _test\.go
- linters:
- unparam
path: _test\.go
paths:
- vendor

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-rules:
- path: _test\.go
text: "don't use underscores in Go names"
linters:
- golint

- path: _test\.go
linters:
- errcheck
run:
timeout: 5m
43 changes: 15 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@ SHELL := /bin/bash
DIR_PATH=$(shell dirname `pwd`)
BIN_DIR=$(shell echo $${GOPATH:-~/go} | awk -F':' '{ print $$1 "/bin"}')
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GOLANG_VERSION = 1.19.6
GINKGO=$(GOPATH)/bin/ginkgo
GOLANG_VERSION = 1.25.0
GINKGO=$(BIN_DIR)/ginkgo
DEST = .

GOFLAGS :=
GOIMPORTS=$(BIN_DIR)/goimports
GOLANG_LINTER=$(BIN_DIR)/golangci-lint

.PHONY: test lint goimports golangci-lint gofmt unit coverage depend set-dev set-prod
.PHONY: test lint format unit coverage depend

test: lint unit

lint:
$(MAKE) goimports gofmt golangci-lint
$(GOIMPORTS):
GOBIN=$(BIN_DIR) go install golang.org/x/tools/cmd/goimports@latest

goimports:
docker run --rm -i -v "${PWD}":/data -w /data unibeautify/goimports -w -l /data
LINTER_VERSION=v2.12.2
$(GOLANG_LINTER):
GOBIN=$(BIN_DIR) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(LINTER_VERSION)

golangci-lint:
docker run --rm -v ${PWD}:/data -w /data golangci/golangci-lint golangci-lint run -v
format: $(GOIMPORTS)
@goimports -w $(shell find . -type f -name '*.go' -not -path "./vendor/*")

gofmt:
docker run --rm -v ${PWD}:/data cytopia/gofmt --ci .
lint: $(GOLANG_LINTER)
golangci-lint run

$(GINKGO):
go install github.com/onsi/ginkgo/v2/ginkgo@latest
GOBIN=$(BIN_DIR) go install github.com/onsi/ginkgo/v2/ginkgo@v2.13.0

unit: $(GINKGO)
ginkgo -r --keep-going --randomize-suites --randomize-all \
Expand All @@ -55,19 +58,3 @@ clean :
# Code coverage files
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