-
Notifications
You must be signed in to change notification settings - Fork 12
172 lines (149 loc) · 5.27 KB
/
Copy pathdocs.yml
File metadata and controls
172 lines (149 loc) · 5.27 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
name: Deploy Documentation
on:
push:
branches:
- master
- develop
tags:
- 'v*'
paths:
- 'docs/**'
permissions:
contents: write # нужно для push в gh-pages
pages: write
id-token: write
concurrency:
group: pages-${{ github.ref_name }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
outputs:
base: ${{ steps.vars.outputs.base }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # нужны все теги
- name: Compute deployment base
id: vars
run: |
REF="${{ github.ref_name }}"
if [ "$REF" = "master" ]; then BASE="/"
elif [ "$REF" = "develop" ]; then BASE="/develop/"
else BASE="/${REF}/" # теги: v1.2.3 → /v1.2.3/
fi
echo "base=$BASE" >> "$GITHUB_OUTPUT"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: docs/package-lock.json
- name: Install dependencies
working-directory: docs
run: npm ci
- name: Build docs
working-directory: docs
env:
DOCS_BASE: ${{ steps.vars.outputs.base }}
run: npm run docs:build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
# Обновляем единый /versions.json в корне gh-pages после каждого деплоя.
# VersionSwitcher загружает его в рантайме — любая старая версия
# всегда видит актуальный список, включая теги, добавленные позже.
update-versions-json:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout full history (for tags)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
continue-on-error: true
- name: Init gh-pages if branch missing
run: |
if [ ! -f gh-pages/.git/config ]; then
mkdir -p gh-pages && cd gh-pages
git init
git remote add origin \
https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git
git checkout --orphan gh-pages
fi
- name: Generate /versions.json
run: |
python3 - <<'EOF'
import json, subprocess
versions = [
{"label": "master (stable)", "base": "/"},
{"label": "develop (next)", "base": "/develop/"},
]
# Теги вида v1.2.3, отсортированные по semver, последние 10
out = subprocess.check_output(
["git", "tag", "-l", "v*", "--sort=-version:refname"]
).decode().strip()
for tag in [t for t in out.splitlines() if t][:10]:
versions.append({"label": tag, "base": f"/{tag}/"})
with open("gh-pages/versions.json", "w", encoding="utf-8") as f:
json.dump(versions, f, ensure_ascii=False, indent=2)
print(json.dumps(versions, ensure_ascii=False, indent=2))
EOF
- name: Commit and push versions.json
working-directory: gh-pages
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add versions.json
git diff --cached --quiet && echo "versions.json unchanged" && exit 0
git commit -m "chore: update versions.json [skip ci]"
git push origin gh-pages
# master → корень GitHub Pages через официальный механизм Actions Pages
deploy-master:
if: github.ref_name == 'master'
needs: [build, update-versions-json]
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# develop и теги → подпапка в gh-pages (/develop/, /v1.2.3/, …)
deploy-subpath:
if: github.ref_name != 'master'
needs: [build, update-versions-json]
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: github-pages
path: artifact
- name: Extract into subpath
run: |
SUBPATH="gh-pages/${{ needs.build.outputs.base }}"
mkdir -p "$SUBPATH"
tar -xf artifact/artifact.tar -C "$SUBPATH"
- name: Push to gh-pages
working-directory: gh-pages
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git diff --cached --quiet && echo "Nothing to commit" && exit 0
git commit -m "docs: deploy ${{ github.ref_name }} @ ${{ github.sha }}"
git push origin gh-pages