Skip to content

Commit b0c56c6

Browse files
vdusekclaude
andcommitted
ci: Extract docs versioning into reusable manual_version_docs.yaml workflow
Extract the inline `version_docs` job from `manual_release_stable.yaml` into a standalone workflow that can be triggered manually or called from the release pipeline. Key improvements: - Fix `api:version` ENOENT bug by running docusaurus commands through `uv run` - Clean up ALL versions for the same major (not just exact major.minor match) - Remove non-docs artifacts (pyproject.toml, .gitignore, caches) from snapshots - Align doc_release ref to use version_docs_commitish instead of default_branch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d52bc8d commit b0c56c6

2 files changed

Lines changed: 148 additions & 56 deletions

File tree

.github/workflows/manual_release_stable.yaml

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -105,62 +105,12 @@ jobs:
105105
version_docs:
106106
name: Version docs
107107
needs: [release_prepare, changelog_update, pypi_publish]
108-
runs-on: ubuntu-latest
109108
permissions:
110109
contents: write
111-
env:
112-
NODE_VERSION: 22
113-
PYTHON_VERSION: 3.14
114-
115-
steps:
116-
- name: Checkout repository
117-
uses: actions/checkout@v6
118-
with:
119-
ref: ${{ github.event.repository.default_branch }}
120-
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
121-
122-
- name: Set up Node
123-
uses: actions/setup-node@v6
124-
with:
125-
node-version: ${{ env.NODE_VERSION }}
126-
127-
- name: Set up Python
128-
uses: actions/setup-python@v6
129-
with:
130-
python-version: ${{ env.PYTHON_VERSION }}
131-
132-
- name: Set up uv package manager
133-
uses: astral-sh/setup-uv@v7
134-
with:
135-
python-version: ${{ env.PYTHON_VERSION }}
136-
137-
- name: Install Python dependencies
138-
run: uv run poe install-dev
139-
140-
- name: Install website dependencies
141-
run: |
142-
cd website
143-
yarn install
144-
145-
- name: Snapshot the current version
146-
run: |
147-
cd website
148-
VERSION="$(python -c "import tomllib, pathlib; print(tomllib.loads(pathlib.Path('../pyproject.toml').read_text())['project']['version'])")"
149-
MAJOR_MINOR="$(echo "$VERSION" | cut -d. -f1-2)"
150-
export MAJOR_MINOR
151-
rm -rf "versioned_docs/version-${MAJOR_MINOR}"
152-
rm -rf "versioned_sidebars/version-${MAJOR_MINOR}-sidebars.json"
153-
jq 'map(select(. != env.MAJOR_MINOR))' versions.json > tmp.json && mv tmp.json versions.json
154-
bash build_api_reference.sh
155-
npx docusaurus docs:version "$MAJOR_MINOR"
156-
npx docusaurus api:version "$MAJOR_MINOR"
157-
158-
- name: Commit and push the version snapshot
159-
uses: EndBug/add-and-commit@v10
160-
with:
161-
author_name: Apify Release Bot
162-
author_email: noreply@apify.com
163-
message: "docs: update versioned docs for ${{ needs.release_prepare.outputs.version_number }}"
110+
uses: ./.github/workflows/manual_version_docs.yaml
111+
with:
112+
ref: ${{ needs.changelog_update.outputs.changelog_commitish }}
113+
secrets: inherit
164114

165115
doc_release:
166116
name: Doc release
@@ -171,6 +121,6 @@ jobs:
171121
id-token: write
172122
uses: ./.github/workflows/_release_docs.yaml
173123
with:
174-
# Use the default branch to include both the changelog update and the versioned docs snapshot.
175-
ref: ${{ github.event.repository.default_branch }}
124+
# Use the version_docs commit to include both changelog and versioned docs.
125+
ref: ${{ needs.version_docs.outputs.version_docs_commitish }}
176126
secrets: inherit
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Version docs
2+
3+
on:
4+
# Runs when manually triggered from the GitHub UI.
5+
workflow_dispatch:
6+
inputs:
7+
ref:
8+
description: "Git ref to checkout (branch, tag, or SHA). Defaults to the default branch."
9+
required: false
10+
type: string
11+
default: ""
12+
13+
# Runs when invoked by another workflow.
14+
workflow_call:
15+
inputs:
16+
ref:
17+
description: "Git ref to checkout (branch, tag, or SHA)"
18+
required: true
19+
type: string
20+
outputs:
21+
version_docs_commitish:
22+
description: "The commit SHA of the versioned docs commit"
23+
value: ${{ jobs.version_docs.outputs.version_docs_commitish }}
24+
25+
concurrency:
26+
group: version-docs
27+
cancel-in-progress: false
28+
29+
permissions:
30+
contents: read
31+
32+
jobs:
33+
version_docs:
34+
name: Version docs
35+
runs-on: ubuntu-latest
36+
outputs:
37+
version_docs_commitish: ${{ steps.resolve_commitish.outputs.commitish }}
38+
permissions:
39+
contents: write
40+
env:
41+
NODE_VERSION: 22
42+
PYTHON_VERSION: "3.14"
43+
44+
steps:
45+
- name: Determine checkout ref
46+
id: resolve_ref
47+
run: |
48+
REF="${{ inputs.ref }}"
49+
if [ -z "$REF" ]; then
50+
REF="${{ github.event.repository.default_branch }}"
51+
fi
52+
echo "ref=$REF" >> "$GITHUB_OUTPUT"
53+
54+
- name: Checkout repository
55+
uses: actions/checkout@v6
56+
with:
57+
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
58+
ref: ${{ steps.resolve_ref.outputs.ref }}
59+
60+
- name: Set up Node
61+
uses: actions/setup-node@v6
62+
with:
63+
node-version: ${{ env.NODE_VERSION }}
64+
65+
- name: Set up Python
66+
uses: actions/setup-python@v6
67+
with:
68+
python-version: ${{ env.PYTHON_VERSION }}
69+
70+
- name: Set up uv package manager
71+
uses: astral-sh/setup-uv@v7
72+
with:
73+
python-version: ${{ env.PYTHON_VERSION }}
74+
75+
- name: Install Python dependencies
76+
run: uv run poe install-dev
77+
78+
- name: Install website dependencies
79+
run: |
80+
cd website
81+
corepack enable
82+
yarn install
83+
84+
- name: Snapshot the current version
85+
run: |
86+
cd website
87+
88+
# Extract version from pyproject.toml.
89+
VERSION="$(python -c "import tomllib, pathlib; print(tomllib.loads(pathlib.Path('../pyproject.toml').read_text())['project']['version'])")"
90+
MAJOR_MINOR="$(echo "$VERSION" | cut -d. -f1-2)"
91+
MAJOR="$(echo "$VERSION" | cut -d. -f1)"
92+
echo "Version: $VERSION, Major.Minor: $MAJOR_MINOR, Major: $MAJOR"
93+
94+
# Remove ALL existing versions for this major (not just exact major.minor match).
95+
for dir in versioned_docs/version-${MAJOR}.*; do
96+
if [ -d "$dir" ]; then
97+
echo "Removing $dir"
98+
rm -rf "$dir"
99+
fi
100+
done
101+
for file in versioned_sidebars/version-${MAJOR}.*-sidebars.json; do
102+
if [ -f "$file" ]; then
103+
echo "Removing $file"
104+
rm -f "$file"
105+
fi
106+
done
107+
108+
# Update versions.json to remove entries for this major version.
109+
if [ -f versions.json ]; then
110+
jq --arg major "$MAJOR" '[.[] | select((split(".")[0]) != $major)]' versions.json > tmp.json && mv tmp.json versions.json
111+
else
112+
echo "[]" > versions.json
113+
fi
114+
115+
# Build API reference and create Docusaurus version snapshots.
116+
bash build_api_reference.sh
117+
uv run npx docusaurus docs:version "$MAJOR_MINOR"
118+
uv run npx docusaurus api:version "$MAJOR_MINOR"
119+
120+
# Clean up non-docs artifacts from the snapshot.
121+
rm -f "versioned_docs/version-${MAJOR_MINOR}/changelog.md"
122+
rm -f "versioned_docs/version-${MAJOR_MINOR}/pyproject.toml"
123+
rm -f "versioned_docs/version-${MAJOR_MINOR}/.gitignore"
124+
rm -rf "versioned_docs/version-${MAJOR_MINOR}/.ruff_cache"
125+
rm -rf "versioned_docs/version-${MAJOR_MINOR}/.ty_cache"
126+
127+
- name: Commit and push versioned docs
128+
id: commit_versioned_docs
129+
uses: EndBug/add-and-commit@v10
130+
with:
131+
add: "website/versioned_docs website/versioned_sidebars website/versions.json"
132+
message: "docs: version docs [skip ci]"
133+
default_author: github_actions
134+
135+
- name: Resolve output commitish
136+
id: resolve_commitish
137+
run: |
138+
SHA="${{ steps.commit_versioned_docs.outputs.commit_long_sha }}"
139+
if [ -z "$SHA" ]; then
140+
SHA="$(git rev-parse HEAD)"
141+
fi
142+
echo "commitish=$SHA" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)