diff --git a/.ci-scripts/indent b/.ci-scripts/indent new file mode 100755 index 0000000..6524e12 --- /dev/null +++ b/.ci-scripts/indent @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e # halt script on error + +rm -f /tmp/indent.py +wget -q https://raw.githubusercontent.com/stfc/Pan-Indenter/master/pan_indent_checker.py -O /tmp/indent.py +chmod u+x /tmp/indent.py + +git diff --name-only --diff-filter=d HEAD^ | grep '\.pan$' | xargs -rn1 /tmp/indent.py check || exit 1 diff --git a/.ci-scripts/panlint b/.ci-scripts/panlint index b7ba142..fdb53b0 100755 --- a/.ci-scripts/panlint +++ b/.ci-scripts/panlint @@ -5,4 +5,4 @@ rm -f /tmp/panlint.py wget -q https://raw.githubusercontent.com/quattor/pan/master/panc/src/main/scripts/panlint/panlint.py -O /tmp/panlint.py chmod u+x /tmp/panlint.py -git diff --name-only HEAD^ | grep '\.pan$' | xargs -r /tmp/panlint.py || exit 1 +git diff --name-only --diff-filter=d HEAD^ | grep '\.pan$' | xargs -r /tmp/panlint.py || exit 1 diff --git a/.ci-scripts/test-library b/.ci-scripts/test-library deleted file mode 100755 index edf6bf9..0000000 --- a/.ci-scripts/test-library +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash - -set -e # halt script on error - -# Retrieve last version of create-vanilla-SCDB from GitHub -echo "Downloading create-vanilla-SCDB from GitHub..." -rm -f /tmp/create-vanilla-SCDB.sh -wget -q https://raw.githubusercontent.com/quattor/scdb/master/utils/scdb/create-vanilla-SCDB.sh -O /tmp/create-vanilla-SCDB.sh -chmod u+x /tmp/create-vanilla-SCDB.sh - -/tmp/create-vanilla-SCDB.sh -F --debug --continuous-integration HEAD diff --git a/.ci-scripts/test-templates b/.ci-scripts/test-templates new file mode 100755 index 0000000..ba2b8e2 --- /dev/null +++ b/.ci-scripts/test-templates @@ -0,0 +1,438 @@ +#!/bin/bash +# +# Create one big profile including all pan templates and try to compile it +# (optional) arguments: +# clean: runs git clean (and will remove changes), to be used on jenkins only +# +rm -Rf ./build_temp + +if [ "$1" == "clean" ]; then + git clean -fxd +fi + +mkdir build_temp + +tplfiles=`find . -type f -regex '.*\.tpl' |wc -l` +if [ $tplfiles -ne 0 ]; then + echo "[ERROR] found .tpl files, should be .pan only: $tplfiles" + exit 1 +fi + +# panc-annotations can have issues with multiple threads creating dirs +echo "Testing pan annotations" +find . -type d ! -regex '.*build_temp.*' | xargs -I '{}' mkdir -p 'build_temp/{}' +nrpanfiles=`find . -type f -regex '.*\.pan' | grep -v yumng | wc -l` +panfiles=`find . -type f -regex '.*\.pan' | grep -v yumng` +panc-annotations --output-dir build_temp $panfiles + +nrannofiles=`find build_temp -type f -regex '.*annotation\.xml'|wc -l` +if [ $nrpanfiles != $nrannofiles ]; then + echo "[ERROR]: number of annotation files is not the same as numnber of pan files." + exit 1 +else + echo "pan annotations ok" +fi + +cat > build_temp/test.pan < build_temp/rpms/package_default_versions.pan < build_temp/rpms/web_server.pan <> build_temp/test.pan +find . -type f ! -regex '^./pan/.*' ! -regex '^./build_temp/.*' -name *.pan | grep -v yumng | xargs sed -n "s/^declaration[ ]\+template[ ]\+\(.*\);/include '\1';/p" | sort >> build_temp/test.pan +find . -type f ! -regex '^./build_temp/.*' -name *.pan | grep -v yumng | xargs sed -n "s/^\(unique[ ]\+\)\?template[ ]\+\(.*\);/include '\2';/p" |sort >> build_temp/test.pan + +# fix for multiversion metaconfig +sed -i '/.*metaconfig\/\(elasticsearch\|logstash\|beats\|kibana\|slurm\)\/.*_[0-9].*/d' build_temp/test.pan +# none-versioned ganesha templates are v1 +sed -i "/.*metaconfig\/ganesha\/\(config\(_v1\)\?\|schema\)'/d" build_temp/test.pan +sed -i "/.*metaconfig\/ganesha\/fsal.*/d" build_temp/test.pan +# action.pan is included by the schema and can only be included after inputs.pan +sed -i "/.*metaconfig\/rsyslog\/actions.*/d" build_temp/test.pan + +# only spma yum +sed -i "/.*components\/spma\/\(apt\|ips\).*/d" build_temp/test.pan + +# Only test default schema version of ceph component +sed -i "/.*components\/ceph\/v[1-9][0-9]*\/.*/d" build_temp/test.pan + +# Only test default schema version of ssh component +sed -i "/.*components\/ssh\/schema-.*/d" build_temp/test.pan + +# try to compile it +output=`panc --output-dir build_temp --include-path .:build_temp build_temp/test.pan 2>&1` + +# use "$output" to preserve newlines in echo + +# if it fails, it's sort of ok when due to bind problems because there's no actual data +ec=$? + +if [ $ec -eq 0 ]; then + echo "$output" + echo "[OK] Pan compilation success." +else + echo "$output" | grep 'element does not exist' >& /dev/null + if [ $? -eq 0 ]; then + echo "$output" | grep 'bound to type' >& /dev/null + if [ $? -eq 0 ]; then + echo "$output" + echo "[OK] expected panc failure due to missing data." + ec=0 + fi + fi +fi + +if [ $ec -ne 0 ]; then + echo "$output" + echo "[ERROR] Pan compilation failed" +fi + +exit $ec diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 55875ed..8c1e8b5 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -3,38 +3,50 @@ name: Run Tests on: [push, pull_request] jobs: + test-library: runs-on: ubuntu-latest - container: centos:7 + container: ghcr.io/quattor/quattor-test-container:latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install dependencies - run: yum -y install wget subversion git - - name: Setup Java JDK - uses: actions/setup-java@v2.0.0 - with: - java-version: 11 - distribution: adopt + run: dnf -y install subversion - name: run tests run: .ci-scripts/test-library env: TRAVIS_BUILD_DIR: "$GITHUB_WORKSPACE" TRAVIS_REPO_SLUG: "$GITHUB_REPOSITORY" TRAVIS_BRANCH: "${GITHUB_HEAD_REF:-master}" + panlint: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: # we need the full repo or HEAD^ does not work fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: 3.6 + python-version: 3 - name: Install dependencies run: pip install colorama prettytable six - name: run panlint run: .ci-scripts/panlint + + indentation: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + # we need the full repo or HEAD^ does not work + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3 + - name: run indent checker + run: .ci-scripts/indent