diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..ad0ba5f --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,55 @@ +before: + hooks: + - go mod download +builds: + - env: + - CGO_ENABLED=1 + goos: + - linux + goarch: + - amd64 +dockers: + - image_templates: + - ghcr.io/openchami/{{.ProjectName}}:latest + - ghcr.io/openchami/{{.ProjectName}}:{{ .Tag }} + - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }} + - ghcr.io/openchami/{{.ProjectName}}:{{ .Major }}.{{ .Minor }} + build_flag_templates: + - "--pull" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + extra_files: + - LICENSE + - README.md +archives: + - format: tar.gz + rlcp: true + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + files: + - LICENSE + - CHANGELOG.md + - README.md +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' +release: + github: + name_template: "{{.Version}}" + prerelease: auto + mode: append \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b309d19 --- /dev/null +++ b/Makefile @@ -0,0 +1,87 @@ +# import config. +# You can change the default config with `make cnf="config_special.env" build` +cnf ?= config.env +include $(cnf) +export $(shell sed 's/=.*//' $(cnf)) + +ifndef NAME +$(error NAME is not set. Please review and copy config.env.default to config.env and try again) +endif + +ifndef VERSION +$(error VERSION is not set. Please review and copy config.env.default to config.env and try again) +endif + +SHELL := /bin/bash + +.DEFAULT_GOAL := all +.PHONY: all +all: ## build pipeline +all: mod inst build spell lint test + +.PHONY: ci +ci: ## CI build pipeline +ci: all diff + +.PHONY: help +help: + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: clean +clean: ## remove files created during build pipeline + $(call print-target) + rm -rf dist + rm -f coverage.* + rm -f '"$(shell go env GOCACHE)/../golangci-lint"' + go clean -i -cache -testcache -modcache -fuzzcache -x + +.PHONY: mod +mod: ## go mod tidy + $(call print-target) + go mod tidy + +.PHONY: inst +inst: ## go install tools + $(call print-target) + go install github.com/client9/misspell/cmd/misspell@v0.3.4 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2 + go install github.com/goreleaser/goreleaser@v1.18.2 + +.PHONY: build +build: ## goreleaser build +build: + $(call print-target) + goreleaser build --clean --single-target --snapshot + +.PHONY: docker +docker: ## docker build +docker: + $(call print-target) + docker build . --build-arg REGISTRY_HOST=${REGISTRY_HOST} --no-cache --pull --tag '${NAME}:${VERSION}' + +.PHONY: spell +spell: ## misspell + $(call print-target) + misspell -error -locale=US -w **.md + +.PHONY: lint +lint: ## golangci-lint + $(call print-target) + golangci-lint run --fix + +.PHONY: test +test: ## go test + $(call print-target) + go test -race -covermode=atomic -coverprofile=coverage.out -coverpkg=./... ./... + go tool cover -html=coverage.out -o coverage.html + +.PHONY: diff +diff: ## git diff + $(call print-target) + git diff --exit-code + RES=$$(git status --porcelain) ; if [ -n "$$RES" ]; then echo $$RES && exit 1 ; fi + + +define print-target + @printf "Executing target: \033[36m$@\033[0m\n" +endef \ No newline at end of file diff --git a/config.env b/config.env new file mode 100644 index 0000000..b5c977f --- /dev/null +++ b/config.env @@ -0,0 +1,4 @@ +## This configuration is used by the Makefile + +NAME=opaal +VERSION=$(shell git describe --tags --abbrev=0)