1 #!/usr/bin/env -S python3 -B
3 # This script expects the directory ~/samba-rsync-ftp to exist and to be a
4 # copy of the /home/ftp/pub/rsync dir on samba.org. When the script is done,
5 # the git repository in the current directory will be updated, and the local
6 # ~/samba-rsync-ftp dir will be ready to be rsynced to samba.org. See the
7 # script samba-rsync for an easy way to initialize the local ftp copy and to
8 # thereafter update the remote files from your local copy.
10 # This script also expects to be able to gpg sign the resulting tar files
11 # using your default gpg key. Make sure that the html download.html file
12 # has a link to the relevant keys that are authorized to sign the tar files
13 # and also make sure that the following commands work as expected:
17 # gpg --verify TeMp.gpg
21 # The second time you sign the file it should NOT prompt you for your password
22 # (unless the timeout period has passed). It will prompt about overriding the
23 # existing TeMp.gpg file, though.
25 import os, sys, re, argparse, glob, shutil, signal
26 from datetime import datetime
27 from getpass import getpass
29 sys.path = ['packaging'] + sys.path
33 os.environ['LESS'] = 'mqeiXR'; # Make sure that -F is turned off and -R is turned on.
34 dest = os.environ['HOME'] + '/samba-rsync-ftp'
35 ORIGINAL_PATH = os.environ['PATH']
38 if not os.path.isfile('packaging/release-rsync'):
39 die('You must run this script from the top of your rsync checkout.')
42 cl_today = now.strftime('* %a %b %d %Y')
43 year = now.strftime('%Y')
44 ztoday = now.strftime('%d %b %Y')
45 today = ztoday.lstrip('0')
49 signal.signal(signal.SIGINT, signal_handler)
51 if cmd_txt_chk(['packaging/prep-auto-dir']).out == '':
52 die('You must setup an auto-build-save dir to use this script.');
54 auto_dir, gen_files = get_gen_files(True)
55 gen_pathnames = [ os.path.join(auto_dir, fn) for fn in gen_files ]
61 == This will release a new version of rsync onto an unsuspecting world. ==
65 with open('build/rsync.1') as fh:
67 if line.startswith(r'.\" prefix='):
68 doc_prefix = line.split('=')[1].strip()
69 if doc_prefix != '/usr':
70 warn(f"*** The documentation was built with prefix {doc_prefix} instead of /usr ***")
71 die("*** Read the md2man script for a way to override this. ***")
73 if line.startswith('.P'):
74 die("Failed to find the prefix comment at the start of the rsync.1 manpage.")
76 if not os.path.isdir(dest):
77 die(dest, "dest does not exist")
78 if not os.path.isdir('.git'):
79 die("There is no .git dir in the current directory.")
80 if os.path.lexists('a'):
81 die('"a" must not exist in the current directory.')
82 if os.path.lexists('b'):
83 die('"b" must not exist in the current directory.')
84 if os.path.lexists('patches.gen'):
85 die('"patches.gen" must not exist in the current directory.')
87 check_git_state(args.master_branch, True, 'patches')
89 curversion = get_rsync_version()
91 # All version values are strings!
92 lastversion, last_protocol_version, pdate = get_NEWS_version_info()
93 protocol_version, subprotocol_version = get_protocol_versions()
96 m = re.search(r'pre(\d+)', version)
98 version = re.sub(r'pre\d+', 'pre' + str(int(m[1]) + 1), version)
100 version = version.replace('dev', 'pre1')
102 ans = input(f"Please enter the version number of this release: [{version}] ")
104 version = re.sub(r'pre\d+', '', version)
107 if not re.match(r'^[\d.]+(pre\d+)?$', version):
108 die(f'Invalid version: "{version}"')
110 v_ver = 'v' + version
111 rsync_ver = 'rsync-' + version
113 if os.path.lexists(rsync_ver):
114 die(f'"{rsync_ver}" must not exist in the current directory.')
116 out = cmd_txt_chk(['git', 'tag', '-l', v_ver]).out
118 print(f"Tag {v_ver} already exists.")
119 ans = input("\nDelete tag or quit? [Q/del] ")
120 if not re.match(r'^del', ans, flags=re.I):
122 cmd_chk(['git', 'tag', '-d', v_ver])
123 if os.path.isdir('patches/.git'):
124 cmd_chk(f"cd patches && git tag -d '{v_ver}'")
126 version = re.sub(r'[-.]*pre[-.]*', 'pre', version)
127 if 'pre' in version and not curversion.endswith('dev'):
128 lastversion = curversion
130 ans = input(f"Enter the previous version to produce a patch against: [{lastversion}] ")
133 lastversion = re.sub(r'[-.]*pre[-.]*', 'pre', lastversion)
135 rsync_lastver = 'rsync-' + lastversion
136 if os.path.lexists(rsync_lastver):
137 die(f'"{rsync_lastver}" must not exist in the current directory.')
139 m = re.search(r'(pre\d+)', version)
140 pre = m[1] if m else ''
142 release = '0.1' if pre else '1'
143 ans = input(f"Please enter the RPM release number of this release: [{release}] ")
149 finalversion = re.sub(r'pre\d+', '', version)
150 proto_changed = protocol_version != last_protocol_version
152 if finalversion in pdate:
153 proto_change_date = pdate[finalversion]
156 ans = input("On what date did the protocol change to {protocol_version} get checked in? (dd Mmm yyyy) ")
157 if re.match(r'^\d\d \w\w\w \d\d\d\d$', ans):
159 proto_change_date = ans
161 proto_change_date = ' ' * 11
163 if 'pre' in lastversion:
165 die("You should not diff a release version against a pre-release version.")
166 srcdir = srcdiffdir = lastsrcdir = 'src-previews'
167 skipping = ' ** SKIPPING **'
169 srcdir = srcdiffdir = 'src-previews'
171 skipping = ' ** SKIPPING **'
173 srcdir = lastsrcdir = 'src'
174 srcdiffdir = 'src-diffs'
179 version is "{version}"
180 lastversion is "{lastversion}"
184 srcdiffdir is "{srcdiffdir}"
185 lastsrcdir is "{lastsrcdir}"
186 release is "{release}"
189 - tweak SUBPROTOCOL_VERSION in rsync.h, if needed
190 - tweak the version in version.h and the spec files
191 - tweak NEWS.md to ensure header values are correct
192 - generate configure.sh, config.h.in, and proto.h
193 - page through the differences
195 ans = input("<Press Enter to continue> ")
198 'Version:': finalversion,
200 '%define fullversion': f'%{{version}}{pre}',
201 'Released': version + '.',
202 '%define srcdir': srcdir,
205 tweak_files = 'version.h rsync.h NEWS.md'.split()
206 tweak_files += glob.glob('packaging/*.spec')
207 tweak_files += glob.glob('packaging/*/*.spec')
209 for fn in tweak_files:
210 with open(fn, 'r', encoding='utf-8') as fh:
211 old_txt = txt = fh.read()
212 if fn == 'version.h':
213 x_re = re.compile(r'^(#define RSYNC_VERSION).*', re.M)
214 msg = f"Unable to update RSYNC_VERSION in {fn}"
215 txt = replace_or_die(x_re, r'\1 "%s"' % version, txt, msg)
217 for var, val in specvars.items():
218 x_re = re.compile(r'^%s .*' % re.escape(var), re.M)
219 txt = replace_or_die(x_re, var + ' ' + val, txt, f"Unable to update {var} in {fn}")
220 x_re = re.compile(r'^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)', re.M)
221 txt = replace_or_die(x_re, r'%s \1' % cl_today, txt, f"Unable to update ChangeLog header in {fn}")
222 elif fn == 'rsync.h':
223 x_re = re.compile('(#define\s+SUBPROTOCOL_VERSION)\s+(\d+)')
224 repl = lambda m: m[1] + ' ' + ('0' if not pre or not proto_changed else '1' if m[2] == '0' else m[2])
225 txt = replace_or_die(x_re, repl, txt, f"Unable to find SUBPROTOCOL_VERSION define in {fn}")
226 elif fn == 'NEWS.md':
227 efv = re.escape(finalversion)
228 x_re = re.compile(r'^# NEWS for rsync %s \(UNRELEASED\)\s+## Changes in this version:\n' % efv
229 + r'(\n### PROTOCOL NUMBER:\s+- The protocol number was changed to \d+\.\n)?')
230 rel_day = 'UNRELEASED' if pre else today
231 repl = (f'# NEWS for rsync {finalversion} ({rel_day})\n\n'
232 + '## Changes in this version:\n')
234 repl += f'\n### PROTOCOL NUMBER:\n\n - The protocol number was changed to {protocol_version}.\n'
235 good_top = re.sub(r'\(.*?\)', '(UNRELEASED)', repl, 1)
236 msg = f"The top lines of {fn} are not in the right format. It should be:\n" + good_top
237 txt = replace_or_die(x_re, repl, txt, msg)
238 x_re = re.compile(r'^(\| )(\S{2} \S{3} \d{4})(\s+\|\s+%s\s+\| ).{11}(\s+\| )\S{2}(\s+\|+)$' % efv, re.M)
239 repl = lambda m: m[1] + (m[2] if pre else ztoday) + m[3] + proto_change_date + m[4] + protocol_version + m[5]
240 txt = replace_or_die(x_re, repl, txt, f'Unable to find "| ?? ??? {year} | {finalversion} | ... |" line in {fn}')
242 die(f"Unrecognized file in tweak_files: {fn}")
245 print(f"Updating {fn}")
246 with open(fn, 'w', encoding='utf-8') as fh:
249 cmd_chk(['packaging/year-tweak'])
252 cmd_run("git diff".split())
254 srctar_name = f"{rsync_ver}.tar.gz"
255 pattar_name = f"rsync-patches-{version}.tar.gz"
256 diff_name = f"{rsync_lastver}-{version}.diffs.gz"
257 srctar_file = os.path.join(dest, srcdir, srctar_name)
258 pattar_file = os.path.join(dest, srcdir, pattar_name)
259 diff_file = os.path.join(dest, srcdiffdir, diff_name)
260 lasttar_file = os.path.join(dest, lastsrcdir, rsync_lastver + '.tar.gz')
266 - git commit all changes
267 - run a full build, ensuring that the manpages & configure.sh are up-to-date
268 - merge the {args.master_branch} branch into the patch/{args.master_branch}/* branches
269 - update the files in the "patches" dir and OPTIONALLY (if you type 'y') to
270 run patch-update with the --make option (which opens a shell on error)
272 ans = input("<Press Enter OR 'y' to continue> ")
274 s = cmd_run(['git', 'commit', '-a', '-m', f'Preparing for release of {version} [buildall]'])
278 cmd_chk('touch configure.ac && packaging/smart-make && make gen')
280 print('Creating any missing patch branches.')
281 s = cmd_run(f'packaging/branch-from-patch --branch={args.master_branch} --add-missing')
285 print('Updating files in "patches" dir ...')
286 s = cmd_run(f'packaging/patch-update --branch={args.master_branch}')
290 if re.match(r'^y', ans, re.I):
291 print(f'\nRunning smart-make on all "patch/{args.master_branch}/*" branches ...')
292 cmd_run(f"packaging/patch-update --branch={args.master_branch} --skip-check --make")
294 if os.path.isdir('patches/.git'):
295 s = cmd_run(f"cd patches && git commit -a -m 'The patches for {version}.'")
303 - create signed tag for this release: {v_ver}
304 - create release diffs, "{diff_name}"
305 - create release tar, "{srctar_name}"
306 - generate {rsync_ver}/patches/* files
307 - create patches tar, "{pattar_name}"
308 - update top-level README.md, NEWS.md, TODO, and ChangeLog
309 - update top-level rsync*.html manpages
310 - gpg-sign the release files
311 - update hard-linked top-level release files{skipping}
313 ans = input("<Press Enter to continue> ")
315 # TODO: is there a better way to ensure that our passphrase is in the agent?
316 cmd_run("touch TeMp; gpg --sign TeMp; rm TeMp*")
318 out = cmd_txt(f"git tag -s -m 'Version {version}.' {v_ver}", capture='combined').out
320 if 'bad passphrase' in out or 'failed' in out:
323 if os.path.isdir('patches/.git'):
324 out = cmd_txt(f"cd patches && git tag -s -m 'Version {version}.' {v_ver}", capture='combined').out
326 if 'bad passphrase' in out or 'failed' in out:
329 os.environ['PATH'] = ORIGINAL_PATH
331 # Extract the generated files from the old tar.
332 tweaked_gen_files = [ os.path.join(rsync_lastver, fn) for fn in gen_files ]
333 cmd_run(['tar', 'xzf', lasttar_file, *tweaked_gen_files])
334 os.rename(rsync_lastver, 'a')
336 print(f"Creating {diff_file} ...")
337 cmd_chk(['rsync', '-a', *gen_pathnames, 'b/'])
339 sed_script = r's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:' # CAUTION: must not contain any single quotes!
340 cmd_chk(f"(git diff v{lastversion} {v_ver} -- ':!.github'; diff -upN a b | sed -r '{sed_script}') | gzip -9 >{diff_file}")
342 os.rename('b', rsync_ver)
344 print(f"Creating {srctar_file} ...")
345 cmd_chk(f"git archive --format=tar --prefix={rsync_ver}/ {v_ver} | tar xf -")
346 cmd_chk(f"support/git-set-file-times --quiet --prefix={rsync_ver}/")
347 cmd_chk(['fakeroot', 'tar', 'czf', srctar_file, '--exclude=.github', rsync_ver])
348 shutil.rmtree(rsync_ver)
350 print(f'Updating files in "{rsync_ver}/patches" dir ...')
351 os.mkdir(rsync_ver, 0o755)
352 os.mkdir(f"{rsync_ver}/patches", 0o755)
353 cmd_chk(f"packaging/patch-update --skip-check --branch={args.master_branch} --gen={rsync_ver}/patches".split())
355 print(f"Creating {pattar_file} ...")
356 cmd_chk(['fakeroot', 'tar', 'chzf', pattar_file, rsync_ver + '/patches'])
357 shutil.rmtree(rsync_ver)
359 print(f"Updating the other files in {dest} ...")
360 md_files = 'README.md NEWS.md INSTALL.md'.split()
361 html_files = [ fn for fn in gen_pathnames if fn.endswith('.html') ]
362 cmd_chk(['rsync', '-a', *md_files, *html_files, dest])
363 cmd_chk(["./md-convert", "--dest", dest, *md_files])
365 cmd_chk(f"git log --name-status | gzip -9 >{dest}/ChangeLog.gz")
367 for fn in (srctar_file, pattar_file, diff_file):
369 if os.path.lexists(asc_fn):
371 res = cmd_run(['gpg', '--batch', '-ba', fn])
372 if res.returncode != 0 and res.returncode != 2:
373 die("gpg signing failed")
376 for find in f'{dest}/rsync-*.gz {dest}/rsync-*.asc {dest}/src-previews/rsync-*diffs.gz*'.split():
377 for fn in glob.glob(find):
380 srctar_file, f"{srctar_file}.asc",
381 pattar_file, f"{pattar_file}.asc",
382 diff_file, f"{diff_file}.asc",
385 os.link(fn, re.sub(r'/src(-\w+)?/', '/', fn))
390 Local changes are done. When you're satisfied, push the git repository
391 and rsync the release files. Remember to announce the release on *BOTH*
392 rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
396 def replace_or_die(regex, repl, txt, die_msg):
397 m = regex.search(txt)
400 return regex.sub(repl, txt, 1)
403 def signal_handler(sig, frame):
404 die("\nAborting due to SIGINT.")
407 if __name__ == '__main__':
408 parser = argparse.ArgumentParser(description="Prepare a new release of rsync in the git repo & ftp dir.", add_help=False)
409 parser.add_argument('--branch', '-b', dest='master_branch', default='master', help="The branch to release. Default: master.")
410 parser.add_argument("--help", "-h", action="help", help="Output this help message and exit.")
411 args = parser.parse_args()
414 # vim: sw=4 et ft=python