Check hyperlinks and relative path validity workflow (intel/neural-compressor)
The Check hyperlinks and relative path validity workflow from intel/neural-compressor, explained and optimized by Latchkey.
A
CI health: A - excellent
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the Check hyperlinks and relative path validity workflow from the intel/neural-compressor repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
name: Check hyperlinks and relative path validity
on:
pull_request:
branches: ["main"]
types: [opened, reopened, ready_for_review, synchronize]
# If there is a new commit, the previous jobs will be canceled
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
check-the-validity-of-hyperlinks-in-README:
# choose different runner label for internal and external CI
runs-on: ${{ contains(github.repository, 'intel-innersource') && 'self-hosted' || 'ubuntu-latest' }}
steps:
- name: Clean Up Working Directory
run: sudo rm -rf ${{github.workspace}}/*
- name: Checkout Repo
uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2
with:
fetch-depth: 0
- name: Check the Validity of Hyperlinks
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
cd ${{github.workspace}}
export no_proxy="localhost,127.0.0.1"
curl_timeout=10
delay=1
fail="FALSE"
merged_commit=$(git log -1 --format='%H')
changed_files="$(git diff --name-status --diff-filter=ARM $BASE_SHA ${merged_commit} | awk '/\.md$/ {print $NF}')"
echo "no_proxy=$no_proxy"
echo "http_proxy=$http_proxy"
echo "https_proxy=$https_proxy"
if [ -n "$changed_files" ]; then
for changed_file in $changed_files; do
# echo $changed_file
url_lines=$(grep -H -Eo '\]\(http[s]?://[^)]+\)' "$changed_file") || true
if [ -n "$url_lines" ]; then
for url_line in $url_lines; do
# echo $url_line
url=$(echo "$url_line"|cut -d '(' -f2 | cut -d ')' -f1|sed 's/\.git$//')
path=$(echo "$url_line"|cut -d':' -f1 | cut -d'/' -f2-)
if [[ "$url" == "https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-focal-dc.html" || "$url" == "https://ai.cloud.intel.com/" ]]; then
echo "Link "$url" from ${{github.workspace}}/$path needs to be verified by real person."
else
sleep $delay
response=$(curl --max-time "${curl_timeout}" -L -s -o /dev/null -w "%{http_code}" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" "$url")|| true
if [ "$response" -ne 200 ]; then
echo "**********Validation $url failed ($response), try again**********"
response_retry=$(curl --max-time "${curl_timeout}" -s -o /dev/null -w "%{http_code}" "$url") || true
if [ "$response_retry" -eq 200 ]; then
echo "*****Retry successfully*****"
else
echo "******Retry $url failed ($response_retry), add simulated browser requests******"
response_browser=$(curl --max-time "${curl_timeout}" -s -o /dev/null -w "%{http_code}" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" "$url")|| true
if [ "$response_browser" -eq 200 ]; then
echo "*****Retry successfully*****"
else
echo -e "::error:: Invalid link ($response_retry) from ${{github.workspace}}/$(echo "$url_line"|cut -d':' -f1): $url"
fail="TRUE"
fi
fi
fi
fi
done
fi
done
else
echo "No changed .md file."
fi
if [[ "$fail" == "TRUE" ]]; then
exit 1
else
echo "All hyperlinks are valid."
fi
shell: bash
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
# Copyright (C) 2025 Intel Corporation # SPDX-License-Identifier: Apache-2.0 name: Check hyperlinks and relative path validity on: pull_request: branches: ["main"] types: [opened, reopened, ready_for_review, synchronize] # If there is a new commit, the previous jobs will be canceled concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true permissions: contents: read jobs: check-the-validity-of-hyperlinks-in-README: timeout-minutes: 30 # choose different runner label for internal and external CI runs-on: ${{ contains(github.repository, 'intel-innersource') && 'self-hosted' || 'ubuntu-latest' }} steps: - name: Clean Up Working Directory run: sudo rm -rf ${{github.workspace}}/* - name: Checkout Repo uses: actions/checkout@1e31de5234b9f8995739874a8ce0492dc87873e2 with: fetch-depth: 0 - name: Check the Validity of Hyperlinks env: BASE_SHA: ${{ github.event.pull_request.base.sha }} run: | cd ${{github.workspace}} export no_proxy="localhost,127.0.0.1" curl_timeout=10 delay=1 fail="FALSE" merged_commit=$(git log -1 --format='%H') changed_files="$(git diff --name-status --diff-filter=ARM $BASE_SHA ${merged_commit} | awk '/\.md$/ {print $NF}')" echo "no_proxy=$no_proxy" echo "http_proxy=$http_proxy" echo "https_proxy=$https_proxy" if [ -n "$changed_files" ]; then for changed_file in $changed_files; do # echo $changed_file url_lines=$(grep -H -Eo '\]\(http[s]?://[^)]+\)' "$changed_file") || true if [ -n "$url_lines" ]; then for url_line in $url_lines; do # echo $url_line url=$(echo "$url_line"|cut -d '(' -f2 | cut -d ')' -f1|sed 's/\.git$//') path=$(echo "$url_line"|cut -d':' -f1 | cut -d'/' -f2-) if [[ "$url" == "https://dgpu-docs.intel.com/installation-guides/ubuntu/ubuntu-focal-dc.html" || "$url" == "https://ai.cloud.intel.com/" ]]; then echo "Link "$url" from ${{github.workspace}}/$path needs to be verified by real person." else sleep $delay response=$(curl --max-time "${curl_timeout}" -L -s -o /dev/null -w "%{http_code}" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" "$url")|| true if [ "$response" -ne 200 ]; then echo "**********Validation $url failed ($response), try again**********" response_retry=$(curl --max-time "${curl_timeout}" -s -o /dev/null -w "%{http_code}" "$url") || true if [ "$response_retry" -eq 200 ]; then echo "*****Retry successfully*****" else echo "******Retry $url failed ($response_retry), add simulated browser requests******" response_browser=$(curl --max-time "${curl_timeout}" -s -o /dev/null -w "%{http_code}" -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" "$url")|| true if [ "$response_browser" -eq 200 ]; then echo "*****Retry successfully*****" else echo -e "::error:: Invalid link ($response_retry) from ${{github.workspace}}/$(echo "$url_line"|cut -d':' -f1): $url" fail="TRUE" fi fi fi fi done fi done else echo "No changed .md file." fi if [[ "$fail" == "TRUE" ]]; then exit 1 else echo "All hyperlinks are valid." fi shell: bash
What changed
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.