Skip to content

Commit

Permalink
Merge branch 'tests' into 'main'
Browse files Browse the repository at this point in the history
Add running tests

See merge request xebis/repository-template!11
  • Loading branch information
bruzina committed Apr 24, 2021
2 parents 52e6148 + 4ed1651 commit c7ffda4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 14 deletions.
15 changes: 11 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/check-sanity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -u

LANG=C

# commit-msg git hook
# Commit-msg git hook
gitlint --staged --msg-filename "$1" run-hook
23 changes: 23 additions & 0 deletions tools/pre-commit
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 7 additions & 4 deletions tools/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ 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"
exit 1
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"
13 changes: 11 additions & 2 deletions tools/setup-repo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c7ffda4

Please sign in to comment.