Skip to content

Commit

Permalink
Add a workflow that checks if all existing ruletypes have tests
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslav Dimitrov <[email protected]>
  • Loading branch information
rdimitrov committed Apr 1, 2024
1 parent 73fca1e commit c1f578f
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/check-for-new-ruletypes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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: ${{ github.token }}
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

0 comments on commit c1f578f

Please sign in to comment.