-
Notifications
You must be signed in to change notification settings - Fork 79
/
replace-on-build.py
28 lines (20 loc) · 1.15 KB
/
replace-on-build.py
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
#!/usr/bin/env python3
import subprocess
import json
def replace_in_file(file,find,replace):
with open(file) as f:
filedata = f.read()
filedata = filedata.replace(find,replace)
with open(file,"w") as f:
f.write(filedata)
DEFAULT_SEMGREPIGNORE = subprocess.run(["curl","https://raw.githubusercontent.com/semgrep/semgrep/develop/cli/src/semgrep/templates/.semgrepignore"],capture_output=True).stdout.decode("utf-8")
RELEASE_NAME = json.loads(subprocess.run(["curl","https://api.github.com/repos/semgrep/semgrep/releases/latest"], capture_output=True).stdout)["tag_name"]
## List of text replacements to occur when building the docs
## {"file":FILE,"find":FIND,"replace":REPLACE} will find the text FIND in FILE and replace it with REPLACE
replacements = [
{"file":"docs/cli-reference.md", "find":"DEFAULT_SEMGREPIGNORE_TEXT", "replace":DEFAULT_SEMGREPIGNORE},
{"file":"docs/ignoring-files-folders-code.md", "find":"DEFAULT_SEMGREPIGNORE_TEXT", "replace":DEFAULT_SEMGREPIGNORE},
{"file":"docs/extensions/overview.md", "find":"SEMGREP_VERSION_LATEST", "replace":RELEASE_NAME},
]
for args in replacements:
replace_in_file(**args)