Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial CI setup #8

Merged
merged 2 commits into from
Nov 26, 2024
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
54 changes: 54 additions & 0 deletions .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Commit
on:
pull_request:
branches:
- main
push:
branches:
- main

concurrency:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-concurrency-to-cancel-any-in-progress-job-or-run
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.actor }}
cancel-in-progress: true

jobs:
style:
# This verifies the code is formatted correctly via `make precommit`.
name: Code Style Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/.cache/golangci-lint
~/go/pkg/mod
~/go/bin
key: code-style-check-${{ hashFiles('**/go.mod', '**/go.sum', '**/Makefile') }}
- name: Run code style check
run: make check

unittest:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/go/bin
key: unittest-${{ hashFiles('**/go.mod', '**/go.sum', '**/Makefile') }}
- name: Run unit tests
run: make test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.kube
.bin
out/
118 changes: 118 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
run:
timeout: 10m

linters:
enable:
- bodyclose
- depguard
- errorlint
- exportloopref
- importas
- gci
- gofmt
- gofumpt
- goimports
- gocritic
- gosec
- govet
- misspell
- revive
- stylecheck
- testifylint
- unconvert

linters-settings:
depguard:
rules:
Main:
deny:
- pkg: github.com/gogo/protobuf
desc: "gogo/protobuf is deprecated, use golang/protobuf"
- pkg: gopkg.in/yaml.v2
desc: "use sigs.k8s.io/yaml instead"
- pkg: gopkg.in/yaml.v3
desc: "use sigs.k8s.io/yaml instead"
- pkg: k8s.io/utils/pointer
desc: "use k8s.io/utils/ptr instead"
importas:
# Do not allow unaliased imports of aliased packages.
no-unaliased: true
# Do not allow non-required aliases.
no-extra-aliases: false
alias:
# gateway-api
- pkg: sigs.k8s.io/gateway-api/apis/v1
alias: gwapiv1
- pkg: sigs.k8s.io/gateway-api/apis/v1alpha2
alias: gwapiv1a2
- pkg: sigs.k8s.io/gateway-api/apis/v1alpha3
alias: gwapiv1a3
- pkg: sigs.k8s.io/gateway-api/apis/v1beta1
alias: gwapiv1b1
- pkg: github.com/envoyproxy/gateway/api/v1alpha1
alias: egv1a1
- pkg: github.com/envoyproxy/ai-gateway/api/v1alpha1
alias: aigv1a1
# kubernetes api
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: sigs.k8s.io/mcs-api/pkg/apis/v1alpha1
alias: mcsapiv1a1
- pkg: k8s.io/api/(\w+)/(v[\w\d]+)
alias: $1$2
gci:
sections:
# Captures all standard packages if they do not match another section.
- standard
# Contains all imports that could not be matched to another section type.
- default
# Groups all imports with the specified Prefix.
- prefix(github.com/envoyproxy/ai-gateway)
gofmt:
simplify: true
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: github.com/envoyproxy/ai-gateway
govet:
enable-all: true
disable:
- shadow
- fieldalignment
revive:
rules:
# TODO: enable if-return check
- name: if-return
disabled: true
testifylint:
disable:
- float-compare
- go-require
enable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- len
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call

issues:
exclude-rules:
- path: zz_generated
linters:
- goimports
- linters:
- staticcheck
text: "SA1019:"
- path: test/e2e
linters:
- bodyclose
# Show the complete output
max-issues-per-linter: 0
max-same-issues: 0
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# The Go-based tools are defined in Makefile.tools.mk.
include Makefile.tools.mk

.PHONY: lint
lint: golangci-lint
@echo "lint => ./..."
@$(GOLANGCI_LINT) run --build-tags=$(LINT_BUILD_TAGS) ./...

.PHONY: format
format: goimports gofumpt
@echo "format => *.go"
@find . -type f -name '*.go' | xargs gofmt -s -w
@find . -type f -name '*.go' | xargs $(GO_FUMPT) -l -w
@echo "goimports => *.go"
@for f in `find . -name '*.go'`; do \
awk '/^import \($$/,/^\)$$/{if($$0=="")next}{print}' $$f > /tmp/fmt; \
mv /tmp/fmt $$f; \
done
@$(GO_IMPORTS) -w -local github.com/envoyproxy/ai-gateway `find . -name '*.go'`

.PHONY: tidy
tidy: ## Runs go mod tidy on every module
@find . -name "go.mod" \
| grep go.mod \
| xargs -I {} bash -c 'dirname {}' \
| xargs -I {} bash -c 'echo "tidy => {}"; cd {}; go mod tidy -v; '

.PHONY: precommit
precommit: format tidy lint

.PHONY: check
check:
@$(MAKE) precommit
@if [ ! -z "`git status -s`" ]; then \
echo "The following differences will fail CI until committed:"; \
git diff --exit-code; \
fi

.PHONY: test
test:
@echo "test => ./..."
@go test -v $(shell go list ./... | grep -v e2e)
44 changes: 44 additions & 0 deletions Makefile.tools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
LOCALBIN ?= $(shell pwd)/.bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool binary names.
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
GO_FUMPT = $(LOCALBIN)/gofumpt
GO_IMPORTS = $(LOCALBIN)/goimports

## Tool versions.
GOLANGCI_LINT_VERSION ?= v1.60.1
GO_FUMPT_VERSION ?= v0.6.0
GO_IMPORTS_VERSION ?= v0.21.0

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))

.PHONY: gofumpt
gofumpt: $(GO_FUMPT)
$(GO_FUMPT): $(LOCALBIN)
$(call go-install-tool,$(GO_FUMPT),mvdan.cc/gofumpt,$(GO_FUMPT_VERSION))

.PHONY: goimports
goimports: $(GO_IMPORTS)
$(GO_IMPORTS): $(LOCALBIN)
$(call go-install-tool,$(GO_IMPORTS),golang.org/x/tools/cmd/goimports,$(GO_IMPORTS_VERSION))

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/envoyproxy/ai-gateway

go 1.23.2
5 changes: 5 additions & 0 deletions internal/cmd/controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
println("hello")
}