-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a workflow that checks if all existing ruletypes have tests
Signed-off-by: Radoslav Dimitrov <[email protected]>
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
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
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 |