Skip to content

Commit

Permalink
feat: adding act testing support and goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
benjivesterby committed Feb 11, 2024
1 parent d9d2368 commit ae648e3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .env.act
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ALERT_CC_USERS=@benjivesterby
GO_VERSION=1.22.x

# https://$username:$token@github.com/
GIT_CREDENTIALS=op://act_test/git_credentials/credential

GH_PAT=op://act_test/gh_pat/credential

CODECOV_TOKEN=op://act_test/codecov_token/credential
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Lint, Build & Test
id: lint-build-test

on: [push, pull_request]

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Removing Vendor
vendor/
.venv
dist/
.act/

.vscode/

Expand Down
18 changes: 18 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
builds:
- skip: true

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-{{ .ShortCommit }}"

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

release:
prerelease: auto
52 changes: 44 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
all: build tidy lint fmt test
all: deps tidy fmt build test lint

op=op run --env-file="./.env" --

opact=op run --env-file="./.env.act" --

#-------------------------------------------------------------------------
# Variables
Expand All @@ -17,6 +21,11 @@ deps:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/goreleaser/goreleaser@latest

ci-test-deps:
# install act
if [ ! -d .act ]; then make install-act; git clone git@github.com:nektos/act.git .act; fi
cd .act && git pull && sudo make install

test: lint
CGO_ENABLED=1 go test -cover -failfast -race ./...

Expand Down Expand Up @@ -46,7 +55,8 @@ lint: tidy
build: update upgrade tidy lint test
$(env) go build ./...

release-dev: build-ci
release: build-ci
goreleaser release --snapshot --rm-dist

upgrade:
$(pyenv)/pre-commit autoupdate
Expand All @@ -64,11 +74,31 @@ tidy: fmt
clean:
rm -rf dist
rm -rf coverage
rm -rf .act
rm -rf .venv

#-------------------------------------------------------------------------
# Git targets
#-------------------------------------------------------------------------

tag:
@latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \
current_major=$$(echo $$latest_tag | cut -d. -f1); \
current_minor=$$(echo $$latest_tag | cut -d. -f2); \
current_patch=$$(echo $$latest_tag | cut -d. -f3); \
next_minor=$$((current_minor + 1)); \
default_version="$$current_major.$$next_minor.$$current_patch"; \
read -p "Enter the version number [$$default_version]: " version; \
version=$${version:-$$default_version}; \
commits=$$(git log $$latest_tag..HEAD --pretty=format:"%h %s" | awk '{print "- " $$0}'); \
git tag -a v$$version -m "Release v$$version" -m "$$commits"; \
git push origin v$$version

#-------------------------------------------------------------------------
# CI targets
#-------------------------------------------------------------------------
test-ci: deps tidy lint
build-ci:
$(env) go build ./...
CGO_ENABLED=1 go test \
-cover \
-covermode=atomic \
Expand All @@ -77,13 +107,19 @@ test-ci: deps tidy lint
-race ./...
make fuzz FUZZ_TIME=10

build-ci: test-ci
$(env) go build ./...

bench-ci: test-ci
bench-ci: build-ci
go test -bench=. ./... | tee output.txt

release-ci: build-ci
goreleaser release --rm-dist

test-ci:
DOCKER_HOST=$(shell docker context inspect --format='{{json .Endpoints.docker.Host}}' $(shell docker context show)) \
$(opact) act \
-s GIT_CREDENTIALS \
-s GITHUB_TOKEN="$(gh auth token)" \
--var GO_VERSION \
--var ALERT_CC_USERS \

#-------------------------------------------------------------------------
# Force targets
Expand All @@ -95,4 +131,4 @@ FORCE:
# Phony targets
#-------------------------------------------------------------------------

.PHONY: build test lint fuzz
.PHONY: build test lint fuzz bench fmt tidy clean release update upgrade deps translate test-act ci-test-deps
6 changes: 3 additions & 3 deletions scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,14 @@ func FuzzTick(f *testing.F) {
}

func FuzzScaler(f *testing.F) {
interceptFunc := func(ctx context.Context, t int) (string, bool) {
interceptFunc := func(_ context.Context, t int) (string, bool) {
return fmt.Sprintf("%d", t), true
}

f.Fuzz(func(
t *testing.T,
wait, life int64,
step, cStep int,
step, _ int,
mod float64,
max uint,
in int,
Expand Down Expand Up @@ -537,7 +537,7 @@ func Test_Scaler_Max(t *testing.T) {
initedMu := sync.Mutex{}
release := make(chan struct{})

interceptFunc := func(ctx context.Context, t int) (int, bool) {
interceptFunc := func(_ context.Context, t int) (int, bool) {
defer func() {
initedMu.Lock()
defer initedMu.Unlock()
Expand Down

0 comments on commit ae648e3

Please sign in to comment.