diff --git a/.github/workflows/_link_check.yml b/.github/workflows/_link_check.yml index 39779adc73c..2e96b0fd118 100644 --- a/.github/workflows/_link_check.yml +++ b/.github/workflows/_link_check.yml @@ -18,11 +18,11 @@ jobs: timeout: 120 script: | ./scripts/lint_urls.sh $( - { [ "${{ github.event_name }}" = "pull_request" ] \ - && git diff --name-only "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}"; } \ - || \ - { [ "${{ github.event_name }}" = "push" ] \ - && git diff --name-only "${{ github.event.before }}...${{ github.sha }}"; } + if [ "${{ github.event_name }}" = "pull_request" ]; then + echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" + else + echo "${{ github.event.before }}" "${{ github.sha }}" + fi ) || { echo echo "URL lint failed." @@ -43,11 +43,11 @@ jobs: timeout: 60 script: | ./scripts/lint_xrefs.sh $( - { [ "${{ github.event_name }}" = "pull_request" ] \ - && git diff --name-only "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}"; } \ - || \ - { [ "${{ github.event_name }}" = "push" ] \ - && git diff --name-only "${{ github.event.before }}...${{ github.sha }}"; } + if [ "${{ github.event_name }}" = "pull_request" ]; then + echo "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" + else + echo "${{ github.event.before }}" "${{ github.sha }}" + fi ) || { echo echo "Xref lint failed." diff --git a/scripts/lint_urls.sh b/scripts/lint_urls.sh index 64e79c9bec6..d93dc056790 100755 --- a/scripts/lint_urls.sh +++ b/scripts/lint_urls.sh @@ -66,7 +66,7 @@ while IFS=: read -r filepath url; do while [ "$(running_jobs)" -ge "$max_jobs" ]; do sleep 1 done - done < <( +done < <( pattern='(?!.*@lint-ignore)(?\")]*[<>\{\}\$])[^[:space:]<>")\[\]\\|]+' excludes=( ':(exclude,glob)**/.*' @@ -78,12 +78,17 @@ while IFS=: read -r filepath url; do ':(exclude,glob)**/third-party/**' ':(exclude,glob)**/third_party/**' ) - if [ $# -gt 0 ]; then - paths=("$@") + if [ $# -eq 2 ]; then + for filename in $(git diff --name-only --unified=0 "$1...$2"); do + git diff --unified=0 "$1...$2" -- "$filename" "${excludes[@]}" \ + | grep -E '^\+' \ + | grep -Ev '^\+\+\+' \ + | perl -nle 'print for m#'"$pattern"'#g' \ + | sed 's|^|'"$filename"':|' + done else - paths=('*') - fi - git --no-pager grep --no-color -I -P -o "$pattern" -- "${paths[@]}" "${excludes[@]}" \ + git --no-pager grep --no-color -I -P -o "$pattern" -- . "${excludes[@]}" + fi \ | sed -E 's/[^/[:alnum:]]+$//' \ | grep -Ev '://(0\.0\.0\.0|127\.0\.0\.1|localhost)([:/])' \ | grep -Ev '://[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' \ diff --git a/scripts/lint_xrefs.sh b/scripts/lint_xrefs.sh index 6da530d3d2a..3b836df038f 100755 --- a/scripts/lint_xrefs.sh +++ b/scripts/lint_xrefs.sh @@ -34,12 +34,17 @@ done < <( ':(exclude,glob)**/third-party/**' ':(exclude,glob)**/third_party/**' ) - if [ $# -gt 0 ]; then - paths=("$@") + if [ $# -eq 2 ]; then + for filename in $(git diff --name-only --unified=0 "$1...$2"); do + git diff --unified=0 "$1...$2" -- "$filename" "${excludes[@]}" \ + | grep -E '^\+' \ + | grep -Ev '^\+\+\+' \ + | perl -nle 'print for m#'"$pattern"'#g' \ + | sed 's|^|'"$filename"':|' + done else - paths=('*') - fi - git --no-pager grep --no-color -I -P -o "$pattern" -- "${paths[@]}" "${excludes[@]}" \ + git --no-pager grep --no-color -I -P -o "$pattern" -- . "${excludes[@]}" + fi \ | grep -Ev 'https?://' \ | sed -E \ -e 's#([^:]+):\[[^]]+\]\(([^)]+)\)#\1:\2#' \