-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
186 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,57 +2,133 @@ | |
export PATH := $(PWD)/bin:$(PATH) # ./bin to $PATH | ||
export SHELL := bash # Default Shell | ||
|
||
GOPKGS := $(shell go list ./... | grep -vE "(cmd|sandbox|testdata)" | tr -s '\n' ',' | sed 's/.\{1\}$$//' ) | ||
GOPKGS := $(shell go list ./... | grep -vE "(cmd|testdata)" | tr -s '\n' ',' | sed 's/.\{1\}$$//' ) | ||
|
||
define install_go_bin | ||
@ which $(1) 2>&1 1>/dev/null || GOBIN=$(PWD)/bin go install $(2) | ||
endef | ||
|
||
build: | ||
@ go build -trimpath -ldflags="-w -s" \ | ||
-o bin/mirror ./cmd/mirror/ | ||
.DEFAULT_GOAL := help | ||
|
||
build-race: | ||
@ go build -race -trimpath -ldflags="-w -s" \ | ||
-o bin/mirror ./cmd/mirror/ | ||
# Generate Artifacts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
generate: ## Generate Assets | ||
$(MAKE) | ||
|
||
tests: | ||
go test -v -count=1 -race \ | ||
generate-tests: ## Generates Assets at testdata | ||
go run ./cmd/internal/tests/ "$(PWD)/testdata" | ||
|
||
generate-mirror-table: ## Generate Asset MIRROR_FUNCS.md | ||
go run ./cmd/internal/mirror-table/ > "$(PWD)/MIRROR_FUNCS.md" | ||
|
||
|
||
# Build Artifacts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
build: ## Build binary | ||
@ go build -trimpath -ldflags="-w -s" -o bin/mirror ./cmd/mirror/ | ||
|
||
build-race: ## Build binary with race flag | ||
@ go build -race -trimpath -ldflags="-w -s" -o bin/mirror ./cmd/mirror/ | ||
|
||
install: ## Installs binary | ||
@ go install -trimpath -v -ldflags="-w -s" ./cmd/mirror | ||
|
||
# Run Tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
tests: ## Run Tests (Summary) | ||
@ go test -v -count=1 -race \ | ||
-failfast \ | ||
-parallel=2 \ | ||
-timeout=1m \ | ||
-covermode=atomic \ | ||
-coverpkg=$(GOPKGS) -coverprofile=coverage.cov ./... | ||
|
||
tests-summary: | ||
go test -v -count=1 -race \ | ||
tests-summary: ## Run Tests, but shows summary | ||
tests-summary: bin/tparse | ||
@ go test -v -count=1 -race \ | ||
-failfast \ | ||
-parallel=2 \ | ||
-timeout=1m \ | ||
-covermode=atomic \ | ||
-coverpkg=$(GOPKGS) -coverprofile=coverage.cov --json ./... | tparse -all | ||
|
||
test-generate: | ||
go run ./cmd/internal/generate-tests/ "$(PWD)/testdata" | ||
# Linter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
lints: ## Run golangci-lint | ||
lints: bin/golangci-lint | ||
lints: | ||
golangci-lint run --no-config ./... -D deadcode --skip-dirs "^(cmd|sandbox|testdata)" | ||
golangci-lint run --no-config ./... --skip-dirs "^(cmd|testdata)" | ||
|
||
|
||
cover: | ||
go tool cover -html=coverage.cov | ||
cover: ## Run Coverage | ||
@ go tool cover -html=coverage.cov | ||
|
||
install: | ||
go install -trimpath -v -ldflags="-w -s" \ | ||
./cmd/mirror | ||
|
||
funcs: | ||
echo "" > "out/results.txt" | ||
go list std | grep -v "vendor" | grep -v "internal" | \ | ||
xargs -I {} sh -c 'go doc -all {} > out/$(basename {}).txt' | ||
|
||
bin/goreleaser: | ||
@curl -Ls https://github.com/goreleaser/goreleaser/releases/download/v1.17.2/goreleaser_Darwin_all.tar.gz | tar -zOxf - goreleaser > ./bin/goreleaser | ||
chmod 0755 ./bin/goreleaser | ||
# Other ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
test-release: bin/goreleaser | ||
goreleaser release --help | ||
goreleaser release -f .goreleaser.yaml \ | ||
--skip-validate --skip-publish --clean | ||
|
||
# Install ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
bin/tparse: ## Installs [email protected] (if not exists) | ||
bin/tparse: INSTALL_URL=github.com/mfridman/[email protected] | ||
bin/tparse: | ||
$(call install_go_bin, tparse, $(INSTALL_URL)) | ||
|
||
bin/golangci-lint: ## Installs [email protected] (if not exists) | ||
bin/golangci-lint: INSTALL_URL=github.com/golangci/[email protected] | ||
bin/golangci-lint: | ||
$(call install_go_bin, golangci-lint, $(INSTALL_URL)) | ||
|
||
bin/goreleaser: ## Installs [email protected] (if not exists) | ||
bin/goreleaser: INSTALL_URL=github.com/goreleaser/[email protected] | ||
bin/goreleaser: | ||
$(call install_go_bin, goreleaser, $(INSTALL_URL)) | ||
|
||
# Help ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
help: dep-gawk | ||
@ echo "==============================================================================" | ||
@ echo " Makefile: github.com/butuzov/mirror " | ||
@ echo "==============================================================================" | ||
@ cat $(MAKEFILE_LIST) | \ | ||
grep -E '^# ~~~ .*? [~]+$$|^[a-zA-Z0-9_-]+:.*?## .*$$' | \ | ||
gawk '{if ( $$1=="#" ) { \ | ||
match($$0, /^# ~~~ (.+?) [~]+$$/, a);\ | ||
{print "\n", a[1], ""}\ | ||
} else { \ | ||
match($$0, /^([a-zA-Z/_-]+):.*?## (.*)$$/, a); \ | ||
{printf " - \033[32m%-20s\033[0m %s\n", a[1], a[2]} \ | ||
}}' | ||
@ echo "" | ||
|
||
|
||
# Helper Mehtods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
dep-gawk: | ||
@ if [ -z "$(shell command -v gawk)" ]; then \ | ||
if [ -x /usr/local/bin/brew ]; then $(MAKE) _brew_gawk_install; exit 0; fi; \ | ||
if [ -x /usr/bin/apt-get ]; then $(MAKE) _ubuntu_gawk_install; exit 0; fi; \ | ||
if [ -x /usr/bin/yum ]; then $(MAKE) _centos_gawk_install; exit 0; fi; \ | ||
if [ -x /sbin/apk ]; then $(MAKE) _alpine_gawk_install; exit 0; fi; \ | ||
echo "GNU Awk Required.";\ | ||
exit 1; \ | ||
fi | ||
|
||
_brew_gawk_install: | ||
@ echo "Instaling gawk using brew... " | ||
@ brew install gawk --quiet | ||
@ echo "done" | ||
|
||
_ubuntu_gawk_install: | ||
@ echo "Instaling gawk using apt-get... " | ||
@ apt-get -q install gawk -y | ||
@ echo "done" | ||
|
||
_alpine_gawk_install: | ||
@ echo "Instaling gawk using yum... " | ||
@ apk add --update --no-cache gawk | ||
@ echo "done" | ||
|
||
_centos_gawk_install: | ||
@ echo "Instaling gawk using yum... " | ||
@ yum install -q -y gawk; | ||
@ echo "done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,73 @@ | ||
version: '3' | ||
|
||
tasks: | ||
default: | ||
sources: | ||
- "./**/*.go" | ||
method: timestamp | ||
cmds: | ||
- clear | ||
- make build | ||
- make build-race | ||
- task: lints | ||
# - make test-generate | ||
- task: tests | ||
- cmd: go run ./cmd/mirror/ --with-tests --with-debug ./sandbox | ||
ignore_error: true | ||
|
||
testcase: go test -v -failfast -count=1 -run "TestAll/{{ .Case }}" ./... | ||
|
||
tests: | ||
cmds: | ||
- cmd: make tests | ||
ignore_error: true | ||
|
||
lints: | ||
cmds: | ||
- cmd: make lints | ||
ignore_error: true | ||
default: task --list-all | ||
|
||
# Continues Development ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
watcher: | ||
desc: watcher | ||
sources: | ||
- ./**/*.go | ||
method: timestamp | ||
cmds: | ||
- task: lints | ||
- task: test-summary | ||
- task: build-race | ||
|
||
# Generating assets ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
generate: | ||
desc: Generate Assets | ||
sources: | ||
- ./checkers_*.go | ||
- ./cmd/internal/**/*.go | ||
method: timestamp | ||
cmds: | ||
- task generate-mirror-table | ||
- task generate-tests | ||
|
||
generate-mirror-table: | ||
desc: Generates Assets at testdata | ||
cmd: make generate-mirror-table | ||
|
||
generate-tests: | ||
desc: Generate Asset MIRROR_FUNCS.md | ||
cmd: make generate-tests | ||
|
||
# Run Tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
tests: | ||
desc: Run Tests | ||
cmd: make tests | ||
ignore_error: true | ||
|
||
test-summary: | ||
desc: Run Tests (Summary) | ||
cmd: make tests-summary | ||
ignore_error: true | ||
|
||
testcase: go test -v -failfast -count=1 -run "TestAll/{{ .Case }}" ./... | ||
|
||
# Build Artifacts ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
build: | ||
desc: Build binary | ||
cmd: make build | ||
|
||
build-race: | ||
desc: Build binary with race flag | ||
cmd: make build-race | ||
|
||
install: | ||
desc: Install binary | ||
cmd: make install | ||
|
||
# Linter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
lints: | ||
cmd: make lints | ||
|
||
# Other | ||
cover: | ||
desc: Run Coverage | ||
cmd: make cover | ||
|
||
test-release: | ||
desc: Testing Release | ||
cmd: make test-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters