Skip to content

Commit 25b9000

Browse files
committed
[fix] Use version branch of openwisp-docs #218
Fixes #218
1 parent a59e2d5 commit 25b9000

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ openwrt-config-agent
1818
openwrt-monitoring-agent
1919
docker
2020
ansible
21+
openwisp-docs
2122
versions_map.json
2223

2324
### Python ###

build.py

+28-23
Original file line numberDiff line numberDiff line change
@@ -234,47 +234,43 @@ def clone_or_update_repo(name, branch, dir_name, owner='openwisp'):
234234
repo_url = f'git@github.com:{repository}.git'
235235
else:
236236
repo_url = f'https://github.com/{repository}.git'
237-
clone_path = os.path.join('modules', dir_name)
237+
clone_path = os.path.abspath(os.path.join('modules', dir_name))
238238

239239
if os.path.exists(clone_path):
240240
print(f"Repository '{name}' already exists. Updating...")
241-
subprocess.run(
242-
['git', 'remote', 'set-branches', 'origin', branch],
243-
cwd=clone_path,
244-
check=True,
245-
)
246-
subprocess.run(
247-
['git', 'fetch', '--update-shallow', 'origin', branch],
248-
cwd=clone_path,
249-
check=True,
250-
)
251241
subprocess.run(['git', 'checkout', branch], cwd=clone_path, check=True)
252-
subprocess.run(['git', 'pull', 'origin', branch], cwd=clone_path, check=True)
253242
else:
254243
print(f"Cloning repository '{name}'...")
255244
subprocess.run(
256245
[
257246
'git',
258247
'clone',
259-
'--single-branch',
260-
'--branch',
261-
branch,
262-
'--depth',
263-
'1',
264248
repo_url,
265249
clone_path,
266250
],
267251
check=True,
268252
)
253+
subprocess.run(
254+
[
255+
'git',
256+
'checkout',
257+
branch,
258+
],
259+
cwd=clone_path,
260+
check=True,
261+
)
269262
# If the module contains a doc directory, copy it to the dir_name in the root.
270263
# Otherwise, copy the entire directory.
271-
if os.path.islink(dir_name):
272-
os.unlink(dir_name)
264+
dest = dir_name
265+
if dest != 'openwisp-docs':
266+
dest = os.path.join('openwisp-docs', dir_name)
267+
if os.path.islink(dest):
268+
os.unlink(dest)
273269
src = os.path.join(clone_path, 'docs')
274270
# openwisp docs repo
275271
if not os.path.exists(src):
276272
src = clone_path
277-
os.symlink(src, dir_name)
273+
os.symlink(src, dest)
278274

279275

280276
def main():
@@ -333,14 +329,20 @@ def main():
333329

334330
# If a module does not define a branch,
335331
# it will fallback to the version_branch.
336-
version_branch = version.get('branch', version['name'])
332+
version_branch = version.get('module_branch', version['name'])
333+
docs_branch = version.get('docs_branch', 'master')
334+
clone_or_update_repo(
335+
name='openwisp-docs',
336+
branch=docs_branch,
337+
dir_name='openwisp-docs',
338+
)
337339
for module in modules:
338340
clone_or_update_repo(
339341
branch=module.pop('branch', version_branch),
340342
**module,
341343
)
342344
module_dirs.append(module['dir_name'])
343-
sphinx_src_dir = version.get('sphinx_src_dir', '.')
345+
sphinx_src_dir = version.get('sphinx_src_dir', 'openwisp-docs')
344346
for format in ['spellcheck'] + args.formats:
345347
subprocess.run(
346348
[
@@ -360,7 +362,10 @@ def main():
360362
)
361363
# Remove all temporary directories
362364
for dir in module_dirs:
363-
os.unlink(dir)
365+
path = dir
366+
if path != 'openwisp-docs':
367+
path = os.path.join('openwisp-docs', dir)
368+
os.unlink(path)
364369

365370
# Generate the index.html file which redirects to the stable version.
366371
env = Environment(loader=FileSystemLoader('_static'))

config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ modules:
3131
dir_name: docker
3232
versions:
3333
- name: dev
34-
branch: master
34+
module_branch: master
3535
- name: '24.11'
36-
branch: '1.1'
36+
docs_branch: '24.11'
37+
module_branch: '1.1'
3738
modules:
3839
- name: ansible-openwisp2
3940
branch: '24.11'
@@ -50,4 +51,3 @@ versions:
5051
- name: openwisp-docs
5152
branch: 'v22.05'
5253
dir_name: openwisp-docs
53-
sphinx_src_dir: ./openwisp-docs

0 commit comments

Comments
 (0)