]> git.apps.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
workflow: add group_vars/defaults checks
authorGuillaume Abrioux <gabrioux@redhat.com>
Tue, 29 Jun 2021 19:06:37 +0000 (21:06 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Wed, 30 Jun 2021 06:28:49 +0000 (08:28 +0200)
let's use github workflow for checking defaults values.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
(cherry picked from commit d71db816c6d393d6a42b934912f4f47a290c91fe)

.github/workflows/defaults.yml [new file with mode: 0644]
tests/scripts/workflows/defaults.sh [new file with mode: 0755]

diff --git a/.github/workflows/defaults.yml b/.github/workflows/defaults.yml
new file mode 100644 (file)
index 0000000..38b477c
--- /dev/null
@@ -0,0 +1,10 @@
+name: defaults
+on: [pull_request]
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+      - run: "${GITHUB_WORKSPACE}/tests/scripts/workflows/defaults.sh"
\ No newline at end of file
diff --git a/tests/scripts/workflows/defaults.sh b/tests/scripts/workflows/defaults.sh
new file mode 100755 (executable)
index 0000000..cb847bb
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+set -ex
+
+function git_diff_to_head {
+  git diff --diff-filter=MT --no-color origin/"${GITHUB_BASE_REF}"..HEAD
+}
+
+function match_file {
+  git_diff_to_head | sed -n "s|^+++.*\\($1.*\\)|\\1|p"
+}
+
+# group_vars / defaults
+match_file "/defaults/main.yml"
+nb=$(match_file "/defaults/main.yml" | wc -l)
+if [[ "$nb" -eq 0 ]]; then
+  echo "group_vars has not been touched."
+else
+  match_file "group_vars/"
+  nb_group_vars=$(match_file "group_vars/" | wc -l)
+  if [[ "$nb" -gt "$nb_group_vars" ]]; then
+    echo "One or more files containing default variables has/have been modified."
+    echo "You must run 'generate_group_vars_sample.sh' to generate the group_vars template files."
+    exit 1
+  fi
+fi
+
+# ceph_release_num[ceph_release] statements check
+if match_file "roles/ceph-defaults/" | grep -E '^[<>+].*- ceph_release_num\[ceph_release\]'; then
+  echo "Do not use statements like '- ceph_release_num[ceph_release]' in ceph-defaults role!"
+  echo "'ceph_release' is only populated **after** the play of ceph-defaults, typically in ceph-common or ceph-docker-common."
+  exit 1
+fi
+echo "No '- ceph_release_num[ceph_release]' statements found in ceph-defaults role!"