[dev] Add check format, linting and unit test

This commit is contained in:
samuel 2023-02-21 18:04:04 +01:00
parent c2cac454b8
commit adb54410c1
4 changed files with 55 additions and 1 deletions

View File

@ -43,3 +43,16 @@ install:
install -D --target-directory="$(DESTDIR)$(BINDIR)" bin/$(NAME)-*
install --directory "$(DESTDIR)$(TMPDIR)/$(NAME)/deployer/request"
install --directory "$(DESTDIR)$(TMPDIR)/$(NAME)/deployer/response"
.PHONY: check_format
check_format:
shfmt --diff .
.PHONY: check_linting
check_linting:
shfmt --find . | xargs bash -o noexec
shfmt --find . | xargs shellcheck
.PHONY: unit_test
unit_test:
@echo "not implemented yet"

View File

@ -10,7 +10,7 @@ Source0: %{name}-%{version}.tar.gz
BuildArch: x86_64
BuildRequires: make
Requires: bash,rpm-build,rpmdevtools,inotify-tools
Requires: bash,rpm-build,rpmdevtools,inotify-tools,shfmt,shellcheck
%description
Netoik Continuous Deployment tool

35
src/newcommit.sh Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/bash
#
# This binary is made to be run by git server, it checks code validity.
# Exit immediately if any command fails.
set -e
# Exit with the last non-zero exit code.
set -o pipefail
# Name of current gitops pipeline.
pipeline="NEWTAG"
log () {
echo -e "[$pipeline] $(date --rfc-3339=s) - $1"
}
fail () {
if [ $# -eq 1 ]; then
echo "$1" 1>&2
fi
exit 1
}
# Check format.
log "Check format."
make check_format
# Check linting.
log "Check linting."
make check_linting
# Run unit tests.
log "Run unit tests."
make unit_test

View File

@ -29,6 +29,12 @@ pkg_name=$(make name)
pkg_version=$(make version)
[ -z $pkg_version ] && fail "Empty result for target 'make version'."
# Check code validity.
log "Check code validity for $pkg_name v$pkg_version."
make check_format
make check_linting
make unit_test
# Make tarball with source code.
log "Make source tarball for $pkg_name v$pkg_version."
make tarball