-
Notifications
You must be signed in to change notification settings - Fork 21
136 lines (123 loc) · 4.62 KB
/
test.yml
File metadata and controls
136 lines (123 loc) · 4.62 KB
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
126
127
128
129
130
131
132
133
134
135
136
name: Test
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
workflow_dispatch:
permissions:
contents: write
issues: write
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false # Allow previous workflows’ clean-up steps to complete
env:
TESTING_REPOSITORY: github/accessibility-scanner-testing
jobs:
test:
name: Test
runs-on: ubuntu-latest
# Run if triggered manually, or for a non-draft PR
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
strategy:
matrix:
site: ["sites/site-with-errors"]
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Ruby
uses: ruby/setup-ruby@09a7688d3b55cf0e976497ff046b70949eeaccfd
with:
ruby-version: "3.4"
bundler-cache: true
working-directory: ${{ matrix.site }}
- name: Build Jekyll site (${{ matrix.site }})
shell: bash
working-directory: ${{ matrix.site }}
env:
JEKYLL_ENV: production
run: bundle exec jekyll build
- name: Start Puma (${{ matrix.site }})
shell: bash
working-directory: ${{ matrix.site }}
env:
TEST_USERNAME: ${{ secrets.TEST_USERNAME }}
TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
run: |
set -euo pipefail
bundle exec puma -b tcp://127.0.0.1:4000 &
echo "Starting Puma on port 4000"
curl -fsS --retry 25 --retry-delay 1 --retry-all-errors -u "${TEST_USERNAME}:${TEST_PASSWORD}" "http://127.0.0.1:4000/" > /dev/null
echo "Puma has started"
- name: Generate cache key
id: cache_key
shell: bash
run: |
echo "cache_key=$(printf 'cached_results-%s-%s.json' "${{ matrix.site }}" "${{ github.ref_name }}" | tr -cs 'A-Za-z0-9._-' '_')" >> $GITHUB_OUTPUT
- name: Scan site (${{ matrix.site }})
uses: ./
with:
urls: |
http://127.0.0.1:4000/
http://127.0.0.1:4000/jekyll/update/2025/07/30/welcome-to-jekyll.html
http://127.0.0.1:4000/about/
http://127.0.0.1:4000/404.html
login_url: http://127.0.0.1:4000/
username: ${{ secrets.TEST_USERNAME }}
password: ${{ secrets.TEST_PASSWORD }}
repository: ${{ env.TESTING_REPOSITORY }}
token: ${{ secrets.GH_TOKEN }}
cache_key: ${{ steps.cache_key.outputs.cache_key }}
- name: Retrieve cached results
uses: ./.github/actions/gh-cache/restore
with:
path: ${{ steps.cache_key.outputs.cache_key }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Validate scan results (${{ matrix.site }})
run: |
npm ci
npm run test
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
CACHE_PATH: ${{ steps.cache_key.outputs.cache_key }}
- name: Clean up issues and pull requests
if: ${{ always() }}
shell: bash
run: |
set -euo pipefail
if [[ ! -f "${{ steps.cache_key.outputs.cache_key }}" ]]; then
echo "Skipping 'Clean up issues and pull requests' (no cached results)."
exit 0
fi
jq -r '
(if type=="string" then fromjson else . end)
| .[] | .issue.url, .pullRequest.url
| select(. != null)
' "${{ steps.cache_key.outputs.cache_key }}" \
| while read -r URL; do
if [[ "$URL" == *"/pull/"* ]]; then
echo "Closing pull request: $URL"
gh pr close "$URL" || echo "Failed to close pull request: $URL"
branch="$(gh pr view "$URL" --json headRefName -q .headRefName || true)"
if [[ -n "$branch" ]]; then
echo "Deleting branch: $branch"
gh api -X DELETE "repos/${{ env.TESTING_REPOSITORY }}/git/refs/heads/$branch" || echo "Failed to delete branch: $branch"
fi
elif [[ "$URL" == *"/issues/"* ]]; then
echo "Closing issue: $URL"
gh issue close "$URL" || echo "Failed to close issue: $URL"
else
echo "Skipping unrecognized url: $URL"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Clean up cached results
if: ${{ always() }}
uses: ./.github/actions/gh-cache/delete
with:
path: ${{ steps.cache_key.outputs.cache_key }}
token: ${{ secrets.GITHUB_TOKEN }}