diff --git a/Makefile b/Makefile index 4984ea6..3ba81e5 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/netoik-cicd.spec b/netoik-cicd.spec index c8c60a2..94ac914 100644 --- a/netoik-cicd.spec +++ b/netoik-cicd.spec @@ -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 diff --git a/src/newcommit.sh b/src/newcommit.sh new file mode 100644 index 0000000..0bd5acc --- /dev/null +++ b/src/newcommit.sh @@ -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 diff --git a/src/newtag.sh b/src/newtag.sh index 5477109..c207501 100755 --- a/src/newtag.sh +++ b/src/newtag.sh @@ -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