]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2379] add tools/check-for-missing-api-commands.sh
authorAndrei Pavel <andrei@isc.org>
Fri, 1 Jul 2022 15:23:33 +0000 (18:23 +0300)
committerAndrei Pavel <andrei@isc.org>
Fri, 1 Jul 2022 15:23:41 +0000 (18:23 +0300)
.gitlab-ci.yml
tools/check-for-missing-api-commands.sh [new file with mode: 0755]

index 2183dfcca8e66e1f0e06531d1c1098348815921e..ccfbbd8ac4b5511f10aec00ded2832fba3daa2fd 100644 (file)
@@ -17,15 +17,13 @@ variables:
   # Leave only bandit, flawfinder, semgrep.
   SAST_EXCLUDED_ANALYZERS: "eslint, spotbugs"
 
+image: "${CI_REGISTRY_IMAGE}:latest"
+
 stages:
   - test
 
 shellcheck:
   stage: test
-  image: "${CI_REGISTRY_IMAGE}:latest"
-  tags:
-    - linux
-    - amd64
   script:
     - SCRIPTS=
     - SCRIPTS+="src/bin/admin/admin-utils.sh "
@@ -106,6 +104,7 @@ shellcheck:
     - SCRIPTS+="tools/add-config-h.sh "
     - SCRIPTS+="tools/bump-lib-versions.sh "
     - SCRIPTS+="tools/check-for-duplicate-includes.sh "
+    - SCRIPTS+="tools/check-for-missing-api-commands.sh "
     - SCRIPTS+="tools/mk_cfgrpt.sh "
     - SCRIPTS+="tools/path_replacer.sh.in "
     - SCRIPTS+="tools/print-generated-files.sh "
@@ -116,9 +115,6 @@ shellcheck:
 danger:
   stage: test
   image: registry.gitlab.isc.org/isc-projects/stork/ci-danger
-  tags:
-    - linux
-    - amd64
   before_script:
     - export CI_MERGE_REQUEST_ID=$(git ls-remote -q origin merge-requests\*\head | grep $CI_COMMIT_SHA | sed 's/.*refs\/merge-requests\/\([0-9]*\)\/head/\1/g')
     - export CI_PROJECT_PATH=$CI_PROJECT_ID #some version of gitlab has problems with searching by project path
@@ -133,25 +129,21 @@ danger:
 dhcpdb_create-upgrade-consistency:
   allow_failure: false
   stage: test
-  image: "${CI_REGISTRY_IMAGE}:latest"
   script:
     - ./src/share/database/scripts/utils/are-scripts-in-sync.py
 
 duplicate-includes:
   stage: test
-  image: "${CI_REGISTRY_IMAGE}:latest"
-  tags:
-    - linux
-    - amd64
   script:
     - ./tools/check-for-duplicate-includes.sh
 
+missing-api-commands:
+  stage: test
+  script:
+    - ./tools/check-for-missing-api-commands.sh
+
 missing-config-h-include:
   stage: test
-  image: "${CI_REGISTRY_IMAGE}:latest"
-  tags:
-    - linux
-    - amd64
   script:
     - FILES=$(./tools/add-config-h.sh -n)
     - printf '%s\n' "${FILES}"
@@ -159,10 +151,6 @@ missing-config-h-include:
 
 missing-git-attribute:
   stage: test
-  image: "${CI_REGISTRY_IMAGE}:latest"
-  tags:
-    - linux
-    - amd64
   script:
     - git_diff=$(git diff)
     - if test -n "${git_diff}"; then printf '%s\n\ngit diff should be empty here under all circumstances. CI broken?\n' "${git_diff}"; exit 1; fi
diff --git a/tools/check-for-missing-api-commands.sh b/tools/check-for-missing-api-commands.sh
new file mode 100755 (executable)
index 0000000..f4e406d
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+# Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Usage:
+#
+# check-for-missing-api-commands.sh [$kea_repo]
+#
+# $kea_repo is by default ${script_path}/..
+
+set -eu
+
+script_path=$(cd "$(dirname "${0}")" && pwd)
+cd "${script_path}/.."
+
+if test "${#}" -gt 0; then
+  kea_repo=${1}
+else
+  kea_repo="${script_path}/.."
+fi
+
+# In order:
+# 1. grep perl-regexp with-filename only-matching recursive null-output
+# 2. Exclude doxygen files.
+# 3. Exclude tests directories.
+# 4. Grep for all calls to registerCommandCallout even if they span multiple lines.
+# 5. Remove the null byte to be able to assign it to a variable.
+# 6. Remove the newlines to be able to more easily grep further.
+# 7. Remove the spaces to be able to more easily grep further.
+# 8. Turn commas into newlines so that each command is on its own line.
+# 9. Remove commands that are commented out in code.
+# 10. Grep for the name of the command alone.
+# 11. Remove double quotes from the command name.
+commands=$(grep -Phorz \
+          --exclude '*.dox' \
+          --exclude-dir 'tests' \
+          '.*registerCommandCallout\(\s*\n*\s*".*?",' . | \
+          tr -d '\0' | \
+          tr -d '\n' | \
+          tr -d ' ' | \
+          tr ',' '\n' | \
+          grep -Ev '//.*registerCommandCallout' | \
+          grep -Eo '".*?"' | \
+          tr -d '"')
+
+# Check if there is a file with the ${command}.json format in src/share/api.
+failed=false
+for i in ${commands}; do
+  if test -f "${kea_repo}/src/share/api/${i}.json"; then
+    printf '[ SUCCESS ] %s\n' "${i}"
+  else
+    failed=true
+    printf '[ FAILURE ] %s  - not found in src/share/api\n' "${i}"
+  fi
+done
+
+if "${failed}"; then
+  return 1
+fi