From 3d23d20fe9c22e6d99940c9f6cf1fcd7c5ff43eb Mon Sep 17 00:00:00 2001 From: Airscript Date: Sat, 20 Aug 2022 16:18:02 +0000 Subject: [PATCH 1/2] chore(ci): rename ci's make targets --- .circleci/workflows.yml | 14 +++++++------- Makefile | 36 ++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index 066b3b1..900dec5 100644 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -97,7 +97,7 @@ jobs: - run: name: Verify Base - command: make verify-ci environment=base + command: make ci-verify environment=base verify-build: executor: base @@ -111,7 +111,7 @@ jobs: - run: name: Verify Build - command: make verify-ci environment=build + command: make ci-verify environment=build verify-deploy: executor: base @@ -124,7 +124,7 @@ jobs: - run: name: Verify Deploy - command: make verify-ci environment=deploy + command: make ci-verify environment=deploy verify-publish: executor: base @@ -137,7 +137,7 @@ jobs: - run: name: Verify Publish - command: make verify-ci environment=publish + command: make ci-verify environment=publish tests: executor: base @@ -166,7 +166,7 @@ jobs: - run: name: Build Site - command: make build-ci + command: make ci-build - when: condition: @@ -194,7 +194,7 @@ jobs: - run: name: Deploy To Netlify command: > - make deploy-ci + make ci-deploy id=$NETLIFY_SITE_ID token=$NETLIFY_ACCESS_TOKEN @@ -214,7 +214,7 @@ jobs: - run: name: Publish To Docker Hub command: > - make publish-ci + make ci-publish tag=$CIRCLE_TAG username=$DOCKER_USERNAME token=$DOCKER_ACCESS_TOKEN diff --git a/Makefile b/Makefile index 8bef55d..c6d3737 100644 --- a/Makefile +++ b/Makefile @@ -40,26 +40,26 @@ build-tests: .PHONY: run-tests run-tests: - docker run --rm -it $(TESTS_IMAGE_NAME) && \ + docker run --rm $(TESTS_IMAGE_NAME) && \ docker rmi $(TESTS_IMAGE_NAME) -.PHONY: all-ci-configs -all-ci-configs: build-ci-configs run-ci-configs +.PHONY: all-ci +all-ci: build-ci run-ci -.PHONY: clean-ci-configs -clean-ci-configs: +.PHONY: clean-ci +clean-ci: docker rmi $(CI_IMAGE_NAME) -.PHONY: build-ci-configs -build-ci-configs: +.PHONY: build-ci +build-ci: mkdir -p tmp && \ cp -r .circleci .docker scripts Makefile tmp && \ docker build -f .docker/dockerfiles/ci.Dockerfile -t $(CI_IMAGE_NAME) .; \ rm -rf tmp -.PHONY: run-ci-configs -run-ci-configs: - docker run --rm -it $(CI_IMAGE_NAME) && \ +.PHONY: run-ci +run-ci: + docker run --rm $(CI_IMAGE_NAME) && \ docker rmi $(CI_IMAGE_NAME) .PHONY: install-bash @@ -98,20 +98,20 @@ install-circleci-cli: install-netlify-cli: bash ./scripts/install/netlify-cli.sh -.PHONY: verify-ci -verify-ci: +.PHONY: ci-verify +ci-verify: bash ./scripts/ci/verify.sh $(environment) -.PHONY: build-ci -build-ci: +.PHONY: ci-build +ci-builds: bash ./scripts/ci/build.sh -.PHONY: deploy-ci -deploy-ci: +.PHONY: ci-deploy +ci-deploy: bash ./scripts/ci/deploy.sh $(id) $(token) -.PHONY: publish-ci -publish-ci: docker-login docker-build docker-push +.PHONY: ci-publish +ci-publish: docker-login docker-build docker-push .PHONY: git-submodules git-submodules: From e5958c5e2be7a4e2c475034f1f9e122192d54cf1 Mon Sep 17 00:00:00 2001 From: Airscript Date: Sat, 20 Aug 2022 16:32:04 +0000 Subject: [PATCH 2/2] feat(hooks): add pre-commit git hook --- .githooks/pre-commit | 21 +++++++++++++++++++++ Makefile | 4 ++++ README.md | 4 +++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..b799d55 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,21 @@ +#!/bin/bash +PREFIX="pre-commit:" +STAGED_FILES=$(git diff --diff-filter=d --cached --name-only) +CI_FILES=$(echo "$STAGED_FILES" | grep .circleci) +TESTS_FILES=$(echo "$STAGED_FILES" | grep tests) + +if [ ${#CI_FILES} -gt 0 ]; then + if ! make all-ci; then + echo "$PREFIX Error during CI files validation." + exit 1 + fi +fi + +if [ ${#TESTS_FILES} -gt 0 ]; then + if ! make all-tests; then + echo "$PREFIX Error during tests validation." + exit 1 + fi +fi + +echo "$PREFIX Run successfully." diff --git a/Makefile b/Makefile index c6d3737..6a85988 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,10 @@ CI_IMAGE_NAME = airscript/ci:base .PHONY: all all: build run +.PHONY: setup +setup: + git config --local core.hooksPath .githooks/ + .PHONY: clean clean: docker compose down diff --git a/README.md b/README.md index 35975c7..f9cf887 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,15 @@ Follow the steps below in order to have one fully functional. ``` 2. Make sure to have these dependencies installed on your machine: +- [Bash](https://www.gnu.org/software/bash/) - [Make](https://www.gnu.org/software/make/) - [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) - [Docker](https://docs.docker.com/get-docker/) - [Docker Compose](https://docs.docker.com/compose/install/) -3. Run the following command in the repository's root folder: +3. Run the following commands in the repository's root folder: ```bash + make setup make all ```