Skip to content

Commit

Permalink
feat: detect bad outgoing links
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldemoura committed Feb 28, 2024
1 parent 10709a9 commit e310192
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/check_cpln_links.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check Links

on:
push:
branches:
- main
pull_request:

jobs:
check_cpln_links:
runs-on: ubuntu-latest
name: Check Links
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Validate outgoing links to Control Plane
run: |
./script/check_cpln_links
shell: bash
3 changes: 3 additions & 0 deletions .overcommit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PreCommit:
ValidateLinks:
enabled: true
command: ["bash", "./script/check_cpln_links"]
CommandDocs:
enabled: true
command: ["bundle", "exec", "rake", "check_command_docs"]
Expand Down
45 changes: 45 additions & 0 deletions script/check_cpln_links
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

bad_links=("controlplane.com/shakacode")
proper_links=("shakacode.controlplane.com")

bold=$(tput bold)
normal=$(tput sgr0)

exit_status=0
accumulated_results=""
seen_bad_links_indexes=()

for ((idx = 0; idx < ${#bad_links[@]}; idx++)); do
results=$(git grep \
--recursive \
--line-number \
--fixed-strings \
--break \
--heading \
--color=always -- \
"${bad_links[idx]}" \
':!script/check_cpln_links')

# Line would become really unwieldly if everything was mushed into the
# conditional, so let's ignore this check here.
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
accumulated_results+="$results"
seen_bad_links_indexes+=("$idx")
exit_status=1
fi
done

if [ "$exit_status" -eq 1 ]; then
echo "${bold}[!] Found the following bad links:${normal}"
echo ""
echo "$accumulated_results"
echo ""
echo "${bold}[*] Please update accordingly:${normal}"
for bad_link_index in "${seen_bad_links_indexes[@]}"; do
echo " ${bad_links[bad_link_index]} -> ${proper_links[bad_link_index]}"
done
fi

exit "$exit_status"

0 comments on commit e310192

Please sign in to comment.