diff --git a/Makefile b/Makefile index 8e65445..541cf3e 100755 --- a/Makefile +++ b/Makefile @@ -1,21 +1,9 @@ # Git export GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) export GIT_COMMIT ?= $(shell git rev-parse HEAD) -export GIT_REMOTES ?= $(shell git remote -v | awk '{ print $1; }' | sort | uniq) export GIT_OPTIONS ?= - -# CI -export CI_COMMIT_REF_SLUG ?= $(GIT_BRANCH) -export CI_COMMIT_SHA ?= $(GIT_COMMIT) -export CI_ENVIRONMENT_SLUG ?= local -export CI_JOB_ID ?= 0 -export CI_RUNNER_DESCRIPTION ?= $(shell hostname) -export CI_RUNNER_ID ?= $(shell hostname) -export CI_RUNNER_VERSION ?= 0.0.0 - -# Debug -export DEBUG_BIND ?= 127.0.0.1 -export DEBUG_PORT ?= 9229 +export GIT_REMOTES ?= $(shell git remote -v | awk '{ print $1; }' | sort | uniq) +export GIT_TAG ?= $(shell git tag -l --points-at HEAD | head -1) # Paths # resolve the makefile's path and directory, from https://stackoverflow.com/a/18137056 @@ -31,6 +19,26 @@ export TARGET_MAIN ?= $(TARGET_PATH)/main-bundle.js export TEST_PATH ?= $(ROOT_PATH)/test export VENDOR_PATH ?= $(ROOT_PATH)/vendor +# CI +export CI_COMMIT_REF_SLUG ?= $(GIT_BRANCH) +export CI_COMMIT_SHA ?= $(GIT_COMMIT) +export CI_COMMIT_TAG ?= $(GIT_TAG) +export CI_ENVIRONMENT_SLUG ?= local +export CI_JOB_ID ?= 0 +export CI_PROJECT_PATH ?= $(shell ROOT_PATH=$(ROOT_PATH) ${SCRIPT_PATH}/ci-project-path.sh) +export CI_RUNNER_DESCRIPTION ?= $(shell hostname) +export CI_RUNNER_ID ?= $(shell hostname) +export CI_RUNNER_VERSION ?= 0.0.0 + +# Debug +export DEBUG_BIND ?= 127.0.0.1 +export DEBUG_PORT ?= 9229 + +# Versions +export NODE_VERSION := $(shell node -v || echo "none") +export RUNNER_VERSION := $(CI_RUNNER_VERSION) + + # Node options NODE_BIN := $(ROOT_PATH)/node_modules/.bin NODE_CMD ?= $(shell env node) @@ -38,17 +46,13 @@ NODE_DEBUG ?= --inspect-brk=$(DEBUG_BIND):$(DEBUG_PORT) --nolazy NODE_INFO := $(shell node -v) # Tool options -BUNDLE_OPTS ?= --config "$(CONFIG_PATH)/webpack.js" --display-optimization-bailout --display-error-details -COVER_CHECK ?= --check-coverage --branches 90 --functions 100 --lines 95 --statements 95 # increase this every so often COVER_OPTS ?= --reporter=lcov --reporter=text-summary --reporter=html --report-dir="$(TARGET_PATH)/coverage" --exclude-after-remap -DOCS_OPTS ?= --exclude "test.+" --tsconfig "$(CONFIG_PATH)/tsconfig.json" --out "$(TARGET_PATH)/docs" -MOCHA_MULTI ?= --reporter mocha-multi --reporter-options json="$(TARGET_PATH)/mocha.json",spec MOCHA_OPTS ?= --check-leaks --colors --sort --ui bdd RELEASE_OPTS ?= --commit-all -# Versions -export NODE_VERSION := $(shell node -v) -export RUNNER_VERSION := $(CI_RUNNER_VERSION) +.PHONY: all clean clean-deps clean-target configure help todo +.PHONY: build build-bundle build-docs build-image test test-check test-cover test-watch +.PHONY: yarn-install yarn-upgrade git-push git-stats license-check release release-dry upload-climate upload-codecov all: build test ## builds, bundles, and tests the application @echo Success! @@ -97,6 +101,9 @@ build-docs: ## generate html docs $(NODE_BIN)/api-extractor run --config $(CONFIG_PATH)/api-extractor.json --local -v $(NODE_BIN)/api-documenter markdown -i $(TARGET_PATH)/api -o $(DOCS_PATH)/api +build-image: ## build a docker image + $(SCRIPT_PATH)/docker-build.sh + test: ## run mocha unit tests test: test-cover diff --git a/config/gitlab/ci-tools.yml b/config/gitlab/ci-tools.yml index f4d40fe..4595f33 100644 --- a/config/gitlab/ci-tools.yml +++ b/config/gitlab/ci-tools.yml @@ -34,13 +34,8 @@ before_script: - mkdir ${HOME}/.docker - echo "${DOCKER_SECRET}" | base64 -d > ${HOME}/.docker/config.json - - export IMAGE_TAG="${CI_PROJECT_PATH}:${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG}}" script: - - docker info - - | - echo "Building image: ${IMAGE_TAG}" - - docker build -t $IMAGE_TAG . - - docker push $IMAGE_TAG + - ./scripts/docker-build.sh after_script: - rm -rfv ${HOME}/.docker diff --git a/scripts/ci-project-path.sh b/scripts/ci-project-path.sh new file mode 100755 index 0000000..7fb22c0 --- /dev/null +++ b/scripts/ci-project-path.sh @@ -0,0 +1,7 @@ +#! /bin/bash + +PROJECT="${ROOT_PATH}" +PARENT="$(dirname "${PROJECT}")" +PROJECT_PATH="$(basename ${PARENT})/$(basename ${PROJECT})" + +echo "${PROJECT_PATH}" \ No newline at end of file diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh new file mode 100755 index 0000000..8a8715c --- /dev/null +++ b/scripts/docker-build.sh @@ -0,0 +1,14 @@ +#! /bin/bash + +IMAGE_PUSH="${1:---skip}" +IMAGE_TAG="${CI_PROJECT_PATH}:${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG}}" + +echo "Building image: ${IMAGE_TAG}" + +docker build -t ${IMAGE_TAG} . + +if [[ "${IMAGE_PUSH}" == "--push" ]]; +then + echo "Pushing image: ${IMAGE_TAG}" + docker push ${IMAGE_TAG} +fi