-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
51 additions
and
46 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 |
---|---|---|
|
@@ -4,6 +4,8 @@ on: | |
tags: | ||
- 'v*.*.*' | ||
- 'v*.*.*-rc*' | ||
branches: | ||
- master | ||
|
||
permissions: | ||
contents: write | ||
|
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
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
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
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
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,44 +1,22 @@ | ||
NAME ?= bbox | ||
PROJECT ?= gitlab.similarweb.io/infrastructure/bbox | ||
UNFORMATTED_FILES=$(shell find . -not -path "./vendor/*" -name "*.go" | xargs gofmt -s -l) | ||
PROJECT ?= https://github.com/similarweb/bbox | ||
GOCMD=go | ||
GOTEST=$(GOCMD) test | ||
GOBUILD=$(GOCMD) build | ||
GOARCH=amd64 | ||
|
||
.PHONY: release | ||
release: ## Release locally all version | ||
@goreleaser release --clean --config .goreleaser.yml | ||
|
||
test: ## Run tests for the project | ||
$(GOTEST) -short -race -cover -failfast ./... | ||
|
||
.PHONY: build | ||
build-binary: prompt-version ## Build Locally | ||
@echo "Building locally $(VERSION)..." | ||
$(GOBUILD) -ldflags="-X $(NAME)/version.version=$(VERSION)" -o $(NAME)_dev | ||
|
||
fmt: ## Format Go code | ||
@gofmt -w -s main.go $(UNFORMATTED_FILES) | ||
$(GOTEST) ./... -v | ||
|
||
lint: | ||
golangci-lint run --timeout=3m | ||
|
||
fmt-check: ## Check go code formatting | ||
@echo "==> Checking that code complies with gofmt requirements..." | ||
@if [ ! -z "$(UNFORMATTED_FILES)" ]; then \ | ||
echo "gofmt needs to be run on the following files:"; \ | ||
echo "$(UNFORMATTED_FILES)" | xargs -n1; \ | ||
echo "You can use the command: \`make fmt\` to reformat code."; \ | ||
exit 1; \ | ||
else \ | ||
echo "Check passed."; \ | ||
fi | ||
lint: ## Run linter for the project | ||
golangci-lint run | ||
|
||
help: ## Show Help menu | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
|
||
.PHONY: prompt-version | ||
prompt-version: | ||
$(eval VERSION := $(shell read -p "Enter a version number: " version && echo $$version)) | ||
.PHONY: version | ||
version: ## Print the version of the project | ||
$(GOCMD) run $(NAME) version | ||
|
||
.PHONY: version describe | ||
version-describe: ## Print the version of the project with full description | ||
$(GOCMD) run $(NAME) version -d |
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,20 +1,35 @@ | ||
package version | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func ExecuteGitCommand(args ...string) string { | ||
cmd := exec.Command("git", args...) | ||
out, err := cmd.Output() | ||
if err != nil { | ||
return "unknown" | ||
} | ||
return strings.TrimSpace(string(out)) | ||
} | ||
|
||
// Set with LDFLAGS. | ||
var ( | ||
// Version of the release, the value injected by .goreleaser | ||
version = `{{.Version}}` | ||
// Version of the release, dynamically fetched from git | ||
version = ExecuteGitCommand("describe", "--tags", "--abbrev=0") | ||
|
||
// Commit hash of the release, the value injected by .goreleaser | ||
commit = `{{.Commit}}` | ||
// Commit hash of the release, dynamically fetched from git | ||
commit = ExecuteGitCommand("rev-parse", "HEAD") | ||
|
||
// Date of the commit, dynamically fetched from git | ||
date = ExecuteGitCommand("show", "-s", "--format=%ci", "HEAD") | ||
) | ||
|
||
func GetVersion() string { | ||
return version | ||
} | ||
|
||
// GetFormattedVersion returns the current version and commit hash | ||
func GetFormattedVersion() string { | ||
return fmt.Sprintf("%s (%s)", version, commit) | ||
return fmt.Sprintf("%s (%s, %s)", version, commit, date) | ||
} |