Skip to content

Commit 2b364ac

Browse files
Merge pull request #27 from devopsabcs-engineering/feature/2112-scan-all-dispatch
feat(workflows): dispatch scan-all to sibling repos for per-repo Code Scanning alerts Fixes AB#2112
2 parents ce64425 + 1f5c97d commit 2b364ac

1 file changed

Lines changed: 45 additions & 58 deletions

File tree

.github/workflows/scan-all.yml

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 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
34

45
name: Scan All Demo Apps
56

@@ -8,77 +9,63 @@ on:
89

910
permissions:
1011
contents: read
11-
security-events: write
12-
13-
env:
14-
SCANNER_BASE_URL: https://a11y-scan-demo-app.azurewebsites.net
1512

1613
jobs:
1714
scan:
18-
name: Scan ${{ matrix.siteName }}
15+
name: Scan ${{ matrix.repo }}
1916
runs-on: ubuntu-latest
20-
timeout-minutes: 5
17+
timeout-minutes: 15
2118
strategy:
2219
fail-fast: false
2320
max-parallel: 5
2421
matrix:
2522
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
3628
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 }}
4132
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 }}"
5140
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"
5655
exit 0
5756
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
6459
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 }}"
6961
exit 1
7062
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

Comments
 (0)