|
| 1 | +name: Build and Run Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: {} |
| 5 | + workflow_dispatch: {} |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + timeout-minutes: 30 |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v4 |
| 14 | + - uses: xu-cheng/texlive-action@v2 |
| 15 | + with: |
| 16 | + scheme: full # Consider changing to 'basic' or 'medium' if possible |
| 17 | + run: | |
| 18 | + apk add make |
| 19 | + apk add g++ |
| 20 | + apk add zip |
| 21 | + make script zip |
| 22 | + - uses: actions/upload-artifact@v4 |
| 23 | + with: |
| 24 | + name: PDF_Test |
| 25 | + path: vorkurs.pdf |
| 26 | + |
| 27 | + check-links: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + needs: build |
| 30 | + steps: |
| 31 | + - name: Checkout code |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - name: Download compiled PDF |
| 35 | + uses: actions/download-artifact@v4 |
| 36 | + with: |
| 37 | + name: PDF_Test |
| 38 | + path: . |
| 39 | + |
| 40 | + - name: Install pdfgrep |
| 41 | + run: sudo apt-get update && sudo apt-get install -y pdfgrep |
| 42 | + |
| 43 | + - name: Extract and Check URLs |
| 44 | + run: | |
| 45 | + 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) |
| 46 | + error_count=0 |
| 47 | +
|
| 48 | + for url in $urls; do |
| 49 | + echo "Checking URL: $url" |
| 50 | +
|
| 51 | + if [[ ! "$url" =~ ^https:// ]]; then |
| 52 | + echo "ERROR: URL is not HTTPS: $url" |
| 53 | + error_count=$((error_count + 1)) |
| 54 | + continue |
| 55 | + fi |
| 56 | +
|
| 57 | + if ! curl -Isf --fail-early --connect-timeout 10 "$url" > /dev/null 2>&1; then |
| 58 | + curl_error=$(curl -Isf --fail-early --connect-timeout 10 "$url" 2>&1 > /dev/null) |
| 59 | + if [[ $curl_error == *"Failed to connect"* ]]; then |
| 60 | + echo "ERROR: Connection failed: $url" |
| 61 | + elif [[ $curl_error == *"Could not resolve host"* ]]; then |
| 62 | + echo "ERROR: DNS resolution failed: $url" |
| 63 | + elif [[ $curl_error == *"SSL certificate problem"* ]]; then |
| 64 | + echo "ERROR: Initial SSL certificate problem: $url" |
| 65 | + else |
| 66 | + echo "ERROR: Failed to access: $url (curl error: $curl_error)" |
| 67 | + fi |
| 68 | + 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 |
| 69 | + echo " -> CERTIFICATE ERROR DETECTED!" |
| 70 | + fi |
| 71 | +
|
| 72 | + error_count=$((error_count + 1)) |
| 73 | + fi |
| 74 | + done |
| 75 | +
|
| 76 | + if [ "$error_count" -gt 0 ]; then |
| 77 | + echo "::error::Found $error_count broken or insecure links!" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + shell: bash |
0 commit comments