From 5d4ad39cc957710f0be73509348bce2ad3d205cc Mon Sep 17 00:00:00 2001 From: milinddethe15 Date: Sat, 14 Oct 2023 19:45:48 +0530 Subject: [PATCH 1/3] Added github action and updated check-dups.sh --- .github/workflows/check-duplicates.yml | 20 ++++++++++++++++++ scripts/check-dups.sh | 29 +++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/check-duplicates.yml diff --git a/.github/workflows/check-duplicates.yml b/.github/workflows/check-duplicates.yml new file mode 100644 index 0000000..cc0e7a3 --- /dev/null +++ b/.github/workflows/check-duplicates.yml @@ -0,0 +1,20 @@ +name: Check Duplicates + +on: + pull_request: + push: + branches: + - main + +jobs: + check-duplicates: + runs-on: ubuntu-latest + steps: + - name: Check Out Code + uses: actions/checkout@v2 + + - name: Run Check Duplicates Script + run: | + chmod +x scripts/check-dups.sh + ./scripts/check-dups.sh + working-directory: ${{ github.workspace }} diff --git a/scripts/check-dups.sh b/scripts/check-dups.sh index bab7ff9..74a1918 100755 --- a/scripts/check-dups.sh +++ b/scripts/check-dups.sh @@ -14,15 +14,24 @@ then readme="../README.md" fi -links=$(cat $readme | egrep "\- \[" | wc -l) +# Function to extract links from a section and check for duplicates +check_section() { + section=$1 + section_escaped=$(sed 's/[&/\]/\\&/g' <<< "$section") + section_content=$(awk -v section="$section" '/^### / {p=0} {if(p)print} /^### '"$section"'/ {p=1}' "$readme") + duplicate_links=$(echo "$section_content" | grep -oP '\[.*?\]\(\K[^)]+' | sort | uniq -d) + if [[ -n $duplicate_links ]]; then + echo "[ ERR ] DUPLICATE LINKS FOUND" + echo "$duplicate_links" + exit 1 + fi +} -uniqlinks=$(cat $readme | egrep "\- \[" | uniq | wc -l) +# Get all unique section headings from the README file and handle spaces and slashes +sections=$(grep '^### ' "$readme" | sed 's/^### //' | sed 's/[\/&]/\\&/g') -if [[ $links -eq $uniqlinks ]]; -then - echo "[ OK! ] NO DUPLICATES FOUND." - echo "$links links in README." -else - echo "[ ERR ] DUPLICATES FOUND!" - cat $readme | egrep "\- \[" | uniq -c | egrep -iv "1 - [" -fi \ No newline at end of file +# Call the function for each section +for section in $sections; do + check_section "$section" +done +echo "[ OK! ] NO DUPLICATES FOUND." \ No newline at end of file From cf34838f480241ee2d1a806471ec84e8f1578b9b Mon Sep 17 00:00:00 2001 From: M!l!nd <99114125+milinddethe15@users.noreply.github.com> Date: Sat, 14 Oct 2023 20:11:18 +0530 Subject: [PATCH 2/3] Update check-duplicates.yml --- .github/workflows/check-duplicates.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-duplicates.yml b/.github/workflows/check-duplicates.yml index cc0e7a3..2a36b31 100644 --- a/.github/workflows/check-duplicates.yml +++ b/.github/workflows/check-duplicates.yml @@ -2,6 +2,8 @@ name: Check Duplicates on: pull_request: + branches: + - main push: branches: - main From bb2ce143793262153d1658849ee67350ed7cade3 Mon Sep 17 00:00:00 2001 From: milinddethe15 Date: Sat, 14 Oct 2023 20:20:00 +0530 Subject: [PATCH 3/3] removed `section_escaped` --- scripts/check-dups.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/check-dups.sh b/scripts/check-dups.sh index 74a1918..6e50ca8 100755 --- a/scripts/check-dups.sh +++ b/scripts/check-dups.sh @@ -17,7 +17,6 @@ fi # Function to extract links from a section and check for duplicates check_section() { section=$1 - section_escaped=$(sed 's/[&/\]/\\&/g' <<< "$section") section_content=$(awk -v section="$section" '/^### / {p=0} {if(p)print} /^### '"$section"'/ {p=1}' "$readme") duplicate_links=$(echo "$section_content" | grep -oP '\[.*?\]\(\K[^)]+' | sort | uniq -d) if [[ -n $duplicate_links ]]; then