|
| 1 | +name: Quality Checks |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, main ] |
| 6 | + pull_request: |
| 7 | + branches: [ master, main ] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + html-validation: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Harden Runner |
| 17 | + uses: step-security/harden-runner@20cf305ff2073D973412fa9b1e3a4f227bda3c76 # v2.14.0 |
| 18 | + with: |
| 19 | + egress-policy: audit |
| 20 | + |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 23 | + |
| 24 | + - name: Setup Node.js |
| 25 | + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 |
| 26 | + with: |
| 27 | + node-version: '24' |
| 28 | + |
| 29 | + - name: Cache npm global packages |
| 30 | + uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2 |
| 31 | + with: |
| 32 | + path: ~/.npm |
| 33 | + key: ${{ runner.os }}-npm-global-${{ hashFiles('**/package-lock.json') }}-htmlhint |
| 34 | + restore-keys: | |
| 35 | + ${{ runner.os }}-npm-global- |
| 36 | +
|
| 37 | + - name: Install HTMLHint |
| 38 | + run: npm install -g htmlhint |
| 39 | + |
| 40 | + - name: Validate HTML |
| 41 | + run: | |
| 42 | + echo "🔍 Validating HTML files with HTMLHint..." |
| 43 | + echo "" |
| 44 | + |
| 45 | + # Run HTMLHint on all HTML files and capture results |
| 46 | + if htmlhint *.html > htmlhint-report.txt 2>&1; then |
| 47 | + echo "✅ All HTML files passed validation" |
| 48 | + cat htmlhint-report.txt |
| 49 | + else |
| 50 | + echo "⚠️ HTML validation found issues:" |
| 51 | + cat htmlhint-report.txt |
| 52 | + echo "" |
| 53 | + echo "📊 Validation completed with warnings/errors" |
| 54 | + # Don't fail the build on HTML validation issues initially |
| 55 | + # exit 1 |
| 56 | + fi |
| 57 | + |
| 58 | + - name: Upload HTMLHint Report |
| 59 | + if: always() |
| 60 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 61 | + with: |
| 62 | + name: htmlhint-report |
| 63 | + path: htmlhint-report.txt |
| 64 | + retention-days: 30 |
| 65 | + |
| 66 | + link-checker: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + steps: |
| 69 | + - name: Harden Runner |
| 70 | + uses: step-security/harden-runner@20cf305ff2073D973412fa9b1e3a4f227bda3c76 # v2.14.0 |
| 71 | + with: |
| 72 | + egress-policy: audit |
| 73 | + |
| 74 | + - name: Checkout repository |
| 75 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 76 | + |
| 77 | + - name: Setup Node.js |
| 78 | + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 |
| 79 | + with: |
| 80 | + node-version: '24' |
| 81 | + |
| 82 | + - name: Cache npm packages |
| 83 | + uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2 |
| 84 | + with: |
| 85 | + path: ~/.npm |
| 86 | + key: ${{ runner.os }}-npm-linkinator6-${{ hashFiles('**/package-lock.json') }} |
| 87 | + restore-keys: | |
| 88 | + ${{ runner.os }}-npm-linkinator6- |
| 89 | +
|
| 90 | + - name: Cache apt packages |
| 91 | + uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2 |
| 92 | + with: |
| 93 | + path: /var/cache/apt/archives |
| 94 | + key: ${{ runner.os }}-apt-${{ hashFiles('**/.github/workflows/quality-checks.yml') }} |
| 95 | + restore-keys: | |
| 96 | + ${{ runner.os }}-apt- |
| 97 | +
|
| 98 | + - name: Install linkinator@6 |
| 99 | + run: | |
| 100 | + echo "Installing linkinator v6 (v7.5.2 has module resolution bug)..." |
| 101 | + npm install -g linkinator@6 |
| 102 | + linkinator --version |
| 103 | + echo "✅ linkinator v6 installed successfully" |
| 104 | +
|
| 105 | + - name: Install jq |
| 106 | + run: sudo apt-get update && sudo apt-get install -y jq |
| 107 | + |
| 108 | + - name: Check internal links (static files) |
| 109 | + run: | |
| 110 | + echo "🔍 Starting local HTTP server for internal link checking..." |
| 111 | + python3 -m http.server 8080 & |
| 112 | + SERVER_PID=$! |
| 113 | + echo "Server PID: $SERVER_PID" |
| 114 | + |
| 115 | + # Wait for server to start |
| 116 | + sleep 5 |
| 117 | + |
| 118 | + echo "" |
| 119 | + echo "🔗 Checking internal links on localhost..." |
| 120 | + |
| 121 | + # Check links on localhost using global linkinator v6 |
| 122 | + linkinator http://localhost:8080/ \ |
| 123 | + --recurse \ |
| 124 | + --skip "^(?!http://localhost:8080)" \ |
| 125 | + --format json > internal-links-report.json || true |
| 126 | + |
| 127 | + # Kill server |
| 128 | + kill $SERVER_PID 2>/dev/null || true |
| 129 | + |
| 130 | + # Parse and display results |
| 131 | + echo "" |
| 132 | + echo "📊 Internal Link Check Results:" |
| 133 | + if [ -f internal-links-report.json ]; then |
| 134 | + jq '.links[0:10]' internal-links-report.json |
| 135 | + |
| 136 | + # Count passed and failed links |
| 137 | + read passed failed < <(jq -r ' |
| 138 | + [([.links[] | select(.state == "OK")] | length), |
| 139 | + ([.links[] | select(.state != "OK")] | length)] | @tsv |
| 140 | + ' internal-links-report.json 2>/dev/null || echo "0 0") |
| 141 | + |
| 142 | + echo "" |
| 143 | + echo "✅ Passed: $passed links" |
| 144 | + echo "❌ Failed: $failed links" |
| 145 | + fi |
| 146 | + |
| 147 | + - name: Check external links (sample pages) |
| 148 | + run: | |
| 149 | + echo "" |
| 150 | + echo "🌐 Checking external links on deployed site (sample check)..." |
| 151 | + echo "Note: Only checking main index page to avoid rate limiting" |
| 152 | + |
| 153 | + # Check external links on deployed site |
| 154 | + linkinator https://riksdagsmonitor.com/ \ |
| 155 | + --skip "(fonts\.googleapis\.com|fonts\.gstatic\.com|github\.com)" \ |
| 156 | + --timeout 30000 \ |
| 157 | + --format json > external-links-report.json || true |
| 158 | + |
| 159 | + echo "" |
| 160 | + echo "📊 External Link Check Results:" |
| 161 | + if [ -f external-links-report.json ]; then |
| 162 | + jq '.links[0:10]' external-links-report.json |
| 163 | + |
| 164 | + # Count passed and failed links |
| 165 | + read passed failed < <(jq -r ' |
| 166 | + [([.links[] | select(.state == "OK")] | length), |
| 167 | + ([.links[] | select(.state != "OK")] | length)] | @tsv |
| 168 | + ' external-links-report.json 2>/dev/null || echo "0 0") |
| 169 | + |
| 170 | + echo "" |
| 171 | + echo "✅ Passed: $passed links" |
| 172 | + echo "❌ Failed: $failed links" |
| 173 | + echo "" |
| 174 | + echo "ℹ️ Note: External link checking is limited to avoid rate limiting" |
| 175 | + fi |
| 176 | +
|
| 177 | + - name: Upload Link Check Reports |
| 178 | + if: always() |
| 179 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 180 | + with: |
| 181 | + name: link-checker-reports |
| 182 | + path: | |
| 183 | + internal-links-report.json |
| 184 | + external-links-report.json |
| 185 | + retention-days: 30 |
| 186 | + |
| 187 | + summary: |
| 188 | + runs-on: ubuntu-latest |
| 189 | + needs: [html-validation, link-checker] |
| 190 | + if: always() |
| 191 | + steps: |
| 192 | + - name: Harden the runner (Audit all outbound calls) |
| 193 | + uses: step-security/harden-runner@20cf305ff2073D973412fa9b1e3a4f227bda3c76 # v2.14.0 |
| 194 | + with: |
| 195 | + egress-policy: audit |
| 196 | + |
| 197 | + - name: Quality Check Summary |
| 198 | + run: | |
| 199 | + echo "==========================================" |
| 200 | + echo " Quality Checks Completed" |
| 201 | + echo "==========================================" |
| 202 | + echo "" |
| 203 | + echo "✅ HTML validation completed" |
| 204 | + echo "✅ Link checking completed" |
| 205 | + echo "" |
| 206 | + echo "📊 Check artifacts for detailed reports:" |
| 207 | + echo " - htmlhint-report" |
| 208 | + echo " - link-checker-reports" |
| 209 | + echo "" |
| 210 | + echo "==========================================" |
0 commit comments