-
-
Notifications
You must be signed in to change notification settings - Fork 438
176 lines (147 loc) · 6.55 KB
/
docs-backfill.yml
File metadata and controls
176 lines (147 loc) · 6.55 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
name: Backfill versioned docs
on:
workflow_dispatch:
inputs:
count:
description: "Number of recent stable releases to backfill"
required: false
default: "10"
type: string
dry_run:
description: "Dry run (list versions to backfill without building)"
required: false
default: false
type: boolean
permissions:
contents: write
jobs:
backfill:
name: Backfill versioned docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: unstable
fetch-depth: 0
fetch-tags: true
- name: Determine versions to backfill
id: versions
run: |
COUNT=${{ github.event.inputs.count || '10' }}
# Get the last N stable release tags (exclude rc pre-releases)
STABLE_TAGS=$(git tag -l 'v*' --sort=-v:refname | grep -vF -- '-rc.' | head -n "$COUNT")
echo "Found stable tags:"
echo "$STABLE_TAGS"
# Fetch existing versions from docs-versions branch
EXISTING=""
git fetch origin docs-versions 2>/dev/null || true
if git rev-parse origin/docs-versions >/dev/null 2>&1; then
git worktree add /tmp/docs-versions origin/docs-versions
if [ -f /tmp/docs-versions/versions.json ]; then
EXISTING=$(cat /tmp/docs-versions/versions.json | jq -r '.[]')
echo "Existing versions: $EXISTING"
fi
git worktree remove /tmp/docs-versions
fi
# Find missing versions
MISSING=""
for TAG in $STABLE_TAGS; do
VERSION="${TAG#v}"
if echo "$EXISTING" | grep -qx "$VERSION"; then
echo "✓ $VERSION already exists"
else
echo "✗ $VERSION missing — will backfill"
MISSING="$MISSING $TAG"
fi
done
MISSING=$(echo "$MISSING" | xargs)
echo "missing=$MISSING" >> $GITHUB_OUTPUT
if [ -z "$MISSING" ]; then
echo "All $COUNT recent stable versions are already cached!"
else
echo "Versions to backfill: $MISSING"
fi
- name: Install pnpm
if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true'
uses: pnpm/action-setup@c5ba7f7862a0f64c1b1a05fbac13e0b8e86ba08c # v4
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true'
with:
node-version: 24
check-latest: true
cache: pnpm
- name: Backfill missing versions
if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true'
run: |
MISSING="${{ steps.versions.outputs.missing }}"
# Fetch existing versioned docs
git fetch origin docs-versions 2>/dev/null || true
VERSIONED_DIR=$(mktemp -d)
if git rev-parse origin/docs-versions >/dev/null 2>&1; then
git worktree add /tmp/docs-versions origin/docs-versions
cp -r /tmp/docs-versions/versioned_docs "$VERSIONED_DIR/" 2>/dev/null || true
cp -r /tmp/docs-versions/versioned_sidebars "$VERSIONED_DIR/" 2>/dev/null || true
cp /tmp/docs-versions/versions.json "$VERSIONED_DIR/" 2>/dev/null || true
git worktree remove /tmp/docs-versions
fi
# Process each missing version (oldest first for correct ordering)
REVERSED=$(echo "$MISSING" | tr ' ' '\n' | tac | tr '\n' ' ')
for TAG in $REVERSED; do
VERSION="${TAG#v}"
echo ""
echo "========================================="
echo "Backfilling $VERSION (from tag $TAG)"
echo "========================================="
# Checkout the tag
git checkout "$TAG"
# Install and build at that tag
pnpm install --frozen-lockfile
pnpm build
# Generate docs
pnpm docs:build
# Restore existing versioned content into docs/
cp -r "$VERSIONED_DIR/versioned_docs" docs/ 2>/dev/null || true
cp -r "$VERSIONED_DIR/versioned_sidebars" docs/ 2>/dev/null || true
cp "$VERSIONED_DIR/versions.json" docs/ 2>/dev/null || true
# Install docs deps and create version snapshot
cd docs
pnpm install
npx docusaurus docs:version "$VERSION"
cd ..
# Save updated versioned content
cp -r docs/versioned_docs "$VERSIONED_DIR/" 2>/dev/null || true
cp -r docs/versioned_sidebars "$VERSIONED_DIR/" 2>/dev/null || true
cp docs/versions.json "$VERSIONED_DIR/" 2>/dev/null || true
echo "✓ $VERSION backfilled"
done
echo ""
echo "Final versions.json:"
cat "$VERSIONED_DIR/versions.json"
# Save for push step
echo "VERSIONED_DIR=$VERSIONED_DIR" >> $GITHUB_ENV
- name: Push backfilled docs to docs-versions branch
if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true'
run: |
WORK=$(mktemp -d)
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git ls-remote --heads origin docs-versions | grep -q docs-versions; then
git clone --branch docs-versions --single-branch --depth 1 \
"https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" "$WORK"
else
git init "$WORK"
cd "$WORK"
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
git checkout --orphan docs-versions
cd -
fi
cd "$WORK"
rm -rf versioned_docs versioned_sidebars versions.json
cp -r "$VERSIONED_DIR/versioned_docs" . 2>/dev/null || true
cp -r "$VERSIONED_DIR/versioned_sidebars" . 2>/dev/null || true
cp "$VERSIONED_DIR/versions.json" . 2>/dev/null || true
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add versioned_docs versioned_sidebars versions.json
git commit -m "docs: backfill versioned docs for ${{ steps.versions.outputs.missing }}" || echo "Nothing to commit"
git push origin docs-versions