From d1bbfbc48e7af1613a3d74a88ea95a27dcbedb35 Mon Sep 17 00:00:00 2001 From: Tobias Schwarz Date: Mon, 22 Jul 2024 10:46:41 +0000 Subject: [PATCH] workflows: add ip prefix duplicate check --- .github/checks/check-ip-prefix-duplicates.sh | 24 +++++++++++++++++++ .../workflows/check-ip-prefix-duplicates.yml | 16 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 .github/checks/check-ip-prefix-duplicates.sh create mode 100644 .github/workflows/check-ip-prefix-duplicates.yml diff --git a/.github/checks/check-ip-prefix-duplicates.sh b/.github/checks/check-ip-prefix-duplicates.sh new file mode 100755 index 000000000..7e6572820 --- /dev/null +++ b/.github/checks/check-ip-prefix-duplicates.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Change to the locations directory +cd locations || exit 1 + +# Extract IPv4 prefixes, sort them, and check for duplicates +ipv4_duplicates=$(cat * | sed -nE 's/^\s*prefix:\s*["'\'']?([^"\''\s#]+)["'\'']?\s*(#.*)?$/\1/p' | sort | uniq -cd) + +# Extract IPv6 prefixes, sort them, and check for duplicates +ipv6_duplicates=$(cat * | sed -n 's/.*ipv6_prefix:\s*["'\'']\?\([0-9a-fA-F:]\+::\/[0-9]\+\)["'\'']\?.*/\1/p' | sort | uniq -cd) + +if [ -n "$ipv4_duplicates" ] || [ -n "$ipv6_duplicates" ]; then + if [ -n "$ipv4_duplicates" ]; then + echo "Duplicate IPv4 prefixes found:" + echo "$ipv4_duplicates" + fi + if [ -n "$ipv6_duplicates" ]; then + echo "Duplicate IPv6 prefixes found:" + echo "$ipv6_duplicates" + fi + exit 1 +else + echo "No duplicate prefixes found." +fi diff --git a/.github/workflows/check-ip-prefix-duplicates.yml b/.github/workflows/check-ip-prefix-duplicates.yml new file mode 100644 index 000000000..2ff914d6d --- /dev/null +++ b/.github/workflows/check-ip-prefix-duplicates.yml @@ -0,0 +1,16 @@ +name: Check for duplicate IP prefixes + +on: [push, pull_request] + +jobs: + ipv6-check: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run IP prefix duplicate check + run: | + ./.github/checks/check-ip-prefix-duplicates.sh