Skip to content

Commit

Permalink
workflows: add hostname duplicate check
Browse files Browse the repository at this point in the history
  • Loading branch information
Noki authored and pktpls committed Jul 24, 2024
1 parent 17bf7d5 commit e57b305
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/checks/check-hostname-duplicates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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 hostnames, sort, and find duplicates
duplicates=$(sed -nE 's/^\s*-\s*hostname:\s*["'\'']{0,1}([a-zA-Z0-9-]+)["'\''#]?([\s].*)?$/\1/p' "$file" | sort | uniq -cd)

# Accumulate duplicates if found
if [ -n "$duplicates" ]; then
all_duplicates+="\n$duplicates"
fi
fi
done

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

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

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

- name: Run hostname duplicate check
run: |
./.github/checks/check-hostname-duplicates.sh

0 comments on commit e57b305

Please sign in to comment.