-
Notifications
You must be signed in to change notification settings - Fork 10
/
publish.py
70 lines (60 loc) · 1.77 KB
/
publish.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
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
from pathlib import Path
import hashlib
import subprocess
import sys
import zipfile
if len(sys.argv) < 2:
print('Please specify the release version as the first argument, e.g. ./publish.py 1.21')
exit(-1)
version = sys.argv[1]
subprocess.run(['git', 'fetch', '--tags'], check=True)
output = subprocess.run(['git', 'tag', version])
if output.returncode != 0:
print(f'Tag {version} already exists. Please choose another one.')
exit(-2)
paths = [
Path('application.py'),
Path('application_database.py'),
Path('application_login.py'),
Path('application_utils.py'),
Path('code-deploy.sh'),
Path('data'),
Path('engine'),
Path('LICENSE.md'),
Path('pages'),
Path('README.md'),
Path('requirements'),
Path('requirements.txt'),
Path('robots.txt'),
Path('witness-puzzles.conf'),
]
all_paths = []
for path in paths:
if path.is_file():
all_paths.append(path)
else:
all_paths += list(path.glob('**/*'))
# path = path.parent / (path.stem + path.suffix)
# path = path.parent / path.name
replacements = {'%version%': version}
for path in all_paths:
if path.suffix == '.js':
hash = hashlib.sha256()
hash.update(path.read_bytes())
replacements[path.name] = f'{path.stem}-{hash.hexdigest()[:8]}{path.suffix}'
z = zipfile.ZipFile(f'{version}.zip', 'w')
root = Path(__file__).parent.resolve()
for path in all_paths:
path = path.resolve()
arcname = str(path.relative_to(root))
if path.suffix in ['.js', '.html', '.py']:
with path.open() as f:
contents = f.read()
for key in replacements:
contents = contents.replace(key, replacements[key])
arcname = arcname.replace(key, replacements[key])
z.writestr(arcname, contents)
else:
z.write(path, arcname)
z.close()
subprocess.run(['git', 'push', 'origin', version], check=True)