Repository navigation
241 lines (217 loc) · 10.4 KB
/
Copy pathrefresh-docs.yml
File metadata and controls
241 lines (217 loc) · 10.4 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
name: Refresh docs
# Triggered when Iterable/iterable-docs publishes a change to an SDK doc
# path. The docs repo dispatches `iterable-docs-changed` (optionally with a
# `client_payload.ref` = the docs commit); this workflow resolves that ref
# (or the docs default-branch head on a manual run), rewrites every
# configured platform's `reference/` from the docs at that commit, bumps the
# pinned `source.ref` only for platforms whose corpus changed, validates the
# result, and commits straight to `main`. There is no LLM step — the corpus is
# the docs reshaped.
#
# Refreshes are NOT pre-reviewed: the validate step below is the only gate, and
# a human audits the commit after the fact (see REVIEW.md).
#
# `workflow_dispatch` is kept as a manual fallback for re-running a
# refresh outside of a docs-side trigger (e.g. when validating a config
# change on this repo).
on:
repository_dispatch:
types: [iterable-docs-changed]
workflow_dispatch:
concurrency:
group: refresh-docs
cancel-in-progress: true
permissions:
contents: write
issues: write
jobs:
refresh:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Full history: the commit step rebases onto main if it moved mid-run,
# and rebasing a shallow clone is unreliable.
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: pipeline/pnpm-lock.yaml
- name: Install pipeline deps
working-directory: pipeline
run: pnpm install --frozen-lockfile
- name: Resolve source ref
id: ref
env:
# iterable-docs is a PRIVATE repo, so the built-in GITHUB_TOKEN (scoped
# to this repo only) 404s on it. DOCS_READ_TOKEN is a fine-grained PAT
# with Contents+Metadata read on Iterable/iterable-docs.
GH_TOKEN: ${{ secrets.DOCS_READ_TOKEN }}
# The docs commit that triggered the dispatch, if any. Empty on a
# manual workflow_dispatch → we resolve the docs default branch head.
PAYLOAD_REF: ${{ github.event.client_payload.ref }}
run: |
set -euo pipefail
docs_repo="Iterable/iterable-docs"
# Fine-grained PATs expire, and nothing here monitors that. Probing
# the docs repo first turns a silent mid-run "Bad credentials" into an
# error that names the secret to rotate.
if [[ -z "${GH_TOKEN:-}" ]]; then
echo "::error::DOCS_READ_TOKEN is not set on this repository. Add a fine-grained PAT with Contents+Metadata read on ${docs_repo}."
exit 1
fi
if ! default_branch=$(gh api "repos/${docs_repo}" --jq '.default_branch' 2>&1); then
echo "::error::DOCS_READ_TOKEN cannot read ${docs_repo}: ${default_branch}"
echo "401 Bad credentials → the token expired or was revoked; rotate the DOCS_READ_TOKEN secret."
echo "404 Not Found → the token lost Contents read on ${docs_repo}; re-grant it."
exit 1
fi
req="${PAYLOAD_REF:-$default_branch}"
# Resolve whatever we have (branch name or sha) to a full commit sha,
# so the pin we write back is immutable and reproducible.
sha=$(gh api "repos/${docs_repo}/commits/${req}" --jq '.sha')
echo "sha=${sha}" >> "$GITHUB_OUTPUT"
echo "label=master @ $(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
echo "Resolved ${req} → ${sha}"
# Refreshes commit straight to main, so only ever publish docs that
# are actually published. A dispatch can carry the head of an open
# docs PR (that is how the sender's test label works) — refresh and
# validate that, but do not let unmerged docs reach developers.
status=$(gh api "repos/${docs_repo}/compare/${default_branch}...${sha}" --jq '.status')
if [[ "$status" == "identical" || "$status" == "behind" ]]; then
echo "publish=true" >> "$GITHUB_OUTPUT"
else
echo "publish=false" >> "$GITHUB_OUTPUT"
echo "::warning::${sha} is not on ${default_branch} (compare says '${status}'), so this is a dry run: the corpus will be rebuilt and validated but not committed."
fi
- name: Refresh reference corpora (reads private iterable-docs via gh api)
working-directory: pipeline
env:
GH_TOKEN: ${{ secrets.DOCS_READ_TOKEN }}
SOURCE_REF: ${{ steps.ref.outputs.sha }}
run: pnpm refresh:docs
- name: Detect changes
id: changes
working-directory: pipeline
run: pnpm detect:corpus-changes
- name: Bump pinned source ref
if: steps.changes.outputs.changed == 'true'
working-directory: pipeline
env:
SHA: ${{ steps.ref.outputs.sha }}
LABEL: ${{ steps.ref.outputs.label }}
PLATFORMS: ${{ steps.changes.outputs.platforms }}
run: |
set -euo pipefail
IFS=',' read -ra plats <<< "$PLATFORMS"
for p in "${plats[@]}"; do
pnpm set:source-ref -- "$p" "$SHA" "$LABEL"
done
# Hosts skip an update when the manifest version matches what is already
# installed, so a refresh that does not move this string rebuilds the
# corpus on main and reaches nobody. Gated on publish: a dry run must not
# consume a version number.
- name: Bump plugin version
id: version
if: steps.changes.outputs.changed == 'true' && steps.ref.outputs.publish == 'true'
working-directory: pipeline
run: |
set -euo pipefail
version=$(pnpm --silent set:version | sed -n 's/^version=//p')
if [[ -z "$version" ]]; then
echo "::error::set:version did not report a version."
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "Plugin version is now ${version}."
# A push made with GITHUB_TOKEN does not trigger other workflows, so
# validate.yml will not run on the refresh commit. This is the only
# validation the corpus gets — it must stay blocking. It runs after the
# two bumps above so that what gets validated is what gets committed.
- name: Validate refreshed corpora
if: steps.changes.outputs.changed == 'true'
working-directory: pipeline
run: pnpm check:all
# Lands straight on main — no PR. The gate above is therefore the only
# thing between Iterable's docs and what the skills serve, so keep it
# ahead of this step. Review is post-hoc; see REVIEW.md.
- name: Commit to main
if: steps.changes.outputs.changed == 'true' && steps.ref.outputs.publish == 'true'
env:
SHA: ${{ steps.ref.outputs.sha }}
LABEL: ${{ steps.ref.outputs.label }}
PLATFORMS: ${{ steps.changes.outputs.platforms }}
SLUGS: ${{ steps.changes.outputs.slugs }}
VERSION: ${{ steps.version.outputs.version }}
TRIGGER: ${{ github.event_name }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git diff --cached --stat
# No PR body to carry provenance any more, so the commit message is
# the whole audit trail.
{
printf 'docs refresh: %s (v%s)\n\n' "$PLATFORMS" "$VERSION"
printf 'Deterministic rebuild of the reference corpora from the\n'
printf 'published Iterable docs. No LLM step: the corpus is the\n'
printf 'docs reshaped.\n\n'
printf 'Platforms: %s\n' "$PLATFORMS"
printf 'Slugs: %s\n' "$SLUGS"
printf 'Plugin version: %s\n' "$VERSION"
printf 'Docs commit: %s (%s)\n' "$SHA" "$LABEL"
printf 'Trigger: %s\n' "$TRIGGER"
printf 'Run: %s\n' "$RUN_URL"
} > "${RUNNER_TEMP}/refresh-msg"
git commit -q -F "${RUNNER_TEMP}/refresh-msg"
# main can move while a refresh runs; rebase onto it rather than
# clobbering someone else's commit with a force push.
for _ in 1 2 3; do
if git push origin HEAD:main; then
echo "Pushed $(git rev-parse --short HEAD) to main."
exit 0
fi
git fetch origin main
git rebase origin/main
done
echo "::error::Could not push the refresh to main after 3 attempts."
exit 1
# Refreshes are triggered by the docs repo, not by anyone watching this
# one: DOCS_READ_TOKEN expired around 2026-08-29 and the failure went
# unnoticed for two weeks. File an issue so the next one surfaces.
- name: Report failure
if: failure()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
TRIGGER: ${{ github.event_name }}
run: |
set -euo pipefail
gh label create docs-refresh-failed --color B60205 \
--description "A Refresh docs run failed" >/dev/null 2>&1 || true
existing=$(gh issue list --label docs-refresh-failed --state open \
--limit 1 --json number --jq '.[0].number // empty')
if [[ -n "$existing" ]]; then
gh issue comment "$existing" \
--body "Failed again (\`${TRIGGER}\`): ${RUN_URL}"
else
gh issue create --title "Docs refresh is failing" \
--label docs-refresh-failed \
--body "$(printf '%s\n' \
"The \`Refresh docs\` workflow failed, so the bundled \`reference/\` corpora are no longer tracking Iterable's published docs." \
"" \
"Failed run (\`${TRIGGER}\`): ${RUN_URL}" \
"" \
"First thing to check: \`DOCS_READ_TOKEN\`. It is a fine-grained PAT on a private repo, it expires, and nothing renews it. A 401 in the *Resolve source ref* step means rotate it." \
"" \
"This issue is reused for later failures — close it once a refresh succeeds.")"
fi