-
Notifications
You must be signed in to change notification settings - Fork 24
131 lines (112 loc) · 4.22 KB
/
Copy pathmanual_version_docs.yaml
File metadata and controls
131 lines (112 loc) · 4.22 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
name: Version docs
on:
# Runs when manually triggered from the GitHub UI.
workflow_dispatch:
inputs:
ref:
description: Git ref to checkout (branch, tag, or SHA). Defaults to the default branch.
required: false
type: string
default: ""
# Runs when invoked by another workflow.
workflow_call:
inputs:
ref:
description: Git ref to checkout (branch, tag, or SHA)
required: true
type: string
outputs:
version_docs_commitish:
description: The commit SHA of the versioned docs commit
value: ${{ jobs.version_docs.outputs.version_docs_commitish }}
concurrency:
group: version-docs
cancel-in-progress: false
permissions:
contents: read
env:
NODE_VERSION: 22
PYTHON_VERSION: "3.14"
jobs:
version_docs:
name: Version docs
runs-on: ubuntu-latest
outputs:
version_docs_commitish: ${{ steps.resolve_commitish.outputs.commitish }}
permissions:
contents: write
steps:
- name: Determine checkout ref
id: resolve_ref
run: |
REF="${{ inputs.ref }}"
if [[ -z "$REF" ]]; then
REF="${{ github.event.repository.default_branch }}"
fi
echo "ref=$REF" >> "$GITHUB_OUTPUT"
- name: Checkout repository
uses: actions/checkout@v6
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
ref: ${{ steps.resolve_ref.outputs.ref }}
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up uv package manager
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python dependencies
run: uv run poe install-dev
- name: Snapshot the current version
id: snapshot
run: |
cd website
corepack enable
yarn install
# Extract version from pyproject.toml.
FULL_VERSION="$(uv version --short)"
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 version for this major in versions.json (if any).
if [[ -f versions.json ]]; then
OLD_VERSION="$(jq -r --arg major "$MAJOR_VERSION" '.[] | select(startswith($major + "."))' versions.json | head -1)"
else
OLD_VERSION=""
echo "[]" > versions.json
fi
# Remove only the specific old version for this major (if found).
if [[ -n "$OLD_VERSION" ]]; then
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"
jq --arg old "$OLD_VERSION" '[.[] | select(. != $old)]' versions.json > tmp.json && mv tmp.json versions.json
else
echo "No existing version found for major $MAJOR_VERSION, nothing to remove"
fi
# Build API reference and create Docusaurus version snapshots.
bash build_api_reference.sh
uv run npx docusaurus docs:version "$MAJOR_MINOR_VERSION"
uv run npx docusaurus api:version "$MAJOR_MINOR_VERSION"
- name: Commit and push versioned docs
id: commit_versioned_docs
uses: EndBug/add-and-commit@v10
with:
add: website/versioned_docs website/versioned_sidebars website/versions.json
message: "docs: Version docs for v${{ steps.snapshot.outputs.version }} [skip ci]"
default_author: github_actions
- name: Resolve output commitish
id: resolve_commitish
run: |
SHA="${{ steps.commit_versioned_docs.outputs.commit_long_sha }}"
if [[ -z "$SHA" ]]; then
SHA="$(git rev-parse HEAD)"
fi
echo "commitish=$SHA" >> "$GITHUB_OUTPUT"