Skip to content

Commit

Permalink
chore(ci): add testing pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjaziv committed Nov 12, 2023
1 parent 1120d3b commit e68c5bc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test, Lint, Build

on: [push]

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: '1.15.x'

- name: Test
run: make test

- name: Lint
run: make lint

- name: Build server
if: always()
run: make build-binary

- name: Build cli
if: always()
run: make build-cli
7 changes: 0 additions & 7 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ linters-settings:
gofumpt:
extra-rules: true

golint:
min-confidence: 0

govet:
check-shadowing: true
enable-all: true
Expand Down Expand Up @@ -85,7 +82,6 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
- dogsled
- dupl
- errcheck
Expand All @@ -98,7 +94,6 @@ linters:
- goerr113
- gofmt
- gofumpt
- golint
- gosec
- gosimple
- govet
Expand All @@ -110,13 +105,11 @@ linters:
- noctx
- nolintlint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- wrapcheck
- wsl
Expand Down
23 changes: 9 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ help:
.PHONY: help

all: test lint build build-cli ## Test and lint and build.
test: tmp/.tests-passed.sentinel ## Run tests.
lint: tmp/.linted.sentinel ## Lint all of the Go code. Will also test.
build: out/image-id ## Build the mserv Docker image. Will also test and lint.
build-binary: $(binary_name) ## Build a bare binary only, without a Docker image wrapped around it.
build-cli: mservctl/mservctl ## Build the mservctl CLI binary. Will also test and lint.
Expand Down Expand Up @@ -69,36 +67,33 @@ clean-hack: ## Clean up binaries under 'hack'.
clean-all: clean clean-docker clean-hack ## Clean all of the things.
.PHONY: clean-all

# Tests - re-run if any Go files have changes since tmp/.tests-passed.sentinel last touched.
tmp/.tests-passed.sentinel: $(shell find . -type f -iname "*.go")
# Run go tests
test: $(shell find . -type f -iname "*.go")
> mkdir -p $(@D)
> go test ./...
> touch $@
> go test -v -count=1 -p 1 -race ./...

# Lint - re-run if the tests have been re-run (and so, by proxy, whenever the source files have changed).
tmp/.linted.sentinel: .golangci.yaml hack/bin/golangci-lint tmp/.tests-passed.sentinel
# Lint golangci lint
lint: .golangci.yaml hack/bin/golangci-lint
> mkdir -p $(@D)
> hack/bin/golangci-lint run
> go vet ./...
> touch $@

hack/bin/golangci-lint:
> curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
> | sh -s -- -b $(shell pwd)/hack/bin

# Docker image - re-build if the lint output is re-run.
out/image-id: Dockerfile tmp/.linted.sentinel
out/image-id: Dockerfile
> mkdir -p $(@D)
> image_id="$(image_repository):$(shell uuidgen)"
> DOCKER_BUILDKIT=1 docker build --tag="$${image_id}" .
> echo "$${image_id}" > out/image-id

# Main server binary - re-build if the lint output is re-run.
$(binary_name): tmp/.linted.sentinel
# Main server binary
$(binary_name):
> go build -mod=vendor

# CLI binary - re-build if the lint output is re-run.
mservctl/mservctl: tmp/.linted.sentinel
mservctl/mservctl:
> cd mservctl
> go build -mod=vendor

Expand Down

0 comments on commit e68c5bc

Please sign in to comment.