Fix broken links (#164) #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Run Tests | |
on: | |
push: {} | |
workflow_dispatch: {} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- uses: xu-cheng/texlive-action@v2 | |
with: | |
scheme: full # Consider changing to 'basic' or 'medium' if possible | |
run: | | |
apk add make | |
apk add g++ | |
apk add zip | |
make script zip | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: PDF_Test | |
path: vorkurs.pdf | |
check-links: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Download compiled PDF | |
uses: actions/download-artifact@v4 | |
with: | |
name: PDF_Test | |
path: . | |
- name: Install pdfgrep | |
run: sudo apt-get update && sudo apt-get install -y pdfgrep | |
- name: Extract and Check URLs | |
run: | | |
urls=$(pdfgrep -o -P 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' vorkurs.pdf | sort -u) | |
error_count=0 | |
for url in $urls; do | |
echo "Checking URL: $url" | |
if [[ ! "$url" =~ ^https:// ]]; then | |
echo "ERROR: URL is not HTTPS: $url" | |
error_count=$((error_count + 1)) | |
continue | |
fi | |
if ! curl -Isf --fail-early --connect-timeout 10 "$url" > /dev/null 2>&1; then | |
curl_error=$(curl -Isf --fail-early --connect-timeout 10 "$url" 2>&1 > /dev/null) | |
if [[ $curl_error == *"Failed to connect"* ]]; then | |
echo "ERROR: Connection failed: $url" | |
elif [[ $curl_error == *"Could not resolve host"* ]]; then | |
echo "ERROR: DNS resolution failed: $url" | |
elif [[ $curl_error == *"SSL certificate problem"* ]]; then | |
echo "ERROR: Initial SSL certificate problem: $url" | |
else | |
echo "ERROR: Failed to access: $url (curl error: $curl_error)" | |
fi | |
if ! openssl s_client -connect "$(echo "$url" | sed 's/https\?:\/\///' | cut -d/ -f1):443" -servername "$(echo "$url" | sed 's/https\?:\/\///' | cut -d/ -f1)" 2>/dev/null </dev/null | openssl x509 -noout; then | |
echo " -> CERTIFICATE ERROR DETECTED!" | |
fi | |
error_count=$((error_count + 1)) | |
fi | |
done | |
if [ "$error_count" -gt 0 ]; then | |
echo "::error::Found $error_count broken or insecure links!" | |
exit 1 | |
fi | |
shell: bash |