-
Notifications
You must be signed in to change notification settings - Fork 19
112 lines (96 loc) · 4.29 KB
/
Copy pathsitemap-parity.yml
File metadata and controls
112 lines (96 loc) · 4.29 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
name: Sitemap Parity
# Ensures every URL currently listed in the production sitemap is still
# reachable on the deployment that will be produced by this branch. Runs on:
# - pull_request -> waits for the Netlify deploy-preview, then checks
# - push to main -> waits for the Netlify production deploy, then checks
#
# In both cases the job blocks until Netlify posts a successful commit status
# for the exact commit under test (Netlify integrates via the GitHub Commit
# Status API, not the Deployments API), then runs the check against the URL
# from that status. If any prod URL is unreachable on the new deploy, the
# check fails and blocks the merge.
on:
pull_request:
branches: ['main']
permissions:
contents: read
concurrency:
group: sitemap-parity-${{ github.event.pull_request.head.sha || github.sha }}
cancel-in-progress: true
jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# For PRs, check out the PR head commit so the script matches what
# Netlify actually deployed. For pushes, this is the pushed commit.
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Wait for Netlify deployment
id: wait
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
# Total wait budget in seconds (default 15 min) and poll interval.
WAIT_TIMEOUT: '900'
WAIT_INTERVAL: '15'
run: |
set -euo pipefail
echo "Waiting for a Netlify commit status on commit $SHA ..."
# Netlify reports build status via the GitHub Commit Status API
# (context typically `netlify/<site-name>/deploy-preview`) rather
# than the Deployments API, so we poll that endpoint.
deadline=$(( $(date +%s) + WAIT_TIMEOUT ))
preview_url=""
while [ "$(date +%s)" -lt "$deadline" ]; do
status_json=$(gh api "repos/${{ github.repository }}/commits/$SHA/status")
# Grab the first status whose context looks like a Netlify one.
# `map(select(...)) | .[0]` normalises the jq stream into a single
# (possibly null) object so downstream extraction is unambiguous.
netlify_state=$(printf '%s' "$status_json" | jq -r '
.statuses
| map(select(.context | ascii_downcase | startswith("netlify/")))
| .[0].state // ""')
netlify_target=$(printf '%s' "$status_json" | jq -r '
.statuses
| map(select(.context | ascii_downcase | startswith("netlify/")))
| .[0].target_url // ""')
if [ "$netlify_state" = "success" ]; then
if [ -z "$netlify_target" ] || [ "$netlify_target" = "null" ]; then
echo "::error::Netlify status is success but has no target_url."
exit 1
fi
preview_url="$netlify_target"
echo "Found successful Netlify deployment -> $preview_url"
break
elif [ "$netlify_state" = "failure" ] || [ "$netlify_state" = "error" ]; then
echo "::error::Netlify build reported state=$netlify_state for commit $SHA."
exit 1
elif [ -n "$netlify_state" ]; then
echo "Netlify status is currently: $netlify_state. Waiting ${WAIT_INTERVAL}s ..."
else
echo "No Netlify status posted yet. Waiting ${WAIT_INTERVAL}s ..."
fi
sleep "$WAIT_INTERVAL"
done
if [ -z "$preview_url" ]; then
echo "::error::Timed out after ${WAIT_TIMEOUT}s waiting for a Netlify deployment on $SHA."
exit 1
fi
echo "preview_url=$preview_url" >> "$GITHUB_OUTPUT"
- name: Check sitemap parity
env:
PREVIEW_URL: ${{ steps.wait.outputs.preview_url }}
run: |
echo "Preview URL: $PREVIEW_URL"
node scripts/check-sitemap-parity.mjs \
--prod-base=https://open-elements.com \
--preview-base="$PREVIEW_URL" \
--concurrency=4 \
--retries=4