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 fadb378 commit 070dba2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 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
21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ 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.
: ## 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 +68,34 @@ 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 $@

# 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 070dba2

Please sign in to comment.