11name : Deployment Accessibility Checks
22
33on :
4- push :
5- branches :
6- - gh-pages
4+ page_build :
75 workflow_dispatch :
86
97env :
10- PRODUCTION_URL : " https://data6.org/notes/"
11- # must match the end of PRODUCTION_URL
12- # leave blank if at root
138 SITE_SUBDIR : " notes"
149
1510jobs :
1611 axe-audit :
12+ if : |
13+ (github.event_name == 'page_build' && github.event.build.status == 'built') ||
14+ github.event_name == 'workflow_dispatch'
1715 runs-on : ubuntu-latest
1816
1917 steps :
2018 # 1. Checkout Code
2119 - name : Checkout repository
2220 uses : actions/checkout@v4
21+ with :
22+ ref : gh-pages
2323
2424 # 2. Setup Node.js (for Axe and http-server)
2525 - name : Set up Node.js
@@ -39,18 +39,25 @@ jobs:
3939
4040 sleep 5
4141
42- # 7 . Run Axe Scan
42+ # 5 . Run Axe Scan
4343 - name : Run Accessibility Scan
4444 id : axe-scan
4545 run : |
46- # Swap the Production URL for Localhost + Subdirectory
47- # e.g. https://data6.org/notes -> http://localhost:3000/notes
46+ # Reconstruct URLs based on specific domain structure replacing with localhost.
47+ # Get the first URL from sitemap.xml
48+ FIRST_URL=$(sed -n 's/.*<loc>\(.*\)<\/loc>.*/\1/p' sitemap.xml | head -n 1)
49+
50+ # Extract the base URL to be replaced (e.g., 'https://data6.org/notes')
51+ # This assumes all LOCs start with the same base URL.
52+ BASE_URL_TO_REPLACE="${FIRST_URL%%/*}/${{ env.SITE_SUBDIR }}/"
4853
4954 LOCAL_URL="http://localhost:3000/${{ env.SITE_SUBDIR }}"
5055
56+ echo "Base URL found in sitemap to replace: $BASE_URL_TO_REPLACE"
57+
5158 URLS=$(cat sitemap.xml | \
5259 sed -n 's/.*<loc>\(.*\)<\/loc>.*/\1/p' | \
53- sed "s|${{ env.PRODUCTION_URL } }|$LOCAL_URL|" | \
60+ sed "s|${BASE_URL_TO_REPLACE }|$LOCAL_URL|" | \
5461 tr '\n' ' ')
5562
5663 echo "Scanning the following pages:"
6269 --save axe-report.json \
6370 --exit
6471
65- # 8 . Upload Report (Runs even if Step 7 fails)
72+ # 6 . Upload Report (Runs even if previous step fails)
6673 - name : Upload Accessibility Report
6774 if : always()
6875 uses : actions/upload-artifact@v4
0 commit comments