diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 638ce57..266c3f2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,6 @@ default: before_script: - TZ="Europe/Prague" - ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - - apt update - - apt upgrade -y - - apt install --no-install-recommends -y git nodejs npm stages: - verify @@ -15,7 +12,9 @@ stages: lint: stage: verify script: - - apt install --no-install-recommends -y ca-certificates golang python3-pip shellcheck + - apt update + - apt upgrade -y + - apt install --no-install-recommends -y ca-certificates git golang nodejs npm python3-pip shellcheck - pip3 install gitlint pre-commit yamllint - gitlint - tools/check-sanity @@ -24,9 +23,17 @@ lint: - PATH="$PATH:/root/go/bin" - pre-commit run --all-files +test-full: + stage: verify + script: + - echo "$0 ✓ Full test set" + release: stage: release script: + - apt update + - apt upgrade -y + - apt install --no-install-recommends -y git nodejs npm - npm install -g semantic-release @semantic-release/gitlab @semantic-release/github @semantic-release/git @semantic-release/changelog - npx semantic-release rules: diff --git a/README.md b/README.md index 0fbf283..754bded 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,16 @@ Strategies and tactics to achieve objectives: - Automated workflow using [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), and [GitLab CI](https://about.gitlab.com/stages-devops-lifecycle/continuous-integration/) - GitLab CI skips CI if commit contains `[skip ci]` in the commit message - Commit messages are checked using [gitlint](https://github.com/jorisroovers/gitlint) and [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) -- Git `push` is checked: +- Git `commit` is normalized, checked, and tested: + - Runs quick test set +- Git `push` is checked, and tested: - Lints last commit message - Prevents `todo` preceded with `#` at the codebase - Prevents existence of unstaged files -- Git `commit` scans each codebase change, git `push` scans whole codebase, and following rules are applied: + - Runs reduced test set +- GitLab CI run is tested: + - Runs full test set +- Git `commit` scans each codebase change; git `push`, and GitLab CI scans whole codebase, and following rules are applied: - Enforces max file size to 1024 kB using [pre-commit/pre-commit-hooks: check-added-large-files](https://github.com/pre-commit/pre-commit-hooks#check-added-large-files) - Prevents case insensitive filename conflict using [pre-commit/pre-commit-hooks: check-case-conflict](https://github.com/pre-commit/pre-commit-hooks#check-case-conflict) - Enforces executables have shebangs using [pre-commit/pre-commit-hooks: check-executables-have-shebangs](https://github.com/pre-commit/pre-commit-hooks#check-executables-have-shebangs) diff --git a/tools/check-sanity b/tools/check-sanity index 4b0830a..3c1ac5e 100755 --- a/tools/check-sanity +++ b/tools/check-sanity @@ -13,7 +13,7 @@ ECHO_PRE_INST="$0 +" ECHO_PRE_ERR="$0 ❌" # Check sanity -# Anti-todo check +# Check for todos TODO="todo" if grep -riq "#$TODO"; then diff --git a/tools/commit-msg b/tools/commit-msg index 023e7e4..bce85ed 100755 --- a/tools/commit-msg +++ b/tools/commit-msg @@ -5,5 +5,5 @@ set -u LANG=C -# commit-msg git hook +# Commit-msg git hook gitlint --staged --msg-filename "$1" run-hook diff --git a/tools/pre-commit b/tools/pre-commit new file mode 100755 index 0000000..3e72121 --- /dev/null +++ b/tools/pre-commit @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -e +set -o pipefail +set -u + +LANG=C + +# shellcheck disable=SC2034 +ECHO_PRE_OK="$0 ✓" +# shellcheck disable=SC2034 +ECHO_PRE_INST="$0 +" +# shellcheck disable=SC2034 +ECHO_PRE_ERR="$0 ❌" + +# Pre-commit git hook + +# Normalize + +# Check codebase changes +pre-commit + +# Run quick test set +echo "$ECHO_PRE_OK Quick test set" diff --git a/tools/pre-push b/tools/pre-push index e1a9c7a..985b189 100755 --- a/tools/pre-push +++ b/tools/pre-push @@ -14,8 +14,8 @@ ECHO_PRE_ERR="$0 ❌" # Pre-push git hook -# Local sanity check -# Uncommited changes check +# Check local sanity +# Check for uncommited changes GIT_UNCOMMITED=$(git ls-files -dmo --exclude-standard) if [ -n "$GIT_UNCOMMITED" ]; then echo "$ECHO_PRE_ERR git unstaged changes" @@ -23,8 +23,11 @@ if [ -n "$GIT_UNCOMMITED" ]; then fi echo "$ECHO_PRE_OK git unstaged changes" -# General sanity check +# Check general sanity tools/check-sanity -# Lint full +# Check full codebase pre-commit run --all-files + +# Run reduced test set +echo "$ECHO_PRE_OK Reduced test set" diff --git a/tools/setup-repo b/tools/setup-repo index ea677b3..851ccdd 100755 --- a/tools/setup-repo +++ b/tools/setup-repo @@ -124,8 +124,17 @@ else fi fi - # Install pre-commit and gitlint into git hooks - pre-commit install + # Install pre-commit hook if it's not present or doesn't point to the right location + if [[ ! -L ".git/hooks/pre-commit" ]] || [ "$(readlink .git/hooks/pre-commit)" != "../../tools/pre-commit" ]; then + if ln -s ../../tools/pre-commit .git/hooks/pre-commit; then + echo "$ECHO_PRE_INST pre-commit hook has been installed." + else + echo "$ECHO_PRE_ERR pre-commit hook installation failed, cannot create symbolic link." + exit 1 + fi + else + echo "$ECHO_PRE_OK pre-commit hook is installed." + fi # Install commit-msg hook if it's not present or doesn't point to the right location if [[ ! -L ".git/hooks/commit-msg" ]] || [ "$(readlink .git/hooks/commit-msg)" != "../../tools/commit-msg" ]; then