Skip to content

Commit 41da64c

Browse files
pdmackclaude
andauthored
feat(ci): trigger publish on release tags, auto-register and prune versions (#1292)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent eba11e7 commit 41da64c

1 file changed

Lines changed: 44 additions & 22 deletions

File tree

.github/workflows/publish-fern-docs.yml

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
# Publishes the Fern documentation site when a docs tag is pushed or manually triggered.
4+
# Publishes the Fern documentation site on release tag push or manual dispatch.
55
#
6-
# On a docs/vX.Y.Z tag push the workflow also:
6+
# On a vX.Y.Z release tag push the workflow also:
77
# 1. Generates fern/versions/vX.Y.Z.yml from the tag's docs/index.yml
88
# 2. Adds a version entry to fern/docs.yml
9-
# 3. Commits both back to main so future publishes include the new version
9+
# 3. Prunes older versions to keep only the 3 most recent (plus Latest)
10+
# 4. Commits changes back to main so future publishes include the new version
1011
#
11-
# To publish: git tag docs/v1.2.0 && git push origin docs/v1.2.0
12-
# Or use the "Run workflow" button in the Actions tab.
12+
# Pre-release tags (e.g. v1.6.0-rc1) trigger publish but skip version registration.
1313
#
1414
# Required configuration:
1515
# - Repository secret: DOCS_FERN_TOKEN (provisioned by the docs infrastructure team)
@@ -19,7 +19,7 @@ name: Publish Fern Docs
1919
on:
2020
push:
2121
tags:
22-
- "docs/v*"
22+
- "v[0-9]*.[0-9]*.[0-9]*"
2323
workflow_dispatch: {}
2424

2525
permissions:
@@ -29,6 +29,9 @@ concurrency:
2929
group: fern-publish
3030
cancel-in-progress: true
3131

32+
env:
33+
MAX_VERSIONS: 3
34+
3235
jobs:
3336
publish:
3437
name: Publish Fern Docs
@@ -41,47 +44,66 @@ jobs:
4144
ref: main
4245

4346
- name: Register new version from tag
44-
if: startsWith(github.ref, 'refs/tags/docs/v')
47+
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-')
4548
run: |
4649
set -eo pipefail
47-
TAG_VERSION="${GITHUB_REF#refs/tags/docs/}" # e.g. v1.5.0
50+
TAG_VERSION="${GITHUB_REF#refs/tags/}" # e.g. v1.5.0
4851
4952
# Skip if version file already exists
5053
if [ -f "fern/versions/${TAG_VERSION}.yml" ]; then
5154
echo "Version file fern/versions/${TAG_VERSION}.yml already exists — skipping"
5255
exit 0
5356
fi
5457
55-
# Extract index.yml from the matching release tag
56-
if ! git rev-parse "$TAG_VERSION" >/dev/null 2>&1; then
57-
echo "::warning::Release tag $TAG_VERSION not found — cannot create version entry"
58-
exit 0
59-
fi
60-
6158
# Generate version nav from the tag's docs/index.yml
6259
echo "Generating fern/versions/${TAG_VERSION}.yml from tag $TAG_VERSION"
63-
git archive "$TAG_VERSION" -- docs/index.yml | tar -xO docs/index.yml | \
60+
git archive "${TAG_VERSION}" -- docs/index.yml | tar -xO docs/index.yml | \
6461
sed "s|path: |path: ${TAG_VERSION}-content/|g" > "fern/versions/${TAG_VERSION}.yml"
6562
6663
# Add version entry to docs.yml (insert after Latest, before older versions)
6764
export TAG_VERSION
6865
yq -i '.products[0].versions |= [.[0]] + [{"display-name": env(TAG_VERSION), "path": "versions/" + env(TAG_VERSION) + ".yml", "slug": env(TAG_VERSION), "availability": "stable"}] + .[1:]' fern/docs.yml
6966
70-
echo "--- docs.yml versions ---"
71-
grep "display-name:" fern/docs.yml
67+
echo "--- docs.yml versions after insert ---"
68+
yq '.products[0].versions[].display-name' fern/docs.yml
69+
70+
- name: Prune old versions
71+
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-')
72+
run: |
73+
set -eo pipefail
74+
KEEP=$((MAX_VERSIONS + 1)) # +1 for the Latest entry at index 0
75+
76+
# Count current versioned entries (including Latest)
77+
TOTAL=$(yq '.products[0].versions | length' fern/docs.yml)
78+
if [ "$TOTAL" -le "$KEEP" ]; then
79+
echo "Only $TOTAL version entries — nothing to prune"
80+
exit 0
81+
fi
82+
83+
# Remove excess entries from the end (oldest) and their version files
84+
PRUNED=$(yq ".products[0].versions[$KEEP:].[].slug" fern/docs.yml)
85+
yq -i ".products[0].versions |= .[:$KEEP]" fern/docs.yml
86+
87+
for slug in $PRUNED; do
88+
rm -f "fern/versions/${slug}.yml"
89+
echo "Pruned version $slug"
90+
done
91+
92+
echo "--- docs.yml versions after prune ---"
93+
yq '.products[0].versions[].display-name' fern/docs.yml
7294
73-
- name: Commit new version entry
74-
if: startsWith(github.ref, 'refs/tags/docs/v')
95+
- name: Commit version changes
96+
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-')
7597
run: |
76-
TAG_VERSION="${GITHUB_REF#refs/tags/docs/}"
77-
if git diff --quiet fern/; then
98+
TAG_VERSION="${GITHUB_REF#refs/tags/}"
99+
if git diff --quiet fern/ && [ -z "$(git ls-files --deleted fern/)" ]; then
78100
echo "No version changes to commit"
79101
exit 0
80102
fi
81103
git config user.name "github-actions[bot]"
82104
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
83105
git add fern/versions/ fern/docs.yml
84-
git commit -m "chore(fern): add ${TAG_VERSION} version entry [automated]"
106+
git commit -m "chore(fern): register ${TAG_VERSION}, keep latest ${MAX_VERSIONS} versions [automated]"
85107
git push origin main
86108
87109
- name: Checkout frozen version content

0 commit comments

Comments
 (0)