Skip to content

Commit

Permalink
Merge pull request #362 from NFV-BU/fix/examples
Browse files Browse the repository at this point in the history
updated Makefile template to automatically use replace in go.mod for installing CLI
  • Loading branch information
stonedu1011 authored and GitHub Enterprise committed Jan 17, 2024
2 parents 7d6afbd + 04dc73c commit 7387794
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 40 deletions.
22 changes: 14 additions & 8 deletions cmd/lanai-cli/initcmd/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CLI ?= lanai-cli

INIT_TMP_DIR = $(TMP_DIR)/init
CLI_GOMOD_FILE = $(INIT_TMP_DIR)/go.mod
CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
CLI_MOD_PATH ?= $(shell realpath `$(GO) list -f='{{or .Replace ""}}' -m $(CLI_MOD)`)

## Local Targets

Expand All @@ -58,18 +58,23 @@ init-ws:
# init-cli:
# Used to bootstrap any targets other than init-once
# Required Vars:
# - CLI_MOD_PATH the path of the go-lanai module on local file system. If provided, it would override CLI_TAG
# e.g. CLI_MOD_PATH=./../go-lanai
# - CLI_TAG branch/tag to use to install "lanai-cli", typically same branch/tag of cto-github.cisco.com/NFV-BU/go-lanai
# e.g. CLI_TAG=develop
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
ifneq ($(filter true True TRUE,$(DEV)),)
# For CLI Dev, or Service Dev who have go-lanai checkout out and have proper "replace" directive in go.mod
init-cli: CLI_VERSION = service-$(shell $(GIT) rev-parse HEAD)
init-cli: CLI_PKG_PATH = $(if $(CLI_TAG),$(CLI_PKG)@$(CLI_TAG),$(CLI_PKG))
ifneq ("$(wildcard $(CLI_MOD_PATH)/go.mod)","")
# For Contributors or Service Dev who have go-lanai checked out (either by-side or as parent) and have proper "replace" directive in go.mod
init-cli: CLI_PKG = cmd/lanai-cli
init-cli: CLI_PKG_PATH = $(CLI_MOD_PATH)/cmd/lanai-cli
init-cli: CLI_VERSION = 0.0.0-$(shell cd $(CLI_MOD_PATH); date +"%Y%m%d%H%M%S")-$(shell $(GIT) rev-parse --short=12 HEAD || echo "SNAPSHOT")
init-cli: print
@echo Installing $(CLI_PKG_PATH) $(CLI_VERSION) ...
@$(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)
@echo Installing $(CLI_MOD_PATH)/$(CLI_PKG)@$(CLI_VERSION) ...
@cd $(CLI_MOD_PATH); $(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)

else
# For CI/CD and Service Dev
init-cli: CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
init-cli: CLI_VERSION = $(shell $(GO) list -modfile "$(CLI_GOMOD_FILE)" -m -f {{.Version}} $(CLI_MOD_PATH))
# If the version is a pseudo version, we want to use the commit hash (the last 12 characters) for the go install command
init-cli: CLI_PKG_PATH = $(if [["$(CLI_VERSION)" =~ $(pseudo_version_pattern)]],$(CLI_PKG)@$(shell printf $(CLI_VERSION) | tail -c 12),$(CLI_PKG)@$(CLI_VERSION))
Expand All @@ -89,4 +94,5 @@ print:
@echo "CLI_VERSION: $(CLI_VERSION)"
@echo "CLI_PKG_PATH: $(CLI_PKG_PATH)"
@echo "CLI_TAG: $(CLI_TAG)"
@echo "CLI_MOD_PATH: $(CLI_MOD_PATH)"

22 changes: 14 additions & 8 deletions examples/auth/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CLI ?= lanai-cli

INIT_TMP_DIR = $(TMP_DIR)/init
CLI_GOMOD_FILE = $(INIT_TMP_DIR)/go.mod
CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
CLI_MOD_PATH ?= $(shell realpath `$(GO) list -f='{{or .Replace ""}}' -m $(CLI_MOD)`)

## Local Targets

Expand All @@ -58,18 +58,23 @@ init-ws:
# init-cli:
# Used to bootstrap any targets other than init-once
# Required Vars:
# - CLI_MOD_PATH the path of the go-lanai module on local file system. If provided, it would override CLI_TAG
# e.g. CLI_MOD_PATH=./../go-lanai
# - CLI_TAG branch/tag to use to install "lanai-cli", typically same branch/tag of cto-github.cisco.com/NFV-BU/go-lanai
# e.g. CLI_TAG=develop
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
ifneq ($(filter true True TRUE,$(DEV)),)
# For CLI Dev, or Service Dev who have go-lanai checkout out and have proper "replace" directive in go.mod
init-cli: CLI_VERSION = service-$(shell $(GIT) rev-parse HEAD)
init-cli: CLI_PKG_PATH = $(if $(CLI_TAG),$(CLI_PKG)@$(CLI_TAG),$(CLI_PKG))
ifneq ("$(wildcard $(CLI_MOD_PATH)/go.mod)","")
# For Contributors or Service Dev who have go-lanai checked out (either by-side or as parent) and have proper "replace" directive in go.mod
init-cli: CLI_PKG = cmd/lanai-cli
init-cli: CLI_PKG_PATH = $(CLI_MOD_PATH)/cmd/lanai-cli
init-cli: CLI_VERSION = 0.0.0-$(shell cd $(CLI_MOD_PATH); date +"%Y%m%d%H%M%S")-$(shell $(GIT) rev-parse --short=12 HEAD || echo "SNAPSHOT")
init-cli: print
@echo Installing $(CLI_PKG_PATH) $(CLI_VERSION) ...
@$(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)
@echo Installing $(CLI_MOD_PATH)/$(CLI_PKG)@$(CLI_VERSION) ...
@cd $(CLI_MOD_PATH); $(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)

else
# For CI/CD and Service Dev
init-cli: CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
init-cli: CLI_VERSION = $(shell $(GO) list -modfile "$(CLI_GOMOD_FILE)" -m -f {{.Version}} $(CLI_MOD_PATH))
# If the version is a pseudo version, we want to use the commit hash (the last 12 characters) for the go install command
init-cli: CLI_PKG_PATH = $(if [["$(CLI_VERSION)" =~ $(pseudo_version_pattern)]],$(CLI_PKG)@$(shell printf $(CLI_VERSION) | tail -c 12),$(CLI_PKG)@$(CLI_VERSION))
Expand All @@ -89,4 +94,5 @@ print:
@echo "CLI_VERSION: $(CLI_VERSION)"
@echo "CLI_PKG_PATH: $(CLI_PKG_PATH)"
@echo "CLI_TAG: $(CLI_TAG)"
@echo "CLI_MOD_PATH: $(CLI_MOD_PATH)"

22 changes: 14 additions & 8 deletions examples/database/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CLI ?= lanai-cli

INIT_TMP_DIR = $(TMP_DIR)/init
CLI_GOMOD_FILE = $(INIT_TMP_DIR)/go.mod
CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
CLI_MOD_PATH ?= $(shell realpath `$(GO) list -f='{{or .Replace ""}}' -m $(CLI_MOD)`)

## Local Targets

Expand All @@ -58,18 +58,23 @@ init-ws:
# init-cli:
# Used to bootstrap any targets other than init-once
# Required Vars:
# - CLI_MOD_PATH the path of the go-lanai module on local file system. If provided, it would override CLI_TAG
# e.g. CLI_MOD_PATH=./../go-lanai
# - CLI_TAG branch/tag to use to install "lanai-cli", typically same branch/tag of cto-github.cisco.com/NFV-BU/go-lanai
# e.g. CLI_TAG=develop
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
ifneq ($(filter true True TRUE,$(DEV)),)
# For CLI Dev, or Service Dev who have go-lanai checkout out and have proper "replace" directive in go.mod
init-cli: CLI_VERSION = service-$(shell $(GIT) rev-parse HEAD)
init-cli: CLI_PKG_PATH = $(if $(CLI_TAG),$(CLI_PKG)@$(CLI_TAG),$(CLI_PKG))
ifneq ("$(wildcard $(CLI_MOD_PATH)/go.mod)","")
# For Contributors or Service Dev who have go-lanai checked out (either by-side or as parent) and have proper "replace" directive in go.mod
init-cli: CLI_PKG = cmd/lanai-cli
init-cli: CLI_PKG_PATH = $(CLI_MOD_PATH)/cmd/lanai-cli
init-cli: CLI_VERSION = 0.0.0-$(shell cd $(CLI_MOD_PATH); date +"%Y%m%d%H%M%S")-$(shell $(GIT) rev-parse --short=12 HEAD || echo "SNAPSHOT")
init-cli: print
@echo Installing $(CLI_PKG_PATH) $(CLI_VERSION) ...
@$(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)
@echo Installing $(CLI_MOD_PATH)/$(CLI_PKG)@$(CLI_VERSION) ...
@cd $(CLI_MOD_PATH); $(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)

else
# For CI/CD and Service Dev
init-cli: CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
init-cli: CLI_VERSION = $(shell $(GO) list -modfile "$(CLI_GOMOD_FILE)" -m -f {{.Version}} $(CLI_MOD_PATH))
# If the version is a pseudo version, we want to use the commit hash (the last 12 characters) for the go install command
init-cli: CLI_PKG_PATH = $(if [["$(CLI_VERSION)" =~ $(pseudo_version_pattern)]],$(CLI_PKG)@$(shell printf $(CLI_VERSION) | tail -c 12),$(CLI_PKG)@$(CLI_VERSION))
Expand All @@ -89,4 +94,5 @@ print:
@echo "CLI_VERSION: $(CLI_VERSION)"
@echo "CLI_PKG_PATH: $(CLI_PKG_PATH)"
@echo "CLI_TAG: $(CLI_TAG)"
@echo "CLI_MOD_PATH: $(CLI_MOD_PATH)"

22 changes: 14 additions & 8 deletions examples/opa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CLI ?= lanai-cli

INIT_TMP_DIR = $(TMP_DIR)/init
CLI_GOMOD_FILE = $(INIT_TMP_DIR)/go.mod
CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
CLI_MOD_PATH ?= $(shell realpath `$(GO) list -f='{{or .Replace ""}}' -m $(CLI_MOD)`)

## Local Targets

Expand All @@ -58,18 +58,23 @@ init-ws:
# init-cli:
# Used to bootstrap any targets other than init-once
# Required Vars:
# - CLI_MOD_PATH the path of the go-lanai module on local file system. If provided, it would override CLI_TAG
# e.g. CLI_MOD_PATH=./../go-lanai
# - CLI_TAG branch/tag to use to install "lanai-cli", typically same branch/tag of cto-github.cisco.com/NFV-BU/go-lanai
# e.g. CLI_TAG=develop
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
ifneq ($(filter true True TRUE,$(DEV)),)
# For CLI Dev, or Service Dev who have go-lanai checkout out and have proper "replace" directive in go.mod
init-cli: CLI_VERSION = service-$(shell $(GIT) rev-parse HEAD)
init-cli: CLI_PKG_PATH = $(if $(CLI_TAG),$(CLI_PKG)@$(CLI_TAG),$(CLI_PKG))
ifneq ("$(wildcard $(CLI_MOD_PATH)/go.mod)","")
# For Contributors or Service Dev who have go-lanai checked out (either by-side or as parent) and have proper "replace" directive in go.mod
init-cli: CLI_PKG = cmd/lanai-cli
init-cli: CLI_PKG_PATH = $(CLI_MOD_PATH)/cmd/lanai-cli
init-cli: CLI_VERSION = 0.0.0-$(shell cd $(CLI_MOD_PATH); date +"%Y%m%d%H%M%S")-$(shell $(GIT) rev-parse --short=12 HEAD || echo "SNAPSHOT")
init-cli: print
@echo Installing $(CLI_PKG_PATH) $(CLI_VERSION) ...
@$(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)
@echo Installing $(CLI_MOD_PATH)/$(CLI_PKG)@$(CLI_VERSION) ...
@cd $(CLI_MOD_PATH); $(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)

else
# For CI/CD and Service Dev
init-cli: CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
init-cli: CLI_VERSION = $(shell $(GO) list -modfile "$(CLI_GOMOD_FILE)" -m -f {{.Version}} $(CLI_MOD_PATH))
# If the version is a pseudo version, we want to use the commit hash (the last 12 characters) for the go install command
init-cli: CLI_PKG_PATH = $(if [["$(CLI_VERSION)" =~ $(pseudo_version_pattern)]],$(CLI_PKG)@$(shell printf $(CLI_VERSION) | tail -c 12),$(CLI_PKG)@$(CLI_VERSION))
Expand All @@ -89,4 +94,5 @@ print:
@echo "CLI_VERSION: $(CLI_VERSION)"
@echo "CLI_PKG_PATH: $(CLI_PKG_PATH)"
@echo "CLI_TAG: $(CLI_TAG)"
@echo "CLI_MOD_PATH: $(CLI_MOD_PATH)"

22 changes: 14 additions & 8 deletions examples/skeleton/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CLI ?= lanai-cli

INIT_TMP_DIR = $(TMP_DIR)/init
CLI_GOMOD_FILE = $(INIT_TMP_DIR)/go.mod
CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
CLI_MOD_PATH ?= $(shell realpath `$(GO) list -f='{{or .Replace ""}}' -m $(CLI_MOD)`)

## Local Targets

Expand All @@ -58,18 +58,23 @@ init-ws:
# init-cli:
# Used to bootstrap any targets other than init-once
# Required Vars:
# - CLI_MOD_PATH the path of the go-lanai module on local file system. If provided, it would override CLI_TAG
# e.g. CLI_MOD_PATH=./../go-lanai
# - CLI_TAG branch/tag to use to install "lanai-cli", typically same branch/tag of cto-github.cisco.com/NFV-BU/go-lanai
# e.g. CLI_TAG=develop
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
ifneq ($(filter true True TRUE,$(DEV)),)
# For CLI Dev, or Service Dev who have go-lanai checkout out and have proper "replace" directive in go.mod
init-cli: CLI_VERSION = service-$(shell $(GIT) rev-parse HEAD)
init-cli: CLI_PKG_PATH = $(if $(CLI_TAG),$(CLI_PKG)@$(CLI_TAG),$(CLI_PKG))
ifneq ("$(wildcard $(CLI_MOD_PATH)/go.mod)","")
# For Contributors or Service Dev who have go-lanai checked out (either by-side or as parent) and have proper "replace" directive in go.mod
init-cli: CLI_PKG = cmd/lanai-cli
init-cli: CLI_PKG_PATH = $(CLI_MOD_PATH)/cmd/lanai-cli
init-cli: CLI_VERSION = 0.0.0-$(shell cd $(CLI_MOD_PATH); date +"%Y%m%d%H%M%S")-$(shell $(GIT) rev-parse --short=12 HEAD || echo "SNAPSHOT")
init-cli: print
@echo Installing $(CLI_PKG_PATH) $(CLI_VERSION) ...
@$(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)
@echo Installing $(CLI_MOD_PATH)/$(CLI_PKG)@$(CLI_VERSION) ...
@cd $(CLI_MOD_PATH); $(GO) install -ldflags="-X main.BuildVersion=$(CLI_VERSION)" $(CLI_PKG_PATH)

else
# For CI/CD and Service Dev
init-cli: CLI_MOD_PATH = $(if $(CLI_TAG),$(CLI_MOD)@$(CLI_TAG),$(CLI_MOD))
init-cli: CLI_PKG = $(CLI_MOD)/cmd/lanai-cli
init-cli: CLI_VERSION = $(shell $(GO) list -modfile "$(CLI_GOMOD_FILE)" -m -f {{.Version}} $(CLI_MOD_PATH))
# If the version is a pseudo version, we want to use the commit hash (the last 12 characters) for the go install command
init-cli: CLI_PKG_PATH = $(if [["$(CLI_VERSION)" =~ $(pseudo_version_pattern)]],$(CLI_PKG)@$(shell printf $(CLI_VERSION) | tail -c 12),$(CLI_PKG)@$(CLI_VERSION))
Expand All @@ -89,4 +94,5 @@ print:
@echo "CLI_VERSION: $(CLI_VERSION)"
@echo "CLI_PKG_PATH: $(CLI_PKG_PATH)"
@echo "CLI_TAG: $(CLI_TAG)"
@echo "CLI_MOD_PATH: $(CLI_MOD_PATH)"

0 comments on commit 7387794

Please sign in to comment.