From e932f05bc8b497a6a321bf94528103486e40b4e4 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Fri, 20 Jan 2023 15:42:07 +0100 Subject: [PATCH] ci: adds git fetch before doing schema checks This fixes the CI errors when doing `make check-source` steps 'schema-added-check' and 'schema-removed-check'. These errors prevented CI from performing these steps correctly: ``` fatal: ambiguous argument 'main': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git [...] -- [...]' ``` I changed it so that CI does a `git fetch origin` at first and do the `git diff` against 'origin/master' (which then exist). Also fixed a bug in the script that was missing $$master in the same line. Also I added that the script shows the actual diff before failing, so the user quickly sees whats wrong. --- doc/Makefile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 5b9479bd2..b7951a637 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -206,14 +206,19 @@ doc/index.rst: $(MANPAGES:=.md) ) # For CI to (very roughly!) check that we only deprecated fields, or labelled added ones - -# So GitHub renamed master to main. This is painful. +# When running on GitHub (CI=true), we need to fetch origin/master schema-added-check: - @if ! git describe master >/dev/null 2>&1; then MASTER=main; else MASTER=master; fi; if git diff $$MASTER doc/schemas | grep -q '^+.*{' && ! git diff master doc/schemas | grep -q '^+.*"added"'; then echo 'New schema fields must have "added": "vNEXTVERSION"' >&2; exit 1; fi - -# So GitHub renamed master to main. This is painful. + @if ! test -z $$CI; then git fetch origin master; fi; \ + if git diff origin/master -- doc/schemas | grep -q '^+.*{' && ! git diff origin/master -- doc/schemas | grep -q '^+.*"added"'; then \ + git diff origin/master -- doc/schemas; \ + echo 'New schema fields must have "added": "vNEXTVERSION"' >&2; exit 1; \ + fi schema-removed-check: - @if ! git describe master >/dev/null 2>&1; then MASTER=main; else MASTER=master; fi; if git diff $$MASTER doc/schemas | grep -q '^-.*{' && ! git diff master doc/schemas | grep -q '^-.*"deprecated": "'; then echo 'Schema fields must be deprecated, with version, not removed' >&2; exit 1; fi + @if ! test -z $$CI; then git fetch origin master; fi; \ + if git diff origin/master -- doc/schemas | grep -q '^-.*{' && ! git diff origin/master -- doc/schemas | grep -q '^-.*"deprecated"'; then \ + git diff origin/master -- doc/schemas ; \ + echo 'Schema fields must be "deprecated", with version, not removed' >&2; exit 1; \ + fi schema-diff-check: schema-added-check schema-removed-check