From 65f9112114609be5d8e2dd4d31c3ca466e3294ef Mon Sep 17 00:00:00 2001 From: "Dr. Jaska" Date: Wed, 15 Jan 2025 07:22:46 +0000 Subject: [PATCH] Add genmod and cvar spelling into CI/CD tests --- .gitignore | 5 +- .gitlab-ci.yml | 11 +++- Makefile | 7 +-- qcsrc/Makefile | 16 ++++- qcsrc/tools/cvar-standardize.sh | 4 ++ qcsrc/tools/scripts-diff-test-wrapper.sh | 76 ++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 8 deletions(-) mode change 100644 => 100755 qcsrc/tools/cvar-standardize.sh create mode 100755 qcsrc/tools/scripts-diff-test-wrapper.sh diff --git a/.gitignore b/.gitignore index 83f1c3c65..d9c58546d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,10 @@ cscope* .idea/ Thumbs.db -# sv_game hashtest local test re-use +# CI/CD pipeline files +gmqcc +data/xonotic-data.pk3dir +## sv_game hashtest local test re-use data/maps/ data/maps/_init.bsp data/stormkeep.pk3 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 81a98fa72..b45e9f27b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,7 +31,16 @@ test_compilation_units: - qcsrc/**/* stage: test script: - - make test + - > + if ! make test-diff ; then + printf "\e[31m %s \e[0m\n" "Previous script in the pipeline produced a change." + printf "\e[31m %s \e[0m\n" "This is treated as a test failure." + printf "\e[31m %s \e[0m\n" "Please run 'make test-diff' locally" + printf "\e[31m %s \e[0m\n" "and address the changes somehow in a commit." + exit 1 + fi + + - make test-comp test_sv_game: stage: test diff --git a/Makefile b/Makefile index f7bc68e49..4040d6d2a 100644 --- a/Makefile +++ b/Makefile @@ -38,9 +38,8 @@ sv: pk3: $(MAKE) -C qcsrc pk3 +DIFFTESTS = test-genmod test-cvar-spelling COMPTESTS = test-server test-client test-menu -.PHONY: test $(COMPTESTS) -test: - $(MAKE) -C qcsrc test -$(COMPTESTS): +.PHONY: test test-diff $(DIFFTESTS) test-comp $(COMPTESTS) +test test-diff $(DIFFTESTS) test-comp $(COMPTESTS): $(MAKE) -C qcsrc $@ diff --git a/qcsrc/Makefile b/qcsrc/Makefile index ae9a8e61c..4994469c1 100644 --- a/qcsrc/Makefile +++ b/qcsrc/Makefile @@ -59,9 +59,21 @@ pk3: csprogs-$(VER).pk3 +DIFFTESTS = test-genmod test-cvar-spelling COMPTESTS = test-server test-client test-menu -.PHONY: test $(COMPTESTS) -test: $(COMPTESTS) +.PHONY: test test-diff $(DIFFTESTS) test-comp $(COMPTESTS) + +test: $(DIFFTESTS) $(COMPTESTS) + +test-diff: test-genmod test-cvar-spelling +test-genmod: + tools/scripts-diff-test-wrapper.sh genmod.sh +test-cvar-spelling: + tools/scripts-diff-test-wrapper.sh cvar-standardize.sh + +.NOTPARALLEL: $(DIFFTESTS) + +test-comp: $(COMPTESTS) $(COMPTESTS): tools/compilationunits.sh $@ diff --git a/qcsrc/tools/cvar-standardize.sh b/qcsrc/tools/cvar-standardize.sh old mode 100644 new mode 100755 index 78dedb1fc..e74207024 --- a/qcsrc/tools/cvar-standardize.sh +++ b/qcsrc/tools/cvar-standardize.sh @@ -122,3 +122,7 @@ function check() { check . +if [ -n "$(git diff)" ] +then + echo "$0: Changes produced, please commit or ignore with ' // script-ignore [reason]'" +fi diff --git a/qcsrc/tools/scripts-diff-test-wrapper.sh b/qcsrc/tools/scripts-diff-test-wrapper.sh new file mode 100755 index 000000000..934328fef --- /dev/null +++ b/qcsrc/tools/scripts-diff-test-wrapper.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +set -eu + + +# This script is a wrapper for running other scripts to test whether +# or not they produce a change, such as a file modification, +# creation, or deletion. +# +# In order to test it accurately this # script should not be +# ran with uncommitted changes. +# +# In the case that there are changes produced this wrapper script +# mentions that there has been a change and exits with an error. +# +# Any of the potential changes are left in the git index so that +# if this script is run in a developer setup they can easily see +# the changes and commit them or address them without the need +# to re-run any scripts. +# +# This script is also intended for GitLab CI/CD pipelines so that +# we're able to have tests which track the output of certain scripts. + + +# Check that we got an argument +if [ -z "${1-}" ] +then + echo + echo "$0: No argument provided" + echo + exit 1 +fi + + +# Check that we do not already have changes +if [ -n "$(git status --porcelain=v1)" ] +then + echo + echo "$0: Do not run this script with changes in git index" + echo + echo + git status + echo + echo + exit 2 +fi + + +# Run if argument is executable +if [ -x "${0%/*}/$1" ] +then + # Run the given script + "${0%/*}/$1" || { + echo + echo "$0: ${0%/*}/$1 ran into an error while executing" + echo + exit 3 + } +else + echo "$0: ${0%/*}/$1 is not an executable" + exit 4 +fi + + +# Check that we did not produce changes +if [ -n "$(git status --porcelain=v1)" ] +then + echo + echo "$0: ${0%/*}/$1 produced a change in the repository:" + echo + echo + git status + echo + echo + exit 5 +fi -- 2.39.5