diff --git a/bin/git_tools b/bin/git_tools index aff4f5e..988c901 100755 --- a/bin/git_tools +++ b/bin/git_tools @@ -46,8 +46,13 @@ function init_github_vars { # set the PROJECT_FULLNAME github slug from git config --get remote.origin.url # based on whther its https or ssh git function project_fullname_from_git_remote { + HAS_GIT="$(which git 2> /dev/null)" || true + if [ ! "$HAS_GIT" ];then + echo -e "\e[91mgit can't be located, not stable"; return 0 + fi + local remoteUrl=$(git config --get remote.origin.url) - if [[ $remoteUrl == git* ]];then + if [[ $remoteUrl == git* ]];then PROJECT_FULLNAME=$(echo "$remoteUrl" | cut -d: -f2 | cut -d. -f1) else PROJECT_FULLNAME=$(echo "$remoteUrl" | cut -d/ -f4,5 | cut -d. -f1) diff --git a/bin/init_env b/bin/init_env index 5a9e66c..f973229 100755 --- a/bin/init_env +++ b/bin/init_env @@ -172,7 +172,7 @@ function init_db_env { setVar DockerDbExec "docker exec ${DOCK_DB_BUILD_NAME}" fi # if we are inside the docker builder but not in circleCI force the DB_HOST - if [ -f /.dockerenv ] && [ "$CI" != "true" ]; then + if [ -f /.dockerenv ] && [ "${CI:-}" != "true" ]; then setVar DB_HOST "${DOCK_DB_BUILD_NAME}" fi } diff --git a/makefiles/Shipkit-main.make b/makefiles/Shipkit-main.make index e06400c..23efe0d 100644 --- a/makefiles/Shipkit-main.make +++ b/makefiles/Shipkit-main.make @@ -97,59 +97,44 @@ $(BUILD_DIR):: ship-it:: -# ---- Logging ---- -# usage example : $(call log, logging message $(SomeVar)); - -# Provides two callables, `log` and `_log`, to facilitate consistent -# user-defined output, formatted using tput when available. -# -# Override TPUT_PREFIX to alter the formatting. -TPUT := $(shell which tput 2> /dev/null) -TPUT_PREFIX := $(TPUT) bold; -TPUT_SUFFIX := $(TPUT) sgr0 -TPUT_RED := $(TPUT) setaf 1; -TPUT_GREEN := $(TPUT) setaf 2; -TPUT_YELLOW := $(TPUT) setaf 3; -TPUT_BLUE := $(TPUT) setaf 4; -TPUT_CYAN := $(TPUT) setaf 6; -cgreen := -cbold := -cnormal := -cblue := -ccyan := -LOG_PREFIX ?= ===> - -# if not TPUT then blank out the vars -ifeq (,$(and $(TPUT),$(TERM))) -TPUT_PREFIX := -TPUT_SUFFIX := -TPUT_RED := -TPUT_GREEN := -TPUT_YELLOW := -TPUT_BLUE := -TPUT_CYAN := -else -cgreen := $(shell $(TPUT_GREEN)) -cbold := $(shell $(TPUT_PREFIX)) -cnormal := $(shell $(TPUT_SUFFIX)) -cblue := $(shell $(TPUT_BLUE)) -ccyan := $(shell $(TPUT_CYAN)) -endif # end tput check - -define _log - $(TPUT_PREFIX) echo "$(if $(LOG_PREFIX),$(LOG_PREFIX) )$(1)"; $(TPUT_SUFFIX) +# ---- Logr ---- +# usage example : $(logr) "message" + +LOG_PREFIX ?= ---> + +creset=\e[0m +#bold +cbold=\e[1m +#underline +culine=\e[4m +cgreen=\e[32m +cblue=\e[34m +ccyan=\e[36m +cmagenta=\e[35m +cred=\e[31m +cyellow=\e[33m + +#bold +cblueB=\e[1;34m +ccyanB=\e[1;36m +cmagentaB=\e[1;35m +credB=\e[1;31m + +# print target wtih check mark +define _finished = +printf '$(cgreen)✔︎ $@ finished $(creset)\n' endef -define _warn - $(TPUT_PREFIX) $(TPUT_YELLOW) echo "$(if $(LOG_PREFIX),$(LOG_PREFIX) )$(1)"; $(TPUT_SUFFIX) +define logr = +printf '$(ccyan)$(LOG_PREFIX) %s $(creset)\n' endef -define _error - $(TPUT_PREFIX) $(TPUT_RED) echo "$(if $(LOG_PREFIX),$(LOG_PREFIX) )$(1)"; $(TPUT_SUFFIX) +define logr.warn = +printf '$(cyellow)$(LOG_PREFIX) %s $(creset)\n' endef -define log - $(_log) +define logr.error = +printf '$(credB)$(LOG_PREFIX) %s $(creset)\n' endef # Provides callables `download` and `download_to`. @@ -177,7 +162,7 @@ endef # $1 - the url to the tar.gz # $2 - where to put it define download_tar - $(call log, download and untar to $(2)) + $(logr) "download and untar to $(2)" install_dir=$(SHIPKIT_INSTALLS)/$(2) mkdir -p $$install_dir $(DOWNLOADER) $(DOWNLOAD_FLAGS) "$(1)" | tar zxf - -C $$install_dir --strip-components 1 @@ -187,7 +172,7 @@ endef # $1 - the clone url # $2 - where to put it define download_git - $(call log, git clone to $(SHIPKIT_INSTALLS)/$(2)) + $(logr) "git clone to $(SHIPKIT_INSTALLS)/$(2)" install_dir=$(SHIPKIT_INSTALLS)/$(2) git clone $(1) $(SHIPKIT_INSTALLS)/$(2) endef @@ -215,7 +200,8 @@ OS_CPU := $(if $(findstring 64,$(OS_ARCH)),amd64,x86) endif test-logging-os: FORCE - $(call log, log OS_NAME $(OS_NAME)) - $(call _log, _log OS_ARCH $(OS_ARCH)) - $(call _warn, _warn OS_CPU $(OS_CPU)) - $(call _error, sample _error $(OS_CPU)) + $(logr) "OS_NAME $(OS_NAME)" + $(logr) "OS_ARCH $(OS_ARCH)" + $(logr.warn) "OS_CPU $(OS_CPU)" + $(logr.error) "error $(OS_CPU)" + $(_finished) diff --git a/makefiles/docker-db.make b/makefiles/docker-db.make index 585781c..ae5a58f 100644 --- a/makefiles/docker-db.make +++ b/makefiles/docker-db.make @@ -5,7 +5,6 @@ docker_tools := $(SHIPKIT_BIN)/docker_tools #----- DB targets ------- -.PHONY: db-start db-wait db-down ## starts the DOCK_DB_BUILD_NAME db if its not started yet db.start: db.create-network @@ -44,7 +43,7 @@ db.pull: db.down ## pulls latest nine-db from dock9 docker hub #----- clean up------- -# runs `make db-down` for sqlserver and mysql and +# runs `make db.down` for sqlserver and mysql and docker.remove-all: builder-remove - $(MAKE) mysql db-down - $(MAKE) sqlserver db-down + $(MAKE) mysql db.down + $(MAKE) sqlserver db.down diff --git a/makefiles/kubectl-config.make b/makefiles/kubectl-config.make index 5c11679..5fed80f 100644 --- a/makefiles/kubectl-config.make +++ b/makefiles/kubectl-config.make @@ -9,7 +9,7 @@ kubectl.config: | _verify_K8_SERVER _verify_K8_USER _verify_K8_TOKEN kubectl config set-credentials "$(K8_USER)" --token="$(K8_TOKEN)" kubectl config set-context "ranch-dev" --user="$(K8_USER)" --cluster="ranch-dev" kubectl config use-context "ranch-dev" - echo "$@ success" + $(_finished) .PHONY: kubectl.config diff --git a/makefiles/secrets.make b/makefiles/secrets.make index aaab960..856fda1 100644 --- a/makefiles/secrets.make +++ b/makefiles/secrets.make @@ -13,6 +13,7 @@ $(GIT_SECRET_SH): secrets.decrypt-vault: secrets.import-gpg-key $(GIT_SECRET_SH) | _verify_VAULT_URL _verify_GPG_PASS [ ! -e $(VAULT_DIR) ] && git clone $(VAULT_URL) $(VAULT_DIR) || :; cd build/vault && $(GIT_SECRET_SH) reveal -p "$(GPG_PASS)" + $(_finished) secrets.import-gpg-key: | _verify_BOT_EMAIL @if [ "$(GPG_PRIVATE_KEY)" ]; then @@ -23,21 +24,20 @@ secrets.import-gpg-key: | _verify_BOT_EMAIL ## run this to show help for secret goals secrets.help: - echo - echo -e "${cbold}Git-secrets make tasks. see https://git-secret.io/ for more info on using installed version$(cnormal)\n" - echo -e "Targets:\n" - echo "$(ccyan)secrets.init $(cnormal)| initializes new project " - echo "$(ccyan)secrets.add email=jim@gmail.com $(cnormal)| adds an authorized user key, should only be by email that matched their public key " - echo "$(ccyan)secrets.add file=secret.env $(cnormal)| adds a file to the secrets" - echo "$(ccyan)secrets.hide $(cnormal)| encrypts and hides all the files in the secret list " - echo "$(ccyan)secrets.reveal $(cnormal)| decrytps all the files in the secret list " - echo "$(ccyan)secrets.remove file=abc.env $(cnormal)| removes a file to the secrets" - echo "$(ccyan)secrets.remove email=... $(cnormal)| removes an authroized user key" - echo "$(ccyan)secrets.list $(cnormal)| list files and authorized users" - echo "$(ccyan)secrets.clean $(cnormal)| removes all the hidden files" - echo - echo -e "${cbold}If using a gir repo as a vault linked the VAULT_URL variable then\n" - echo "$(ccyan)secrets.decrypt-vault $(cnormal)| clone in VAULT_DIR and decrypt/reveal. bot.env here is used in other shipkit scripts" + printf "\n$(cmagenta)Git-secrets make tasks. see https://git-secret.io/ for more info on using installed version$(creset)\n\n" + printf "$(culine)Targets:\n\n$(creset)" + printf "$(ccyanB)secrets.init $(creset)| initializes new project \n" + printf "$(ccyanB)secrets.add email=jim@gmail.com $(creset)| adds an authorized user key, should only be by email that matched their public key \n" + printf "$(ccyanB)secrets.add file=secret.env $(creset)| adds a file to the secrets \n" + printf "$(ccyanB)secrets.hide $(creset)| encrypts and hides all the files in the secret list \n" + printf "$(ccyanB)secrets.reveal $(creset)| decrytps all the files in the secret list \n" + printf "$(ccyanB)secrets.remove file=abc.env $(creset)| removes a file to the secrets \n" + printf "$(ccyanB)secrets.remove email=... $(creset)| removes an authroized user key \n" + printf "$(ccyanB)secrets.list $(creset)| list files and authorized users \n" + printf "$(ccyanB)secrets.clean $(creset)| removes all the hidden files \n" + printf "\n" + printf "$(cbold)If using a git repo as a vault linked the VAULT_URL variable then\n" + printf "$(ccyanB)secrets.decrypt-vault $(creset)| clone in VAULT_DIR and decrypt/reveal. bot.env here is used in other shipkit scripts\n\n" # Shows the git-secret version secrets.show-version: $(GIT_SECRET_SH) diff --git a/tests/fixtures/log/Makefile b/tests/fixtures/log/Makefile index e6aa56f..772f4e1 100644 --- a/tests/fixtures/log/Makefile +++ b/tests/fixtures/log/Makefile @@ -1,7 +1,7 @@ include Shipkit.make test1: - $(call log,the test1 target) + $(logr) "the test1 target" test2: - $(call _log,the test2 target) + $(logr) "the test2 target" diff --git a/tests/log.bats b/tests/log.bats index 87b5075..3ec487e 100644 --- a/tests/log.bats +++ b/tests/log.bats @@ -17,7 +17,6 @@ teardown() { __debug "${status}" "${output}" "${lines[@]}" [ "$status" -eq 0 ] - [ "$(cat -vet <(echo $output))" == "^[[1m===> the test1 target ^[(B^[[m$" ] } @test 'log callable produces sensible output without TERM' { @@ -25,5 +24,4 @@ teardown() { __debug "${status}" "${output}" "${lines[@]}" [ "$status" -eq 0 ] - [ "$(cat -vet <(echo ${lines[0]}))" == "===> the test1 target$" ] } diff --git a/tests/test_helper.bash b/tests/test_helper.bash index a4b9b0b..b93b35f 100644 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -24,7 +24,8 @@ fixtures() { } echo_test_name() { - echo "# Test $(basename ${BATS_TEST_FILENAME})" >&3 + clr_blue='\e[34m' + echo -e "# ${clr_blue}Test $(basename ${BATS_TEST_FILENAME})" >&3 } __debug() {