-
Notifications
You must be signed in to change notification settings - Fork 6
125 lines (109 loc) · 4.59 KB
/
web-crawler-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Build Run and Test Website Crawl
on:
workflow_dispatch:
inputs:
A11Y_ENGINE_BRANCH:
description: 'Purple A11y Branch (master, other)'
required: true
default: 'master'
A11Y_SCAN_URL:
description: 'Website URL'
required: true
default: 'https://'
A11Y_SCANNER:
description: 'Scanner (website, sitemap)'
required: true
default: 'website'
A11Y_SCAN_MAX_NUM_PAGES:
description: 'Maximum Number of Pages to Scan'
required: true
default: '10'
A11Y_SCAN_MAX_CONCURRENCY:
description: 'Maximum Number of Concurrent Page Scans'
required: true
default: '10'
A11Y_SCAN_SCREENSHOTS:
description: 'Include screenshots (screenshots, none)'
required: true
default: 'screenshots'
A11Y_SCAN_FOLLOW_ROBOTS:
description: 'Crawler adhere to robots.txt (yes, no)'
required: true
default: 'no'
A11Y_SCAN_STRATEGY:
description: 'Crawler adhere to pages matching exact hostname or same parent domain (same-hostname, same-domain)'
required: true
default: 'same-domain'
USERNAME:
description: "Your name (for telemetry purposes)"
required: false
EMAIL:
description: "Email address (for telemetry purposes)"
required: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get Public IP Address
run:
curl https://ipinfo.io
- name: Check if email is valid or empty
run: |
email="${{ inputs.EMAIL }}"
echo "Email provided: $email"
valid_email_regex='^.+@.+\..+$'
echo "Validating with regex: $valid_email_regex"
status="$(if [ -z "$email" ]; then echo "Empty"; elif [[ $email =~ $valid_email_regex ]]; then echo "Valid"; else echo "Invalid"; fi)"
if [[ "$status" == "Invalid" ]]; then
echo "Invalid email provided. Workflow failed."
exit 1
fi
# Proceed with steps if EMAIL is valid or empty
- name: Use provided name and email or defaults
run: |
if [[ -z "${{ inputs.EMAIL }}" ]]; then
final_email="${{ github.actor }}@users.noreply.github.com"
else
final_email="${{ inputs.EMAIL }}"
fi
username="${{ inputs.USERNAME || github.actor }}"
echo "final_email=$final_email" >> $GITHUB_ENV
echo "username=$username" >> $GITHUB_ENV
# Use $final_email and $username in subsequent steps
- name: Checkout code
uses: actions/checkout@master
with:
repository: "GovTechSG/purple-a11y"
ref: "${{ github.event.inputs.A11Y_ENGINE_BRANCH }}"
- name: Build and run Docker container
run: |
# Build your Docker image (replace 'purple-a11y' and 'Dockerfile' with your image name and Dockerfile path)
docker build -t purple-a11y .
# Run the Docker container (adjust any options as needed)
docker run -dit --name purple-a11y-container purple-a11y
# Ensure the Docker container is running before running the next step
continue-on-error: true
- name: Start accessibility scan in Docker container
run: |
# Execute a webisite crawl
docker exec -e PURPLE_A11Y_VERBOSE=true purple-a11y-container npm run cli -- -c "${{ github.event.inputs.A11Y_SCANNER }}" -u "${{ github.event.inputs.A11Y_SCAN_URL }}" -p "${{ github.event.inputs.A11Y_SCAN_MAX_NUM_PAGES }}" -t "${{ github.event.inputs.A11Y_SCAN_MAX_CONCURRENCY }}" -a "${{ github.event.inputs.A11Y_SCAN_SCREENSHOTS }}" -r "${{ github.event.inputs.A11Y_SCAN_FOLLOW_ROBOTS }}" -s "${{ github.event.inputs.A11Y_SCAN_STRATEGY}}" -k "${{ env.username }}:${{ env.final_email }}" -b chromium || true
- name: Print errors
run: |
docker exec purple-a11y-container cat errors.txt || true
- name: Print logs
run: |
docker exec purple-a11y-container cat logs/*/*.txt || true
- name: Copy Results from Docker Container
run: docker cp purple-a11y-container:/app/results ./results
- name: Zip Results
run: zip -r results.zip ./results
- name: Upload Zip File
uses: actions/upload-artifact@v2
with:
name: results
path: results.zip
- name: Cleanup Docker container
run: |
# Stop and remove the Docker container
docker stop purple-a11y-container
docker rm purple-a11y-container