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

Add pipeline with unit-tests #19

Merged
merged 3 commits into from
Feb 23, 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
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Continuous Integration

on:
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
pull_request:

defaults:
run:
shell: bash

concurrency:
group: ${{ github.ref_name }}-ci
cancel-in-progress: true

permissions:
contents: read

jobs:
vars:
name: Checks and variables
runs-on: ubuntu-22.04
outputs:
go_path: ${{ steps.vars.outputs.go_path }}
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Golang Environment
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: stable

- name: Output Variables
id: vars
run: echo "go_path=$(go env GOPATH)" >> $GITHUB_OUTPUT

- name: Check if go.mod and go.sum are up to date
run: go mod tidy && git diff --exit-code -- go.mod go.sum

- name: Check if generated go files are up to date
run: make generate && git diff --exit-code

unit-tests:
name: Unit Tests
runs-on: ubuntu-22.04
needs: vars
steps:
- name: Checkout Repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Setup Golang Environment
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: stable

- name: Run Tests
run: make unit-test

- name: Upload Coverage Report
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: cover-${{ github.run_id }}.html
path: ${{ github.workspace }}/cmd-cover.html
if: always()
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Output of the go coverage tool
cmd-cover.out
cmd-cover.html

# Vim
*.swp
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ help: Makefile ## Display this help
.PHONY: unit-test
unit-test:
go test ./... -race -coverprofile cmd-cover.out
go tool cover -html=cmd-cover.out -o cmd-cover.html

.PHONY: clean-go-cache
clean-go-cache: ## Clean go cache
Expand Down
Loading