Repository navigation
272 lines (247 loc) · 10.7 KB
/
Copy pathdeploy.yml
File metadata and controls
272 lines (247 loc) · 10.7 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
inputs:
pages-base:
description: >-
Astro base path for project-level GitHub Pages (e.g. /purview-dev/).
Leave empty for a custom domain or organisation Pages site.
required: false
type: string
default: ""
# Called by upstream-refresh.yml when a catalogue project's repository or
# packages changed since the deployed build (ADR 0014). That workflow also
# owns the `purview-site-rebuild` repository dispatch, so a release elsewhere
# waits for its packages to publish before this runs.
workflow_call:
inputs:
pages-base:
required: false
type: string
default: ""
schedule:
# Weekly refresh of release information from GitHub and NuGet (download
# counts and other figures the nightly upstream check does not compare).
- cron: "17 4 * * 1"
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
# actions/checkout v7.0.1
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
# Full history so sitemap `lastmod` can use each source file's real
# last-commit date (see src/src/lib/discovery/last-modified.ts).
fetch-depth: 0
- name: Install Bun
# oven-sh/setup-bun v2.2.0
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
with:
bun-version: 1.4.4
- name: Install Just
# taiki-e/install-action v2.87.13
uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f
with:
tool: just@1.59.0
# The repository is a Bun workspace: the lockfile and root `package.json`
# live here, the Astro site package lives in `src/`, and every `bun run`
# / `just` recipe delegates to `src/` (see `package.json` scripts).
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Capture the currently deployed discovery manifest
# Captured before the new site is deployed so the post-deploy IndexNow
# step can diff "what changed". Published as /_discovery/previous.json
# (public, non-sensitive) so no cross-job artifact is needed.
env:
SITE_URL: ${{ vars.SITE_URL }}
run: |
ORIGIN="${SITE_URL:-https://purview.dev}"
mkdir -p .discovery-capture
if curl -fsSL "$ORIGIN/discover.json" -o .discovery-capture/previous.json; then
echo "Captured the previous discovery manifest."
else
echo '{"schemaVersion":0,"resources":[]}' > .discovery-capture/previous.json
echo "No previous discovery manifest (first deployment)."
fi
- name: Resolve deployment base and site URL
# Resolved before validation, not after it: `just validate` is also what
# builds the site, so the base and the site URL have to be in the
# environment for that build to be the artifact that ships.
id: pages-config
env:
REPO_NAME: ${{ github.event.repository.name }}
OWNER: ${{ github.repository_owner }}
run: |
BASE="${{ vars.PAGES_BASE }}"
if [ -n "${{ inputs.pages-base }}" ]; then
BASE="${{ inputs.pages-base }}"
fi
if [ -z "$BASE" ]; then
if [ "$REPO_NAME" = "$OWNER.github.io" ]; then
BASE="/"
else
BASE="/$REPO_NAME"
fi
fi
SITE="${{ vars.SITE_URL }}"
if [ -z "$SITE" ]; then
SITE="https://$OWNER.github.io"
fi
echo "pages-base=$BASE" >> "$GITHUB_OUTPUT"
echo "site-url=$SITE" >> "$GITHUB_OUTPUT"
- name: Run validation
# One pass: `just validate` runs the live data sync (a fresh checkout has
# no cache or docs mirror, so pass a token to avoid unauthenticated rate
# limits), builds, and runs every check. The deployment base and site URL
# are in the environment, so the build it produces is the one that is
# uploaded and the link, SEO and dist checks see the URLs the deployment
# actually serves. This used to re-sync all data and rebuild the site
# afterwards, with nothing in between to invalidate the first result.
#
# The build never receives the IndexNow key: the key verification file is
# written from the secret by a separate step below (see docs/discovery.md).
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PAGES_BASE: ${{ steps.pages-config.outputs.pages-base }}
SITE_URL: ${{ steps.pages-config.outputs.site-url }}
run: just validate
- name: Write the IndexNow key verification file
# The key is supplied only by the INDEXNOW_KEY repository secret and is
# never part of the build or its logs. This writes /<key>.txt, the file
# IndexNow fetches to prove ownership of the domain.
env:
INDEXNOW_KEY: ${{ secrets.INDEXNOW_KEY }}
run: |
if [ -z "${INDEXNOW_KEY}" ]; then
echo "::warning::INDEXNOW_KEY is not configured; skipping the key verification file."
exit 0
fi
bun run discovery:key
- name: Validate the discovery artifacts, including the key file
# The build pipeline cannot require the key verification file (the build
# never sees the key); this is the one place it is guaranteed to exist.
# When INDEXNOW_KEY is unset the requirement is a no-op.
env:
INDEXNOW_KEY: ${{ secrets.INDEXNOW_KEY }}
run: bun run discovery:validate --require-indexnow-key
- name: Publish the previous discovery manifest for change detection
run: |
mkdir -p src/dist/_discovery
cp .discovery-capture/previous.json src/dist/_discovery/previous.json
- name: Record the upstream state this build was made from
# Published as /_discovery/upstream.json. The nightly upstream check
# compares the catalogue repositories and packages with it and skips the
# rebuild when nothing moved (ADR 0014).
run: bun run upstream:state --write dist/_discovery/upstream.json
- name: Configure Pages
# actions/configure-pages v6.0.0
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d
- name: Upload Pages artifact
# actions/upload-pages-artifact v5.0.0
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9
with:
# Build output is written into the `src/` package (see package.json).
path: ./src/dist
# The RFC 9727 API catalog lives at `.well-known/api-catalog`, and this
# action drops dot-files and dot-directories by default — so the file is
# built and validated but never reaches GitHub Pages, and the edge Worker
# then faithfully propagates the origin's 404. `true` ships hidden files
# (it still excludes `.git`/`.github`).
include-hidden-files: true
deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
# actions/deploy-pages v5.0.1
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346
worker:
# The Markdown-for-Agents / API-catalog Worker (`worker/`, ADRs 0016-0017).
# It fronts purview.dev at the Cloudflare edge, so it is deployed as part of
# this deployment — after the site, so the pages and files it serves are live
# first. It is skipped (never fails) when the Cloudflare credentials are not
# configured, so a fork or a contributor without them is never blocked.
needs: deploy
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
# actions/checkout v7.0.1
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- name: Install Bun
# oven-sh/setup-bun v2.2.0
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
with:
bun-version: 1.4.4
- name: Check for Cloudflare credentials
id: creds
env:
TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
ACCOUNT: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: |
if [ -n "$TOKEN" ] && [ -n "$ACCOUNT" ]; then
echo "ready=true" >> "$GITHUB_OUTPUT"
else
echo "ready=false" >> "$GITHUB_OUTPUT"
echo "::notice::CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID are not set; skipping the Worker deploy."
fi
- name: Test the Worker
if: steps.creds.outputs.ready == 'true'
run: bun test worker/tests
- name: Deploy the Worker
if: steps.creds.outputs.ready == 'true'
working-directory: worker
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# Pinned so the deploy is reproducible; `wrangler deploy` bundles the
# TypeScript entry point, so the Worker needs no build step.
run: bunx wrangler@4.171.0 deploy
indexnow:
# Runs only after a successful production deployment. A failed deploy must
# never tell search engines that new URLs are live. The site deployment
# stands on its own; a notification failure is reported here, not by
# rolling the deployment back.
needs: deploy
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout
# actions/checkout v7.0.1
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- name: Install Bun
# oven-sh/setup-bun v2.2.0
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6
with:
bun-version: 1.4.4
- name: Notify IndexNow about changed URLs
# Submits only URLs added or modified since the previous deployment.
# `discovery:indexnow` has no external dependencies, so no `bun install`
# is needed. The IndexNow key is never printed.
env:
SITE_URL: ${{ vars.SITE_URL }}
INDEXNOW_KEY: ${{ secrets.INDEXNOW_KEY }}
run: |
if [ -z "${INDEXNOW_KEY}" ]; then
echo "::warning::INDEXNOW_KEY is not configured; skipping the IndexNow notification."
exit 0
fi
ORIGIN="${SITE_URL:-https://purview.dev}"
bun run discovery:indexnow \
--current "$ORIGIN/discover.json" \
--previous "$ORIGIN/_discovery/previous.json"