Skip to content

Commit

Permalink
feat: update workflows and add makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
benjivesterby committed Feb 5, 2024
1 parent c1ffcf6 commit f229905
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 20 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Removing Vendor
vendor/
.venv

.vscode/

Expand All @@ -23,4 +24,6 @@ coverage.html
*.pem

# ignore mac files
.DS_Store
.DS_Store
coverage.txt

12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
97 changes: 97 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f229905

Please sign in to comment.