Skip to content

Commit

Permalink
fix: test and build fixes (#58)
Browse files Browse the repository at this point in the history
* build: improve makefile commands

* build: fix build workflow

* build: run test with dynamnic tag

* build: run test with dynamnic tag

* build: run test with dynamnic tag

* wip: disable int test

* feat: commit proto code

* feat: test with vendor

* feat: run without dyanmic

* test: chekc integration test

* test: chekc integration test

* test: skip integration test on main
  • Loading branch information
ravisuhag authored Jul 6, 2023
1 parent 1177488 commit 8a6c348
Show file tree
Hide file tree
Showing 9 changed files with 746 additions and 101 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Raccoon Test & Build
name: Test

on:
- push
Expand All @@ -7,32 +7,29 @@ on:
jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Setup Go
uses: actions/[email protected]
with:
go-version: '1.14'
- name: Install Protoc
uses: arduino/setup-protoc@v1
go-version: "1.14"
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Project
run: make install-protoc; make setup
with:
fetch-depth: 0
- name: Invoking go test
run: make test
- name: Invoking go bench test
run: make test-bench

build:
runs-on: ubuntu-latest

steps:
- name: Setup Go
uses: actions/[email protected]
with:
go-version: '1.14'
go-version: "1.14"
- name: Install Protoc
uses: arduino/setup-protoc@v1
- uses: actions/checkout@v2
- name: Build
run: make all
run: make build
1 change: 0 additions & 1 deletion .github/workflows/integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ jobs:
run: cp .env.test .env
- name: Run Raccoon
run: make docker-run
- run: make install-protoc && make generate-proto
- name: Invoking go test
run: INTEGTEST_BOOTSTRAP_SERVER=localhost:9094 INTEGTEST_HOST=localhost:8080 INTEGTEST_TOPIC_FORMAT="clickstream-%s-log" GRPC_SERVER_ADDR="localhost:8081" go test ./integration -v
7 changes: 3 additions & 4 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: Release Raccoon
name: Release
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- "v*.*.*" # Push events to matching v*, i.e. v1.0, v20.15.10
- "v*.*.*"

jobs:
push-to-docker-hub:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ coverage
.vscode
*.env
*.idea/
clickstream-service
raccoon
pkg/proto/*.pb.go
proto/*.pb.go
.temp
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ FROM golang:1.14
WORKDIR /app
RUN apt-get update && apt-get install unzip --no-install-recommends --assume-yes
RUN PROTOC_ZIP=protoc-3.17.3-linux-x86_64.zip && \
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/$PROTOC_ZIP && \
unzip -o $PROTOC_ZIP -d /usr/local bin/protoc && \
unzip -o $PROTOC_ZIP -d /usr/local 'include/*' && \
rm -f $PROTOC_ZIP
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/$PROTOC_ZIP && \
unzip -o $PROTOC_ZIP -d /usr/local bin/protoc && \
unzip -o $PROTOC_ZIP -d /usr/local 'include/*' && \
rm -f $PROTOC_ZIP
COPY . .
RUN make install-protoc && make generate-proto && make update-deps && make compile
RUN make build

FROM debian:buster-slim
WORKDIR /app
COPY --from=0 /app/out/raccoon ./raccoon
COPY --from=0 /app/raccoon ./raccoon
COPY . .
CMD ["./raccoon"]
129 changes: 52 additions & 77 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,86 +1,61 @@
.PHONY: all

ALL_PACKAGES=$(shell go list ./... | grep -v "vendor")
APP_EXECUTABLE="out/raccoon"
COVER_FILE="/tmp/coverage.out"

all: install-protoc setup compile

# Setups
setup: generate-proto copy-config
make update-deps

install-protoc:
@echo "> installing dependencies"
go get -u github.com/golang/protobuf/[email protected]
go get -u github.com/golang/protobuf/[email protected]
go get -u google.golang.org/grpc/cmd/[email protected]

update-deps:
go mod tidy -v
go mod vendor

copy-config:
cp .env.sample .env

PROTO_PACKAGE=/proto
generate-proto:
rm -rf .temp
mkdir -p .temp
curl -o .temp/proton.tar.gz -L http://api.github.com/repos/raystack/proton/tarball/main; tar xvf .temp/proton.tar.gz -C .temp/ --strip-components 1
protoc --proto_path=.temp/ .temp/raystack/raccoon/v1beta1/raccoon.proto --go_out=./ --go_opt=paths=import --go_opt=Mraystack/raccoon/v1beta1/raccoon.proto=$(PROTO_PACKAGE)
protoc --proto_path=.temp/ .temp/raystack/raccoon/v1beta1/raccoon.proto --go-grpc_opt=paths=import --go-grpc_opt=Mraystack/raccoon/v1beta1/raccoon.proto=$(PROTO_PACKAGE) --go-grpc_out=./

# Build Lifecycle
compile:
mkdir -p out/
go build -o $(APP_EXECUTABLE)

build: copy-config update-deps compile
NAME="github.com/raystack/raccoon"
COMMIT := $(shell git rev-parse --short HEAD)
TAG := "$(shell git rev-list --tags --max-count=1)"
VERSION := "$(shell git describe --tags ${TAG})-next"
BUILD_DIR=dist
PROTON_COMMIT := "ccbf219312db35a934361ebad895cb40145ca235"

.PHONY: all build clean test tidy vet proto setup format generate

all: clean test build format lint

tidy:
@echo "Tidy up go.mod..."
@go mod tidy -v

lint: ## Lint checker
@echo "Running lint checks using golangci-lint..."
@golangci-lint run

clean: tidy ## Clean the build artifacts
@echo "Cleaning up build directories..."
@rm -rf $coverage.out ${BUILD_DIR}

proto: ## Generate the protobuf files
@echo "Generating protobuf from raystack/proton"
@echo " [info] make sure correct version of dependencies are installed using 'make install'"
@buf generate https://github.com/raystack/proton/archive/${PROTON_COMMIT}.zip#strip_components=1 --template buf.gen.yaml --path raystack/raccoon -v
@cp -R proto/raystack/raccoon/v1beta1/* proto/ && rm -Rf proto/raystack
@echo "Protobuf compilation finished"

setup: ## Install required dependencies
@echo "> Installing dependencies..."
go mod tidy
go install github.com/bufbuild/buf/cmd/[email protected]

config: ## Generate the sample config file
@echo "Initializing sample server config..."
@cp .env.sample .env

build: ## Build the raccoon binary
@echo "Building racccoon version ${VERSION}..."
go build
@echo "Build complete"

install:
go install $(ALL_PACKAGES)

start: build
./$(APP_EXECUTABLE)
@echo "Installing Guardian to ${GOBIN}..."
@go install

clean: ## Clean the builds
rm -rf out/

# Utility

fmt:
go fmt $(ALL_PACKAGES)

vet:
go vet $(ALL_PACKAGES)

lint:
@for p in $(ALL_PACKAGES); do \
echo "==> Linting $$p"; \
golint $$p | { grep -vwE "exported (var|function|method|type|const) \S+ should have comment" || true; } \
done

# Tests

test: lint
ENVIRONMENT=test go test $(shell go list ./... | grep -v "vendor" | grep -v "integration") -v
@go list ./... | grep -v "vendor" | grep -v "integration" | xargs go test -count 1 -cover -short -race -timeout 1m -coverprofile ${COVER_FILE}
@go tool cover -func ${COVER_FILE} | tail -1 | xargs echo test coverage:
test: ## Run the tests
go test $(shell go list ./... | grep -v "vendor" | grep -v "integration") -v

test-bench: # run benchmark tests
@go test $(shell go list ./... | grep -v "vendor") -v -bench ./... -run=^Benchmark

test_ci: install-protoc setup test
@go test $(shell go list ./... | grep -v "vendor") -v -bench ./... -run=^Benchmark ]

# Docker Run
vendor: ## Update the vendor directory
@echo "Updating vendor directory..."
@go mod vendor

docker-run:
docker-compose build
docker-compose up -d

docker-stop:
docker-compose stop

docker-start:
docker-compose start
docker-compose up -d
8 changes: 8 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: v1
plugins:
- plugin: buf.build/protocolbuffers/go:v1.31.0
out: proto
opt: paths=source_relative
- plugin: buf.build/grpc/go:v1.3.0
out: proto
opt: paths=source_relative,require_unimplemented_servers=true
Loading

0 comments on commit 8a6c348

Please sign in to comment.