|
| 1 | +name: Backfill versioned docs |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + count: |
| 7 | + description: "Number of recent stable releases to backfill" |
| 8 | + required: false |
| 9 | + default: "10" |
| 10 | + type: string |
| 11 | + dry_run: |
| 12 | + description: "Dry run (list versions to backfill without building)" |
| 13 | + required: false |
| 14 | + default: false |
| 15 | + type: boolean |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + backfill: |
| 22 | + name: Backfill versioned docs |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + ref: unstable |
| 28 | + fetch-depth: 0 |
| 29 | + fetch-tags: true |
| 30 | + |
| 31 | + - name: Determine versions to backfill |
| 32 | + id: versions |
| 33 | + run: | |
| 34 | + COUNT=${{ github.event.inputs.count || '10' }} |
| 35 | +
|
| 36 | + # Get the last N stable release tags (exclude rc pre-releases) |
| 37 | + STABLE_TAGS=$(git tag -l 'v*' --sort=-v:refname | grep -vF -- '-rc.' | head -n "$COUNT") |
| 38 | + echo "Found stable tags:" |
| 39 | + echo "$STABLE_TAGS" |
| 40 | +
|
| 41 | + # Fetch existing versions from docs-versions branch |
| 42 | + EXISTING="" |
| 43 | + git fetch origin docs-versions 2>/dev/null || true |
| 44 | + if git rev-parse origin/docs-versions >/dev/null 2>&1; then |
| 45 | + git worktree add /tmp/docs-versions origin/docs-versions |
| 46 | + if [ -f /tmp/docs-versions/versions.json ]; then |
| 47 | + EXISTING=$(cat /tmp/docs-versions/versions.json | jq -r '.[]') |
| 48 | + echo "Existing versions: $EXISTING" |
| 49 | + fi |
| 50 | + git worktree remove /tmp/docs-versions |
| 51 | + fi |
| 52 | +
|
| 53 | + # Find missing versions |
| 54 | + MISSING="" |
| 55 | + for TAG in $STABLE_TAGS; do |
| 56 | + VERSION="${TAG#v}" |
| 57 | + if echo "$EXISTING" | grep -qx "$VERSION"; then |
| 58 | + echo "✓ $VERSION already exists" |
| 59 | + else |
| 60 | + echo "✗ $VERSION missing — will backfill" |
| 61 | + MISSING="$MISSING $TAG" |
| 62 | + fi |
| 63 | + done |
| 64 | +
|
| 65 | + MISSING=$(echo "$MISSING" | xargs) |
| 66 | + echo "missing=$MISSING" >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + if [ -z "$MISSING" ]; then |
| 69 | + echo "All $COUNT recent stable versions are already cached!" |
| 70 | + else |
| 71 | + echo "Versions to backfill: $MISSING" |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Install pnpm |
| 75 | + if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true' |
| 76 | + uses: pnpm/action-setup@v4 |
| 77 | + |
| 78 | + - uses: actions/setup-node@v6 |
| 79 | + if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true' |
| 80 | + with: |
| 81 | + node-version: 24 |
| 82 | + check-latest: true |
| 83 | + cache: pnpm |
| 84 | + |
| 85 | + - name: Backfill missing versions |
| 86 | + if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true' |
| 87 | + run: | |
| 88 | + MISSING="${{ steps.versions.outputs.missing }}" |
| 89 | +
|
| 90 | + # Fetch existing versioned docs |
| 91 | + git fetch origin docs-versions 2>/dev/null || true |
| 92 | + VERSIONED_DIR=$(mktemp -d) |
| 93 | +
|
| 94 | + if git rev-parse origin/docs-versions >/dev/null 2>&1; then |
| 95 | + git worktree add /tmp/docs-versions origin/docs-versions |
| 96 | + cp -r /tmp/docs-versions/versioned_docs "$VERSIONED_DIR/" 2>/dev/null || true |
| 97 | + cp -r /tmp/docs-versions/versioned_sidebars "$VERSIONED_DIR/" 2>/dev/null || true |
| 98 | + cp /tmp/docs-versions/versions.json "$VERSIONED_DIR/" 2>/dev/null || true |
| 99 | + git worktree remove /tmp/docs-versions |
| 100 | + fi |
| 101 | +
|
| 102 | + # Process each missing version (oldest first for correct ordering) |
| 103 | + REVERSED=$(echo "$MISSING" | tr ' ' '\n' | tac | tr '\n' ' ') |
| 104 | +
|
| 105 | + for TAG in $REVERSED; do |
| 106 | + VERSION="${TAG#v}" |
| 107 | + echo "" |
| 108 | + echo "=========================================" |
| 109 | + echo "Backfilling $VERSION (from tag $TAG)" |
| 110 | + echo "=========================================" |
| 111 | +
|
| 112 | + # Checkout the tag |
| 113 | + git checkout "$TAG" |
| 114 | +
|
| 115 | + # Install and build at that tag |
| 116 | + pnpm install --frozen-lockfile |
| 117 | + pnpm build |
| 118 | +
|
| 119 | + # Generate docs |
| 120 | + pnpm docs:build |
| 121 | +
|
| 122 | + # Restore existing versioned content into docs/ |
| 123 | + cp -r "$VERSIONED_DIR/versioned_docs" docs/ 2>/dev/null || true |
| 124 | + cp -r "$VERSIONED_DIR/versioned_sidebars" docs/ 2>/dev/null || true |
| 125 | + cp "$VERSIONED_DIR/versions.json" docs/ 2>/dev/null || true |
| 126 | +
|
| 127 | + # Install docs deps and create version snapshot |
| 128 | + cd docs |
| 129 | + pnpm install |
| 130 | + npx docusaurus docs:version "$VERSION" |
| 131 | + cd .. |
| 132 | +
|
| 133 | + # Save updated versioned content |
| 134 | + cp -r docs/versioned_docs "$VERSIONED_DIR/" 2>/dev/null || true |
| 135 | + cp -r docs/versioned_sidebars "$VERSIONED_DIR/" 2>/dev/null || true |
| 136 | + cp docs/versions.json "$VERSIONED_DIR/" 2>/dev/null || true |
| 137 | +
|
| 138 | + echo "✓ $VERSION backfilled" |
| 139 | + done |
| 140 | +
|
| 141 | + echo "" |
| 142 | + echo "Final versions.json:" |
| 143 | + cat "$VERSIONED_DIR/versions.json" |
| 144 | +
|
| 145 | + # Save for push step |
| 146 | + echo "VERSIONED_DIR=$VERSIONED_DIR" >> $GITHUB_ENV |
| 147 | +
|
| 148 | + - name: Push backfilled docs to docs-versions branch |
| 149 | + if: steps.versions.outputs.missing != '' && github.event.inputs.dry_run != 'true' |
| 150 | + run: | |
| 151 | + WORK=$(mktemp -d) |
| 152 | + git config user.name "github-actions[bot]" |
| 153 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 154 | +
|
| 155 | + if git ls-remote --heads origin docs-versions | grep -q docs-versions; then |
| 156 | + git clone --branch docs-versions --single-branch --depth 1 \ |
| 157 | + "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" "$WORK" |
| 158 | + else |
| 159 | + git init "$WORK" |
| 160 | + cd "$WORK" |
| 161 | + git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" |
| 162 | + git checkout --orphan docs-versions |
| 163 | + cd - |
| 164 | + fi |
| 165 | +
|
| 166 | + cd "$WORK" |
| 167 | + rm -rf versioned_docs versioned_sidebars versions.json |
| 168 | + cp -r "$VERSIONED_DIR/versioned_docs" . 2>/dev/null || true |
| 169 | + cp -r "$VERSIONED_DIR/versioned_sidebars" . 2>/dev/null || true |
| 170 | + cp "$VERSIONED_DIR/versions.json" . 2>/dev/null || true |
| 171 | +
|
| 172 | + git config user.name "github-actions[bot]" |
| 173 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 174 | + git add versioned_docs versioned_sidebars versions.json |
| 175 | + git commit -m "docs: backfill versioned docs for ${{ steps.versions.outputs.missing }}" || echo "Nothing to commit" |
| 176 | + git push origin docs-versions |
0 commit comments