Skip to content

Commit 21d3e3e

Browse files
committed
🔗 Replace links to FCP-INDI/C-PAC with versioned links
1 parent 21d2d64 commit 21d3e3e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

‎.circleci/config.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ jobs:
153153
at: /
154154
- get-version
155155
- prep-deploy
156+
- run:
157+
name: 🔗 Replace links to `FCP-INDI/master` with versioned links
158+
command: |
159+
cd /tmp/repo/
160+
python scripts/link_to_set_version.py ${BUILD_VERSION}
156161
- run:
157162
name: 🔖 Checking if latest
158163
command: if $(python /build/scripts/is_latest.py /tmp/repo/docs); then cp -r /build/docs/${BUILD_VERSION} /build/docs/latest; fi
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""This script takes a version string as a commandline argument and updates
2+
the links in `docs/{version}` that point to code in the `master` branch of
3+
FCP-INDI/C-PAC to code in the tagged version.
4+
5+
Usage
6+
-----
7+
python link_to_set_version.py $VERSION
8+
"""
9+
10+
import os
11+
import sys
12+
13+
from glob import glob
14+
15+
16+
def set_version(version):
17+
# Look for links to master branch
18+
patterns = [
19+
'FCP-INDI/C-PAC/blob/master',
20+
'FCP-INDI/C-PAC/master'
21+
]
22+
for filepath in glob('/'.join([
23+
'docs', version, '**'
24+
]), recursive=True):
25+
if 'release_notes' not in filepath and os.path.isfile(filepath):
26+
try:
27+
# Replace links to master branch with links to specified branch
28+
with open(filepath, 'r') as openfile:
29+
file = openfile.read().replace(
30+
patterns[0], 'FCP-INDI/C-PAC/blob/{}'.format(version)
31+
).replace(
32+
patterns[1], 'FCP-INDI/C-PAC/{}'.format(version)
33+
)
34+
with open(filepath, 'w') as openfile:
35+
openfile.write(file)
36+
except UnicodeDecodeError:
37+
# List files that could not be opened to do find-and-replace
38+
print(' '.join([
39+
'Couldn\'t find and replace in file', filepath
40+
]))
41+
42+
43+
if __name__ == '__main__':
44+
if sys.argv[1] not in {'latest', 'nightly', 'develop'}:
45+
set_version(sys.argv[1])

0 commit comments

Comments
 (0)