diff --git a/.github/checks/check-mac-overrides-missing.sh b/.github/checks/check-mac-overrides-missing.sh new file mode 100755 index 000000000..be9e20c89 --- /dev/null +++ b/.github/checks/check-mac-overrides-missing.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Initialize a variable to track if any errors are found +error_found=0 + +# Get the list of changed .yml files in the locations directory compared to the main branch +changed_files=$(git diff --name-only main...HEAD | grep '^locations/.*\.yml$') + +# Check if there are no changes in .yml files in the locations directory +if [ -z "$changed_files" ]; then + echo "No changes in .yml files within the locations directory." + exit 0 +fi + +# Loop through all changed location YAML files +for location_file in $changed_files; do + echo "Processing $location_file" + + # Extract host information using yq + host_count=$(yq '.hosts | length' "$location_file") + + # Loop through each host entry + for ((i=0; i<$host_count; i++)); do + hostname=$(yq ".hosts[$i].hostname" "$location_file") + model=$(yq ".hosts[$i].model" "$location_file") + mac_override=$(yq ".hosts[$i].mac_override" "$location_file") + + # Convert model name to match the model file format + model_file=$(echo "$model" | sed 's/-/_/g' | sed 's/"//g') + model_file_path="group_vars/model_${model_file}.yml" + + # Check if the model file exists + if [ ! -f "$model_file_path" ]; then + echo "Error: Model file $model_file_path not found for host $hostname with model $model" + error_found=1 + continue + fi + + # Check if the model requires mac_override + requires_mac_override=$(yq '.requires_mac_override' "$model_file_path") + + if [ "$requires_mac_override" = "true" ]; then + if [ "$mac_override" == "null" ]; then + # Output the missing mac_override details immediately + echo "Error: Host $hostname (model: $model) in $location_file is missing mac_override." + error_found=1 + fi + fi + done +done + +# Exit with a non-zero status code if any errors were found +if [ "$error_found" -eq 1 ]; then + exit 1 +else + echo "MAC override check completed successfully." +fi diff --git a/.github/workflows/check-mac-overrides-missing.yml b/.github/workflows/check-mac-overrides-missing.yml new file mode 100644 index 000000000..72799622c --- /dev/null +++ b/.github/workflows/check-mac-overrides-missing.yml @@ -0,0 +1,25 @@ +--- +name: Check missing mac_overrides + +on: [push, pull_request] # yamllint disable-line rule:truthy + +jobs: + mac_override_missing__check: + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + # Step 2: Fetch the main branch + - name: Checkout main branch + run: | + git fetch origin main + git checkout main + git checkout - + + - name: Run mac_override missing check + run: | + ./.github/checks/check-mac-overrides-missing.sh diff --git a/locations/k12.yml b/locations/k12.yml index 0caeeaccb..fa51098fc 100644 --- a/locations/k12.yml +++ b/locations/k12.yml @@ -8,6 +8,7 @@ contact_nickname: 'zander' contacts: - 'alexanderjabs@gmx.de' + hosts: - hostname: k12-core role: corerouter