Skip to content

Commit

Permalink
build: install semver tool
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Jan 15, 2025
1 parent e4b0e2a commit 399f8af
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export GOTOOLCHAIN_SEMVER
export AKASH_DIRENV_SET

PATH_add "$AKASH_DEVCACHE_NODE_BIN"
PATH_add "$AKASH_DEVCACHE_BIN"
PATH_add "$AKASH_TS_NODE_BIN"
PATH_add "$AKASH_DEVCACHE_BIN"

make cache
make semver
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ PROTOC_GEN_GO_PULSAR_VERSION ?= $(shell cd $(GO_ROOT); $(GO) list -mod=readon
PROTOC_GEN_GO_VERSION ?= $(shell cd $(GO_ROOT); $(GO) list -mod=readonly -m -f '{{ .Version }}' google.golang.org/protobuf)
PROTOC_GEN_GRPC_GATEWAY_VERSION := $(shell cd $(GO_ROOT); $(GO) list -mod=readonly -m -f '{{ .Version }}' github.com/grpc-ecosystem/grpc-gateway)
PROTOC_GEN_DOC_VERSION := $(shell cd $(GO_ROOT); $(GO) list -mod=readonly -m -f '{{ .Version }}' github.com/pseudomuto/protoc-gen-doc)

PROTOC_GEN_SWAGGER_VERSION := $(PROTOC_GEN_GRPC_GATEWAY_VERSION)
MODVENDOR_VERSION ?= v0.5.0
MOCKERY_VERSION ?= 2.45.0
GOLANGCI_LINT_VERSION ?= v1.60.3
SEMVER_VERSION ?= v1.2.5

BUF_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/buf/$(BUF_VERSION)
PROTOC_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/protoc/$(PROTOC_VERSION)
Expand All @@ -83,6 +83,7 @@ MODVENDOR_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/modvendor/$(M
GIT_CHGLOG_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/git-chglog/$(GIT_CHGLOG_VERSION)
MOCKERY_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/mockery/v$(MOCKERY_VERSION)
GOLANGCI_LINT_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/golangci-lint/$(GOLANGCI_LINT_VERSION)
SEMVER_VERSION_FILE := $(AKASH_DEVCACHE_VERSIONS)/semver/$(SEMVER_VERSION)

BUF := $(AKASH_DEVCACHE_BIN)/buf
PROTOC := $(AKASH_DEVCACHE_BIN)/protoc
Expand All @@ -98,6 +99,7 @@ GIT_CHGLOG := $(AKASH_DEVCACHE_BIN)/git-chglog
SWAGGER_COMBINE := $(AKASH_DEVCACHE_NODE_BIN)/swagger-combine
MOCKERY := $(AKASH_DEVCACHE_BIN)/mockery
GOLANGCI_LINT := $(AKASH_DEVCACHE_BIN)/golangci-lint
SEMVER := $(AKASH_DEVCACHE_BIN)/semver

GOLANGCI_LINT_RUN := $(GOLANGCI_LINT) run
GOLINT := $(GOLANGCI_LINT_RUN) ./... --disable-all --deadline=10m --enable
Expand Down
12 changes: 12 additions & 0 deletions make/setup-cache.mk
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ $(GOLANGCI_LINT_VERSION_FILE): $(AP_DEVCACHE)
touch $@
$(GOLANGCI_LINT): $(GOLANGCI_LINT_VERSION_FILE)

$(SEMVER_VERSION_FILE): $(AP_DEVCACHE)
@echo "installing golangci-lint $(GOLANGCI_LINT_VERSION) ..."
rm -f $(MOCKERY)
(cd $(GO_ROOT); GOBIN=$(AKASH_DEVCACHE_BIN) go install github.com/troian/semver/cmd/semver@$(SEMVER_VERSION))
rm -rf "$(dir $@)"
mkdir -p "$(dir $@)"
touch $@
$(SEMVER): $(SEMVER_VERSION_FILE)


semver: $(SEMVER)

$(NPM):
ifeq (, $(shell which $(NPM) 2>/dev/null))
$(error "npm installation required")
Expand Down
28 changes: 14 additions & 14 deletions script/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,26 @@ function run_gocoverage() {
done
}

function run_bump_module() {
function run_bump_go_module() {
local cmd
local prefix
local mod_tag
local nversion
local cversion

if [[ $# -ne 2 ]]; then
echo "Invalid arguments. expected 2, received $#"
exit 1
fi

cmd="$1"
prefix="$2"
mod_tag="$(git describe --abbrev=0 --tags --match "$prefix/v*")"

if [[ "$mod_tag" =~ $SEMVER_REGEX_STR ]]; then
local nversion
local oversion
cversion=v$(git tag -l | grep -i "^$prefix/v[0-9]*" | sed -e "s/^${prefix//\//\\/}\///" | semver sort --filter=latest)
nversion=v$(semver bump "$cmd" "$cversion")

oversion=${BASH_REMATCH[0]}
echo "bumping module $prefix: $cversion -> $nversion"

nversion=v$($SEMVER bump "$cmd" "$oversion")
git tag -a "$prefix/$nversion" -m "$prefix/$nversion"
else
error "unable to find any tag for module $prefix"
fi
# git tag -a "$prefix/$nversion" -m "$prefix/$nversion"
}

case "$1" in
Expand All @@ -251,8 +251,8 @@ case "$1" in
shift
run_gocoverage "$@"
;;
bump)
bump-go)
shift
run_bump_module "$@"
run_bump_go_module "$@"
;;
esac

0 comments on commit 399f8af

Please sign in to comment.