Skip to content
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
67 changes: 56 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,65 @@
name: Test and Check
name: CI

run-name: Running tests and checks for policies

on: [push]
on:
push:
branches:
- main
- release-*
pull_request: {}

jobs:
Test-And-Check:
setup-go:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Download dependencies
run: go mod download

- name: Check build
run: go build ./...

unit-test:
needs: setup-go
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

permissions:
contents: write
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Run unit tests
run: make test

go-fmt-check:
needs: setup-go
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- name: Checkout code
uses: actions/checkout@v3

- name: Test
run: go test ./...
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"

- name: Check go fmt changes
run: |
go fmt ./...
git status --porcelain
if [ "$(git status --porcelain)" != "" ]; then
echo "The following files would be changed by go fmt:"
git status --porcelain
exit 1
else
echo "All files are properly formatted."
fi
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ data/
dist/
.compliance-framework/
agent
main
main

cover.out
config.yml
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

BLUE := $(shell printf "\033[34m")
YELLOW := $(shell printf "\033[33m")
RED := $(shell printf "\033[31m")
GREEN := $(shell printf "\033[32m")
CNone := $(shell printf "\033[0m")

INFO = echo ${TIME} ${BLUE}[ .. ]${CNone}
WARN = echo ${TIME} ${YELLOW}[WARN]${CNone}
ERR = echo ${TIME} ${RED}[FAIL]${CNone}
OK = echo ${TIME} ${GREEN}[ OK ]${CNone}
FAIL = (echo ${TIME} ${RED}[FAIL]${CNone} && false)

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

help: ## Display this concise help, ie only the porcelain target.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

Expand All @@ -17,3 +34,12 @@ help-all: ## Display all help items, ie including plumbing targets.

proto-gen: ## Generate objects from proto definitions
@buf generate

##@ Test
.PHONY: test
test: ## Run tests
@if ! go test ./... -coverprofile cover.out -v; then \
$(WARN) "Tests failed"; \
exit 1; \
fi ; \
$(OK) Tests passed