-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrelease.py
More file actions
executable file
·140 lines (114 loc) · 4.29 KB
/
Copy pathrelease.py
File metadata and controls
executable file
·140 lines (114 loc) · 4.29 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python3
# Copyright 2026 The Mount-Zip Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import os
import re
import subprocess
import sys
def run(cmd):
subprocess.run(cmd, check=True)
def get_current_version():
with open('mount-zip.cc', 'r') as f:
for line in f:
match = re.search(r'#define PROGRAM_VERSION "(.*)"', line)
if match:
return match.group(1)
raise ValueError('Could not find PROGRAM_VERSION in mount-zip.cc')
def update_version(version, date=None):
# Update mount-zip.cc
with open('mount-zip.cc', 'r') as f:
content = f.read()
content = re.sub(r'#define PROGRAM_VERSION ".*"',
f'#define PROGRAM_VERSION "{version}"', content)
with open('mount-zip.cc', 'w') as f:
f.write(content)
# Update README.md
with open('README.md', 'r') as f:
content = f.read()
content = re.sub(r'footer: mount-zip .*', f'footer: mount-zip {version}',
content)
if date:
content = re.sub(r'date: .*', f'date: {date}', content)
with open('README.md', 'w') as f:
f.write(content)
# Update DEVELOPMENT.md
if os.path.exists('DEVELOPMENT.md'):
with open('DEVELOPMENT.md', 'r') as f:
content = f.read()
state = 'Stable' if date else 'Development'
content = re.sub(r'Current state: \*\*.*\*\*',
f'Current state: **{version} ({state})**', content)
with open('DEVELOPMENT.md', 'w') as f:
f.write(content)
# Regenerate man page
run(['make', 'doc', 'QUIET=1'])
def main():
current_version = get_current_version()
major, minor = map(int, current_version.split('.'))
if len(sys.argv) == 2:
version = sys.argv[1]
else:
# Suggest next even version
if minor % 2 != 0:
version = f'{major}.{minor + 1}'
else:
version = f'{major}.{minor + 2}'
match = re.match(r'^(\d+)\.(\d+)$', version)
if not match:
print(f'Invalid version format: {version}. Expected X.Y')
sys.exit(1)
stable_major = int(match.group(1))
stable_minor = int(match.group(2))
if stable_minor % 2 != 0:
print(f'Version {version} is not an even (stable) version.')
sys.exit(1)
next_version = f'{stable_major}.{stable_minor + 1}'
date = datetime.datetime.now().strftime('%B %Y')
# Confirmation
print(f'Current version: {current_version}')
print(f'Release version: {version}')
print(f'Next dev version: {next_version}')
print(f'Release date: {date}')
confirm = input('Proceed with release? [y/N] ').lower()
if confirm != 'y':
print('Release cancelled.')
sys.exit(0)
# Check for clean git state
res = subprocess.run(['git', 'status', '--porcelain'],
capture_output=True,
text=True)
if res.stdout:
print(
'Git workspace is not clean. Please commit or stash your changes.')
sys.exit(1)
print(f'Releasing version {version}...')
update_version(version, date)
run([
'git', 'add', 'mount-zip.cc', 'mount-zip.1', 'README.md',
'DEVELOPMENT.md'
])
run(['git', 'commit', '-m', f'Release version {version}'])
run(['git', 'tag', '-a', f'v{version}', '-m', f'Version {version}'])
print(f'Starting development version {next_version}...')
update_version(next_version)
run([
'git', 'add', 'mount-zip.cc', 'mount-zip.1', 'README.md',
'DEVELOPMENT.md'
])
run(['git', 'commit', '-m', f'Start development version {next_version}'])
print(f'\nSuccessfully released v{version} and bumped to {next_version}.')
print('Don\'t forget to run: git push origin main --tags')
if __name__ == '__main__':
main()