Add a workflow that checks if all existing ruletypes have tests #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check for new rule types | |
on: | |
pull_request: | |
schedule: | |
- cron: '0 0 * * *' # Every day at midnight | |
workflow_dispatch: | |
jobs: | |
# -------------------------------------------------------------------------------------------------- | |
# Job to check if we have tests for all available rule types | |
# -------------------------------------------------------------------------------------------------- | |
check-rule-types: | |
name: Check rule types | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 | |
- name: Compare the available rule types with the tests | |
env: | |
SMOKE_TESTS_LIST: "smoke-tests-list.yml" | |
GH_TOKEN: ${{ secrets.GH_PAT_READ_SMOKE_TESTS }} | |
shell: bash | |
run: | | |
AVAILABLE_RULES=$(find ./rule-types/github/ -type f -name "*.yaml" -exec basename {} .yaml \; | sort) | |
echo -e "\e[93m**********************************************************************************************\e[0m" | |
echo -e "\e[93m* The following rule types are available" | |
echo -e "\e[93m**********************************************************************************************\e[0m" | |
echo -e "$AVAILABLE_RULES" | |
temp_dir=$(mktemp -d) | |
gh repo clone stacklok/minder-smoke-tests $temp_dir -- -q | |
pushd $temp_dir | |
# Get the list of existing rule types smoke tests | |
EXISTING_TESTS=$(grep -v '^ *#' $SMOKE_TESTS_LIST | grep "rules/" | sed 's/#.*$//' | sed 's/",\?$//' | sed 's/^"//' | awk -F'/' '{print $NF}' | sort) | |
echo -e "\e[93m**********************************************************************************************\e[0m" | |
echo -e "\e[93m* The following rule types have smoke tests" | |
echo -e "\e[93m**********************************************************************************************\e[0m" | |
echo -e "$EXISTING_TESTS" | |
# Initialize a flag to track missing tests | |
MISSING_TESTS=false | |
# Check if we have tests for all available rule types | |
for rule in $AVAILABLE_RULES; do | |
if [[ ! $EXISTING_TESTS =~ $rule ]]; then | |
echo -e "\e[91m$rule" | |
MISSING_TESTS=true | |
else | |
echo -e "$rule" | |
fi | |
done | |
# Check the flag after looping through all rules | |
if [ "$MISSING_TESTS" = true ]; then | |
echo -e "\e[91m**********************************************************************************************\e[0m" | |
echo -e "\e[91m* FAILURE *\e[0m" | |
echo -e "\e[91m**********************************************************************************************\e[0m" | |
echo -e "\e[91mOne or more rule types are missing tests\e[0m" | |
exit 1 | |
else | |
echo -e "\e[92m**********************************************************************************************\e[0m" | |
echo -e "\e[92m* SUCCESS *\e[0m" | |
echo -e "\e[92m**********************************************************************************************\e[0m" | |
echo -e "\e[92mAll rule types have tests\e[0m" | |
fi |