Skip to content

Commit

Permalink
Add lint and unit tests in github action
Browse files Browse the repository at this point in the history
Signed-off-by: chandankumar4 <[email protected]>
  • Loading branch information
chandankumar4 committed May 31, 2024
1 parent c6f214c commit c88100c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 17 deletions.
67 changes: 65 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,101 @@

name: test
name: CI
on:
push:
branches:
- "main"
pull_request:
branches:
- "main"

jobs:
codegen:
name: Codegen
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Restore go build cache
uses: actions/cache@v3
with:
path: ~/.cache/go-build
key: ${{ runner.os }}-go-build-v1-${{ hashFiles('**/go.mod') }}

- name: Setup Golang
uses: actions/[email protected]
with:
go-version: '1.21'

- name: Add bins to PATH
run: |
echo /home/runner/go/bin >> $GITHUB_PATH
echo /usr/local/bin >> $GITHUB_PATH
- name: Get dependencies
run: go mod download

- name: Make codegen
run: |
echo 'GOPATH=/home/runner/go' >> $GITHUB_ENV
make -B codegen
- name: Ensure nothing changed
run: git diff --exit-code

lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
env:
GOPATH: /home/runner/go
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
args: --timeout=10m

unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Golang
uses: actions/[email protected]
with:
go-version: '1.21'
id: go

- name: Install MockGen
run: go install github.com/golang/mock/[email protected]

- name: Restore Go build cache
uses: actions/cache@v3
with:
path: ~/.cache/go-build
key: ${{ runner.os }}-go-build-v1-${{ github.run_id }}

- name: Get dependencies
run: go mod download

- name: Test
run: make test

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Verify docker image
run: make image
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ bin/*
# Dependency directories (remove the comment below to include it)
# vendor/

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~
**/.DS_Store

# Go workspace file
go.work

Expand Down
18 changes: 3 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ IMG ?= numaplane-controller
VERSION ?= latest
# BASE_VERSION will be used during release process to bump up versions
BASE_VERSION := latest
# Default cluster name where numaplane get deployed, update it as needed.
CLUSTER_NAME ?= staging-usw2-k8s
IMAGE_NAMESPACE ?= quay.io/numaproj
IMAGE_FULL_PATH ?= $(IMAGE_NAMESPACE)/$(IMG):$(VERSION)


BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_BRANCH=$(shell git rev-parse --symbolic-full-name --verify --quiet --abbrev-ref HEAD)
Expand Down Expand Up @@ -116,7 +113,7 @@ test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -race -v ./... -coverprofile cover.out

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.54.2
GOLANGCI_LINT_VERSION ?= v1.58.0
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
Expand All @@ -141,13 +138,8 @@ build: manifests generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
go run -gcflags=${GCFLAGS} ./cmd/main.go

.PHONY: run-agent
run-agent: generate fmt vet ## Run agent from your host.
go run -gcflags=${GCFLAGS} cmd/agent/main.go


clean:
-rm bin/manager -f
-rm -f bin/manager

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
Expand Down Expand Up @@ -182,14 +174,10 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform

##@ Deployment

ifndef ignore-not-found
ignore-not-found = false
endif

.PHONY: start
start: image
$(KUBECTL) apply -f tests/manifests/numaplane-ns.yaml
$(KUBECTL) kustomize tests/manifests | sed 's/CLUSTER_NAME_VALUE/$(CLUSTER_NAME)/g' | sed 's@quay.io/numaproj/@$(IMAGE_NAMESPACE)/@' | sed 's/$(IMG):$(BASE_VERSION)/$(IMG):$(VERSION)/' | $(KUBECTL) apply -f -
$(KUBECTL) kustomize tests/manifests | sed '[email protected]/numaproj/@$(IMAGE_NAMESPACE)/@' | sed 's/$(IMG):$(BASE_VERSION)/$(IMG):$(VERSION)/' | $(KUBECTL) apply -f -

##@ Build Dependencies

Expand Down

0 comments on commit c88100c

Please sign in to comment.