Repository navigation
183 lines (157 loc) · 6.1 KB
/
Copy pathmanual_version_docs.yaml
File metadata and controls
183 lines (157 loc) · 6.1 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
name: Version docs
on:
# Runs when manually triggered from the GitHub UI.
workflow_dispatch:
inputs:
version_number:
description: Version to snapshot (e.g. "1.0.0"). If empty, the current version in pyproject.toml is used.
required: false
type: string
default: ""
# Runs when invoked by another workflow.
workflow_call:
inputs:
version_number:
description: Version to snapshot (e.g. "1.0.0"). If empty, the current version in pyproject.toml is used.
required: false
type: string
default: ""
concurrency:
group: version-docs
cancel-in-progress: false
permissions:
contents: read
env:
NODE_VERSION: "24"
PYTHON_VERSION: "3.14"
jobs:
version_docs:
name: Version docs
runs-on: ubuntu-latest
permissions:
contents: read
checks: read
outputs:
sha: ${{ steps.sha.outputs.sha }}
version: ${{ steps.snapshot.outputs.version }}
steps:
# Gate manual dispatches on the `Checks` workflow already succeeding on this commit (run by `on_master.yaml`);
# skipped when called from another workflow.
- name: Wait for checks
if: github.event_name == 'workflow_dispatch'
uses: apify/actions/wait-for-checks@v1.9.0
with:
ref: ${{ github.sha }}
check-regexp: ^Checks
- name: Checkout repository
uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- name: Record the built commit
id: sha
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Set up Node
uses: actions/setup-node@v7.1.0
with:
node-version: ${{ env.NODE_VERSION }}
check-latest: true
- name: Set up Python
uses: actions/setup-python@v7.1.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up uv package manager
uses: astral-sh/setup-uv@v10.4.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python dependencies
run: uv run poe install-dev
- name: Install pnpm and website dependencies
uses: apify/actions/pnpm-install@v1.9.0
with:
working-directory: website
- name: Snapshot the current version
id: snapshot
env:
INPUT_VERSION: ${{ inputs.version_number }}
run: |
cd website
# Prefer the explicit input (passed by the release workflow after the version bump).
# Fall back to pyproject.toml only when run manually without an input — this avoids
# the stale-checkout pitfall where the bumped version isn't visible to this job.
if [[ -n "$INPUT_VERSION" ]]; then
FULL_VERSION="$INPUT_VERSION"
else
FULL_VERSION="$(uv version --short)"
fi
MAJOR_MINOR_VERSION="$(echo "$FULL_VERSION" | cut -d. -f1-2)"
MAJOR_VERSION="$(echo "$FULL_VERSION" | cut -d. -f1)"
echo "version=$FULL_VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $FULL_VERSION, Major.Minor: $MAJOR_MINOR_VERSION, Major: $MAJOR_VERSION"
# Find the existing versions for this major in versions.json (if any).
if [[ -f versions.json ]]; then
OLD_VERSIONS="$(jq -r --arg major "$MAJOR_VERSION" '.[] | select(startswith($major + "."))' versions.json)"
else
OLD_VERSIONS=""
echo "[]" > versions.json
fi
# Remove all old versions for this major (if found).
if [[ -n "$OLD_VERSIONS" ]]; then
while IFS= read -r OLD_VERSION; do
[[ -z "$OLD_VERSION" ]] && continue
echo "Removing old version $OLD_VERSION for major $MAJOR_VERSION"
rm -rf "versioned_docs/version-${OLD_VERSION}"
rm -f "versioned_sidebars/version-${OLD_VERSION}-sidebars.json"
done <<< "$OLD_VERSIONS"
jq --arg major "$MAJOR_VERSION" 'map(select(startswith($major + ".") | not))' versions.json > tmp.json && mv tmp.json versions.json
else
echo "No existing versions found for major $MAJOR_VERSION, nothing to remove"
fi
# Build API reference and create Docusaurus version snapshots.
bash build_api_reference.sh
uv run pnpm exec docusaurus docs:version "$MAJOR_MINOR_VERSION"
uv run pnpm exec docusaurus api:version "$MAJOR_MINOR_VERSION"
- name: Upload versioned docs
uses: actions/upload-artifact@v7.0.2
with:
name: versioned-docs
path: |
website/versioned_docs
website/versioned_sidebars
website/versions.json
include-hidden-files: true
retention-days: 1
# The service account token is only used in a job that does not run the docs toolchain.
commit_versioned_docs:
name: Commit versioned docs
needs: [version_docs]
runs-on: ubuntu-latest
environment:
name: pypi
deployment: false
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v7.0.1
with:
fetch-depth: 0
persist-credentials: false
# Start from the commit the snapshot was made on, so the pull below merges it with anything pushed since.
- name: Reset to the built commit
run: git reset --hard "$BUILT_SHA"
env:
BUILT_SHA: ${{ needs.version_docs.outputs.sha }}
- name: Remove the previous snapshot
run: rm -rf website/versioned_docs website/versioned_sidebars website/versions.json
- name: Download versioned docs
uses: actions/download-artifact@v8.0.2
with:
name: versioned-docs
path: website
- name: Commit and push versioned docs
uses: apify/actions/signed-commit@v1.9.0
with:
message: "docs: Version docs for v${{ needs.version_docs.outputs.version }} [skip ci]"
add: website/versioned_docs website/versioned_sidebars website/versions.json
pull: --rebase --autostash
github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}