Skip to content

Commit

Permalink
feat: add git check so its not required to kick up make. (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
basejump authored Aug 1, 2021
1 parent ee7ae4d commit 1632c20
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 80 deletions.
7 changes: 6 additions & 1 deletion bin/git_tools
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bin/init_env
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
92 changes: 39 additions & 53 deletions makefiles/Shipkit-main.make
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
7 changes: 3 additions & 4 deletions makefiles/docker-db.make
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion makefiles/kubectl-config.make
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 15 additions & 15 deletions makefiles/secrets.make
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 protected] $(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 protected] $(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)
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/log/Makefile
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 0 additions & 2 deletions tests/log.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ 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' {
run make -f $FIXTURES_ROOT/Makefile test1
__debug "${status}" "${output}" "${lines[@]}"

[ "$status" -eq 0 ]
[ "$(cat -vet <(echo ${lines[0]}))" == "===> the test1 target$" ]
}
3 changes: 2 additions & 1 deletion tests/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1632c20

Please sign in to comment.