From f2299059b6a6684e85245817ee35dc965145cc02 Mon Sep 17 00:00:00 2001 From: Benji Vesterby Date: Mon, 5 Feb 2024 16:33:30 +0000 Subject: [PATCH] feat: update workflows and add makefile --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 29 +++++++---- .gitignore | 5 +- .pre-commit-config.yaml | 12 ++--- Makefile | 97 +++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 17 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b4094d2..0e74c2f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,5 +8,5 @@ env: jobs: lint-build-test: name: Lint, Build & Test - uses: devnw/workflows/.github/workflows/build.yml@main + uses: devnw/workflows/.github/workflows/make-build.yml@main secrets: inherit # pragma: allowlist secret diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59e8bf4..d9b1c6c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,32 +7,43 @@ on: jobs: build: - name: "Build & Unit Tests" + name: Make Build strategy: matrix: - go-version: [1.19.x] platform: [ubuntu-latest, macos-latest, windows-latest] fail-fast: true - runs-on: ${{ matrix.platform }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 + - name: Install Go uses: actions/setup-go@v4 with: - go-version: ${{ matrix.go-version }} + go-version: ${{ vars.GO_VERSION }} stable: false + - name: Build - run: go build ./... - - name: Test - run: go test -race -failfast ./... + run: make build-ci + + - name: Upload Test Coverage + uses: actions/upload-artifact@v3 + with: + name: coverage + path: coverage.txt + + - name: Upload Fuzz Results + uses: actions/upload-artifact@v3 + with: + name: fuzz-results + path: testdata/fuzz + release: needs: [build] name: "Tagged Release" runs-on: "ubuntu-latest" steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create Github Release from Tag uses: "marvinpinto/action-automatic-releases@latest" with: diff --git a/.gitignore b/.gitignore index cc0b307..c4e5a25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Removing Vendor vendor/ +.venv .vscode/ @@ -23,4 +24,6 @@ coverage.html *.pem # ignore mac files -.DS_Store \ No newline at end of file +.DS_Store +coverage.txt + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9770031..b3e07c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ exclude: '^package.json|package-lock.json|.*?\.tsv$' fail_fast: true repos: - repo: https://github.com/commitizen-tools/commitizen - rev: v2.42.1 + rev: v3.14.1 hooks: - id: commitizen stages: [commit-msg] @@ -14,7 +14,7 @@ repos: exclude: package.lock.json stages: [commit] - repo: https://github.com/golangci/golangci-lint - rev: v1.52.2 + rev: v1.55.2 hooks: - id: golangci-lint stages: [commit] @@ -24,7 +24,7 @@ repos: - id: go-unit-tests stages: [commit] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-json stages: [commit] @@ -39,18 +39,18 @@ repos: - id: check-yaml stages: [commit] - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.33.0 + rev: v0.39.0 hooks: - id: markdownlint-fix stages: [commit] args: ["--ignore", "README.md"] # This is a generated file - repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.9.0.2 + rev: v0.9.0.6 hooks: - id: shellcheck stages: [commit] - repo: https://github.com/pre-commit/mirrors-eslint - rev: 'v8.36.0' + rev: 'v9.0.0-alpha.2' hooks: - id: eslint stages: [commit] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..592fca2 --- /dev/null +++ b/Makefile @@ -0,0 +1,97 @@ +all: build tidy lint fmt test + +#------------------------------------------------------------------------- +# Variables +# ------------------------------------------------------------------------ +env=CGO_ENABLED=0 + +pyenv=.venv/bin + +#------------------------------------------------------------------------- +# Targets +#------------------------------------------------------------------------- +deps: + python3 -m venv .venv + + $(pyenv)/pip install --upgrade pre-commit + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + go install github.com/goreleaser/goreleaser@latest + +test: lint + CGO_ENABLED=1 go test -cover -failfast -race ./... + +fuzz: + @fuzzTime=$${FUZZ_TIME:-10}; \ + files=$$(grep -r --include='**_test.go' --files-with-matches 'func Fuzz' .); \ + for file in $$files; do \ + funcs=$$(grep -o 'func Fuzz\w*' $$file | sed 's/func //'); \ + for func in $$funcs; do \ + echo "Fuzzing $$func in $$file"; \ + parentDir=$$(dirname $$file); \ + go test $$parentDir -run=$$func -fuzz=$$func -fuzztime=$${fuzzTime}s; \ + if [ $$? -ne 0 ]; then \ + echo "Fuzzing $$func in $$file failed"; \ + exit 1; \ + fi; \ + done; \ + done + + + +lint: tidy + golangci-lint run + $(pyenv)/pre-commit run --all-files + +build: update upgrade tidy lint test + $(env) go build ./... + +release-dev: build-ci + goreleaser release --rm-dist --snapshot + +upgrade: + $(pyenv)/pre-commit autoupdate + go get -u ./... + +update: + git submodule update --recursive + +fmt: + gofmt -s -w . + +tidy: fmt + go mod tidy + +clean: + rm -rf dist + rm -rf coverage + +#------------------------------------------------------------------------- +# CI targets +#------------------------------------------------------------------------- +test-ci: deps tidy lint + CGO_ENABLED=1 go test \ + -cover \ + -covermode=atomic \ + -coverprofile=coverage.txt \ + -failfast \ + -race ./... + make fuzz FUZZ_TIME=10 + +build-ci: test-ci + $(env) go build ./... + + +release-ci: build-ci + goreleaser release --rm-dist + +#------------------------------------------------------------------------- +# Force targets +#------------------------------------------------------------------------- + +FORCE: + +#------------------------------------------------------------------------- +# Phony targets +#------------------------------------------------------------------------- + +.PHONY: build test lint fuzz