|
1 | 1 | # Orchestrating workflow: Scan all demo apps in parallel |
2 | | -# Manually triggered - runs accessibility scans on all 5 demo apps simultaneously |
| 2 | +# Manually triggered - dispatches a11y-scan workflows in sibling repos |
| 3 | +# so SARIF results appear in each repo's own Code Scanning alerts |
3 | 4 |
|
4 | 5 | name: Scan All Demo Apps |
5 | 6 |
|
|
8 | 9 |
|
9 | 10 | permissions: |
10 | 11 | contents: read |
11 | | - security-events: write |
12 | | - |
13 | | -env: |
14 | | - SCANNER_BASE_URL: https://a11y-scan-demo-app.azurewebsites.net |
15 | 12 |
|
16 | 13 | jobs: |
17 | 14 | scan: |
18 | | - name: Scan ${{ matrix.siteName }} |
| 15 | + name: Scan ${{ matrix.repo }} |
19 | 16 | runs-on: ubuntu-latest |
20 | | - timeout-minutes: 5 |
| 17 | + timeout-minutes: 15 |
21 | 18 | strategy: |
22 | 19 | fail-fast: false |
23 | 20 | max-parallel: 5 |
24 | 21 | matrix: |
25 | 22 | include: |
26 | | - - siteName: a11y-demo-app-001 |
27 | | - siteUrl: https://a11y-demo-app-001-app.azurewebsites.net/ |
28 | | - - siteName: a11y-demo-app-002 |
29 | | - siteUrl: https://a11y-demo-app-002-app.azurewebsites.net/ |
30 | | - - siteName: a11y-demo-app-003 |
31 | | - siteUrl: https://a11y-demo-app-003-app.azurewebsites.net/ |
32 | | - - siteName: a11y-demo-app-004 |
33 | | - siteUrl: https://a11y-demo-app-004-app.azurewebsites.net/ |
34 | | - - siteName: a11y-demo-app-005 |
35 | | - siteUrl: https://a11y-demo-app-005-app.azurewebsites.net/ |
| 23 | + - repo: a11y-demo-app-001 |
| 24 | + - repo: a11y-demo-app-002 |
| 25 | + - repo: a11y-demo-app-003 |
| 26 | + - repo: a11y-demo-app-004 |
| 27 | + - repo: a11y-demo-app-005 |
36 | 28 | steps: |
37 | | - - uses: actions/checkout@v4 |
38 | | - |
39 | | - - name: Run accessibility scan - ${{ matrix.siteName }} |
40 | | - id: scan |
| 29 | + - name: Dispatch a11y-scan workflow in ${{ matrix.repo }} |
| 30 | + env: |
| 31 | + GH_TOKEN: ${{ secrets.DISPATCH_PAT }} |
41 | 32 | run: | |
42 | | - mkdir -p results |
43 | | - for attempt in 1 2 3; do |
44 | | - HTTP_STATUS=$(curl -s -o results/${{ matrix.siteName }}.sarif -w "%{http_code}" \ |
45 | | - -X POST "${{ env.SCANNER_BASE_URL }}/api/ci/scan" \ |
46 | | - -H "Content-Type: application/json" \ |
47 | | - -d '{"url": "${{ matrix.siteUrl }}", "format": "sarif"}' \ |
48 | | - --max-time 120) |
49 | | -
|
50 | | - echo "Attempt $attempt - HTTP status: $HTTP_STATUS" |
| 33 | + BEFORE=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 34 | + echo "before=$BEFORE" >> "$GITHUB_ENV" |
| 35 | + echo "Dispatching a11y-scan workflow for ${{ matrix.repo }} (after $BEFORE)..." |
| 36 | + gh workflow run a11y-scan.yml \ |
| 37 | + --repo devopsabcs-engineering/${{ matrix.repo }} \ |
| 38 | + --ref main |
| 39 | + echo "Dispatch sent to ${{ matrix.repo }}" |
51 | 40 |
|
52 | | - if [ "$HTTP_STATUS" -eq 200 ]; then |
53 | | - echo "SARIF file written: results/${{ matrix.siteName }}.sarif" |
54 | | - echo "File size: $(wc -c < results/${{ matrix.siteName }}.sarif) bytes" |
55 | | - echo "scan_ok=true" >> "$GITHUB_OUTPUT" |
| 41 | + - name: Wait for workflow run to appear |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ secrets.DISPATCH_PAT }} |
| 44 | + run: | |
| 45 | + echo "Waiting for a11y-scan run created after ${{ env.before }}..." |
| 46 | + for i in $(seq 1 30); do |
| 47 | + RUN_ID=$(gh run list \ |
| 48 | + --repo devopsabcs-engineering/${{ matrix.repo }} \ |
| 49 | + --workflow a11y-scan.yml \ |
| 50 | + --json databaseId,createdAt,event \ |
| 51 | + --jq "[.[] | select(.createdAt >= \"${{ env.before }}\" and .event == \"workflow_dispatch\")] | .[0].databaseId") |
| 52 | + if [ -n "$RUN_ID" ] && [ "$RUN_ID" != "null" ]; then |
| 53 | + echo "Found workflow run: $RUN_ID" |
| 54 | + echo "run_id=$RUN_ID" >> "$GITHUB_ENV" |
56 | 55 | exit 0 |
57 | 56 | fi |
58 | | -
|
59 | | - echo "::warning::Scan attempt $attempt failed for ${{ matrix.siteUrl }} (HTTP $HTTP_STATUS)" |
60 | | - if [ "$attempt" -lt 3 ]; then |
61 | | - echo "Retrying in 30s..." |
62 | | - sleep 30 |
63 | | - fi |
| 57 | + echo "Attempt $i: run not found yet, waiting 10s..." |
| 58 | + sleep 10 |
64 | 59 | done |
65 | | -
|
66 | | - echo "::error::Scan failed for ${{ matrix.siteUrl }} after 3 attempts (HTTP $HTTP_STATUS)" |
67 | | - cat results/${{ matrix.siteName }}.sarif |
68 | | - echo "scan_ok=false" >> "$GITHUB_OUTPUT" |
| 60 | + echo "::error::Timed out waiting for a11y-scan run to appear in ${{ matrix.repo }}" |
69 | 61 | exit 1 |
70 | 62 |
|
71 | | - - name: Upload SARIF artifact - ${{ matrix.siteName }} |
72 | | - uses: actions/upload-artifact@v4 |
73 | | - if: always() |
74 | | - with: |
75 | | - name: a11y-sarif-${{ matrix.siteName }} |
76 | | - path: results/ |
77 | | - |
78 | | - - name: Upload SARIF to GitHub Security - ${{ matrix.siteName }} |
79 | | - uses: github/codeql-action/upload-sarif@v4 |
80 | | - if: steps.scan.outputs.scan_ok == 'true' |
81 | | - with: |
82 | | - sarif_file: results/${{ matrix.siteName }}.sarif |
83 | | - category: a11y-${{ matrix.siteName }} |
84 | | - wait-for-processing: true |
| 63 | + - name: Wait for workflow to complete |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ secrets.DISPATCH_PAT }} |
| 66 | + run: | |
| 67 | + echo "Watching a11y-scan run ${{ env.run_id }} in ${{ matrix.repo }}..." |
| 68 | + gh run watch ${{ env.run_id }} \ |
| 69 | + --repo devopsabcs-engineering/${{ matrix.repo }} \ |
| 70 | + --exit-status |
| 71 | + echo "${{ matrix.repo }} scan completed successfully" |
0 commit comments