[dev] Add check format, linting and unit test
This commit is contained in:
parent
c2cac454b8
commit
adb54410c1
13
Makefile
13
Makefile
|
@ -43,3 +43,16 @@ install:
|
||||||
install -D --target-directory="$(DESTDIR)$(BINDIR)" bin/$(NAME)-*
|
install -D --target-directory="$(DESTDIR)$(BINDIR)" bin/$(NAME)-*
|
||||||
install --directory "$(DESTDIR)$(TMPDIR)/$(NAME)/deployer/request"
|
install --directory "$(DESTDIR)$(TMPDIR)/$(NAME)/deployer/request"
|
||||||
install --directory "$(DESTDIR)$(TMPDIR)/$(NAME)/deployer/response"
|
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"
|
||||||
|
|
|
@ -10,7 +10,7 @@ Source0: %{name}-%{version}.tar.gz
|
||||||
|
|
||||||
BuildArch: x86_64
|
BuildArch: x86_64
|
||||||
BuildRequires: make
|
BuildRequires: make
|
||||||
Requires: bash,rpm-build,rpmdevtools,inotify-tools
|
Requires: bash,rpm-build,rpmdevtools,inotify-tools,shfmt,shellcheck
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Netoik Continuous Deployment tool
|
Netoik Continuous Deployment tool
|
||||||
|
|
|
@ -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
|
|
@ -29,6 +29,12 @@ pkg_name=$(make name)
|
||||||
pkg_version=$(make version)
|
pkg_version=$(make version)
|
||||||
[ -z $pkg_version ] && fail "Empty result for target '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.
|
# Make tarball with source code.
|
||||||
log "Make source tarball for $pkg_name v$pkg_version."
|
log "Make source tarball for $pkg_name v$pkg_version."
|
||||||
make tarball
|
make tarball
|
||||||
|
|
Loading…
Reference in New Issue