Skip to content

Commit b6d23cd

Browse files
committed
🔗 Replace links to FCP-INDI/C-PAC with versioned links
1 parent 0f5384f commit b6d23cd

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-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 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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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(f'docs/{version}/**', recursive=True):
23+
if 'release_notes' not in filepath and os.path.isfile(filepath):
24+
try:
25+
# Replace links to master branch with links to specified branch
26+
with open(filepath, 'r') as openfile:
27+
file = openfile.read().replace(
28+
patterns[0], f'FCP-INDI/C-PAC/blob/{version}'
29+
).replace(
30+
patterns[1], f'FCP-INDI/C-PAC/{version}'
31+
)
32+
with open(filepath, 'w') as openfile:
33+
openfile.write(file)
34+
except UnicodeDecodeError:
35+
# List files that could not be opened to do find-and-replace
36+
print(' '.join([
37+
'Couldn\'t find and replace in file', filepath
38+
]))
39+
40+
41+
if __name__ == '__main__':
42+
if sys.argv[1] not in {'latest', 'nightly', 'develop'}:
43+
set_version(sys.argv[1])

0 commit comments

Comments
 (0)