Skip to content

Commit

Permalink
workflows: added VID / VLAN name duplication check
Browse files Browse the repository at this point in the history
  • Loading branch information
Noki authored and pktpls committed Aug 16, 2024
1 parent 0b47bb9 commit 81e36b5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/checks/check-vlan-duplicates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Change to the locations directory
cd locations || exit 1

# Variable to accumulate duplicate findings
all_duplicates=""

# Iterate over each file in the directory
for file in ./*; do
# Check if it is a file
if [ -f "$file" ]; then
# Extract VIDs / VLAN names, sort, and find duplicates
duplicates_vid=$(yq 'select(.networks != null) | .networks[].vid' "$file" | grep -v 'null' | sed 's/["'\'']//g' | sort | uniq -cd)
duplicates_name=$(yq 'select(.networks != null) | .networks[].name' "$file" | grep -v 'null' | sed 's/["'\'']//g' | sort | uniq -cd)
# Accumulate duplicates if found
if [ -n "$duplicates_vid" ]; then
all_duplicates+="\nDuplicate VIDs found in $file:\n$duplicates_vid"
fi
if [ -n "$duplicates_name" ]; then
all_duplicates+="\nDuplicate VLAN names found in $file:\n$duplicates_name"
fi
fi
done

# Check if there were any duplicates found
if [ -n "$all_duplicates" ]; then
echo -e "Duplicates VIDs or VLAN names found:$all_duplicates"
exit 1
else
echo "No duplicate VIDs or VLAN names found."
fi
17 changes: 17 additions & 0 deletions .github/workflows/check-vlan-duplicates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Check for duplicate VIDs and VLAN names

on: [push, pull_request] # yamllint disable-line rule:truthy

jobs:
check-vlan-duplicates:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Run VID and VLAN name duplicate check
run: |
./.github/checks/check-vlan-duplicates.sh

0 comments on commit 81e36b5

Please sign in to comment.