-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 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,78 @@ | ||
#!/bin/bash | ||
|
||
set -e # Exit immediately if a command exits with a non-zero status | ||
set -o pipefail # If any command in a pipeline fails, return the exit status of the failed command | ||
|
||
# Directory to hold all model files | ||
MODEL_DIR="group_vars" | ||
|
||
# Function to check if a model requires a mac_override | ||
check_mac_override() { | ||
local model=$1 | ||
|
||
# Convert hyphens to underscores to match the model file naming convention | ||
local model_file="${MODEL_DIR}/model_${model//-/_}.yml" | ||
|
||
# Check if the model file exists | ||
if [[ ! -f "$model_file" ]]; then | ||
echo "Model file for $model not found: $model_file" | ||
exit 1 | ||
fi | ||
|
||
# Check if the model requires a mac_override | ||
yq eval '.requires_mac_override // false' "$model_file" | ||
} | ||
|
||
# Get a list of changed .yml files in the locations directory | ||
changed_files=$(git diff --name-only -- '*.yml' | grep '^locations/') | ||
|
||
# Exit if no .yml files have changed | ||
if [[ -z "$changed_files" ]]; then | ||
echo "No relevant .yml files changed." | ||
exit 0 | ||
fi | ||
|
||
# Flag to track if we should fail the script | ||
should_fail=0 | ||
|
||
# Iterate over each changed .yml file | ||
for file in $changed_files; do | ||
echo "Processing file: $file" | ||
|
||
# Get the list of hosts from the changed location file | ||
hosts=$(yq eval '.hosts[]' "$file" 2>/dev/null) | ||
|
||
# Check if the file has hosts section | ||
if [[ -z "$hosts" ]]; then | ||
echo "No hosts found in $file" | ||
continue | ||
fi | ||
|
||
# Iterate over each host in the file | ||
yq eval '.hosts[]' "$file" | while read -r host; do | ||
hostname=$(echo "$host" | yq eval '.hostname' -) | ||
model=$(echo "$host" | yq eval '.model' -) | ||
|
||
# Check if model requires mac_override | ||
requires_mac_override=$(check_mac_override "$model") | ||
|
||
# If mac_override is required, check if it's present in the host's configuration | ||
if [[ "$requires_mac_override" == "true" ]]; then | ||
mac_override=$(echo "$host" | yq eval '.mac_override' -) | ||
|
||
# If the mac_override is missing or null, mark as failure | ||
if [[ -z "$mac_override" || "$mac_override" == "null" ]]; then | ||
echo "Host $hostname is missing mac_override and the model $model requires it." | ||
should_fail=1 | ||
fi | ||
fi | ||
done | ||
done | ||
|
||
# If any host is missing a required mac_override, fail the script | ||
if [[ "$should_fail" -eq 1 ]]; then | ||
echo "Some hosts are missing required mac_override. Failing the check." | ||
exit 1 | ||
fi | ||
|
||
echo "All checks passed." |
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,17 @@ | ||
--- | ||
name: Check mac_overrides | ||
|
||
on: [push, pull_request] # yamllint disable-line rule:truthy | ||
|
||
jobs: | ||
mac_override_check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Run mac_override check | ||
run: | | ||
./.github/checks/check-mac-overrides.sh |
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ contact_nickname: 'zander' | |
contacts: | ||
- '[email protected]' | ||
|
||
|
||
hosts: | ||
- hostname: k12-core | ||
role: corerouter | ||
|