Debian Codegraph @

packaging/release.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 # Step-based release script for rsync. Each step is a separate invocation
4 # selected by a --step-N-XX option, so the maintainer drives the release
5 # manually one piece at a time.
6 #
7 # All persistent state and working files live in ../release/ (a sibling of
8 # the rsync git checkout):
9 #
10 # ../release/rsync-ftp/ mirror of samba.org:/home/ftp/pub/rsync
11 # ../release/rsync-html/ release-time snapshot of the html site
12 # ../release/work/ scratch space for tarball / diff staging
13 # ../release/release-state.json info shared between steps
14 #
15 # The rsync-patches archive is no longer maintained and has been dropped.
16 #
17 # Run "packaging/release.py --list" to see the step list.
18
19 import os, sys, re, argparse, glob, shutil, json, signal, subprocess
20 from datetime import datetime
21
22 sys.path = ['packaging'] + sys.path
23
24 from pkglib import (
25 warn, die, cmd_run, cmd_chk, cmd_txt, cmd_txt_chk, cmd_pipe,
26 check_git_state, get_rsync_version,
27 get_NEWS_version_info, get_protocol_versions,
28 )
29
30 # ---------- Paths ----------
31
32 RELEASE_DIR = os.path.realpath('../release')
33 FTP_DIR = os.path.join(RELEASE_DIR, 'rsync-ftp')
34 HTML_DIR = os.path.join(RELEASE_DIR, 'rsync-html')
35 WORK_DIR = os.path.join(RELEASE_DIR, 'work')
36 STATE_FILE = os.path.join(RELEASE_DIR, 'release-state.json')
37
38 # The rsync-web/ subdirectory in the rsync source tree is the source-of-truth
39 # for the git-tracked html content. step-1-fetch snapshots it into HTML_DIR
40 # for the release flow, where it can be edited or augmented with server-side
41 # content before step-11-push-html sends it to samba.org.
42 HTML_SRC = os.path.realpath('rsync-web')
43
44 FTP_REMOTE_PATH = '/home/ftp/pub/rsync'
45 HTML_REMOTE_PATH = '/home/httpd/html/rsync'
46
47 # Files that ./configure + make produce and that the release tarball / diff
48 # need to bundle alongside the git-tracked source. Mirrors the GENFILES
49 # definition in Makefile.in (with rrsync.1{,.html} since we always configure
50 # --with-rrsync in --step-4-build).
51 GEN_FILES = [
52 'configure.sh',
53 'aclocal.m4',
54 'config.h.in',
55 'rsync.1', 'rsync.1.html',
56 'rsync-ssl.1', 'rsync-ssl.1.html',
57 'rsyncd.conf.5', 'rsyncd.conf.5.html',
58 'rrsync.1', 'rrsync.1.html',
59 ]
60
61 # ---------- Step registry ----------
62
63 STEPS = [
64 ('step-1-fetch', 'mirror ../release/rsync-ftp from samba.org and snapshot ../release/rsync-html from rsync-web/'),
65 ('step-2-prepare', 'gather release info interactively and write release-state.json'),
66 ('step-3-tweak', 'update version.h, rsync.h, NEWS.md, and packaging/*.spec'),
67 ('step-4-build', 'run smart-make + make gen'),
68 ('step-5-commit', 'git commit -a (commit the prepared release changes)'),
69 ('step-6-tag', 'create the gpg-signed git tag'),
70 ('step-7-tarball', 'build the source tarball and diffs.gz against the previous release'),
71 ('step-8-update-ftp', 'refresh README/NEWS/INSTALL/html in the ftp dir, regen ChangeLog.gz, gpg-sign tarballs'),
72 ('step-9-toplinks', 'hard-link top-level release files (final releases only)'),
73 ('step-10-push-ftp', 'rsync ../release/rsync-ftp/ to samba.org'),
74 ('step-11-push-html', 'rsync ../release/rsync-html/ to samba.org (after any manual edits)'),
75 ('step-12-push-git', 'print the git push commands for you to run'),
76 ]
77 STEP_FLAGS = [s[0] for s in STEPS]
78
79 DASH_LINE = '=' * 74
80
81 # ---------- State helpers ----------
82
83 def load_state():
84 if not os.path.isfile(STATE_FILE):
85 die(f"{STATE_FILE} not found. Run --step-2-prepare first.")
86 with open(STATE_FILE, 'r', encoding='utf-8') as fh:
87 return json.load(fh)
88
89
90 def save_state(state):
91 os.makedirs(RELEASE_DIR, exist_ok=True)
92 with open(STATE_FILE, 'w', encoding='utf-8') as fh:
93 json.dump(state, fh, indent=2, sort_keys=True)
94 fh.write('\n')
95
96
97 def require_samba_host():
98 host = os.environ.get('RSYNC_SAMBA_HOST', '')
99 if not host.endswith('.samba.org'):
100 die("Set RSYNC_SAMBA_HOST in your environment to the samba hostname (e.g. hr3.samba.org).")
101 return host
102
103
104 def require_top_of_checkout():
105 if not os.path.isfile('packaging/release.py'):
106 die("Run this script from the top of your rsync checkout.")
107 if not os.path.exists('.git'):
108 die("There is no .git in the current directory (run from the top of a git checkout or worktree).")
109
110
111 def replace_or_die(regex, repl, txt, die_msg):
112 m = regex.search(txt)
113 if not m:
114 die(die_msg)
115 return regex.sub(repl, txt, 1)
116
117
118 def section(title):
119 print(f"\n{DASH_LINE}\n== {title}\n{DASH_LINE}")
120
121
122 def confirm(prompt, default_no=True):
123 suffix = '[n] ' if default_no else '[y] '
124 ans = input(f"{prompt} {suffix}").strip().lower()
125 if default_no:
126 return ans.startswith('y')
127 return ans == '' or ans.startswith('y')
128
129
130 # ---------- Step 1: fetch ftp + html ----------
131
132 def step_1_fetch(args):
133 host = require_samba_host()
134 os.makedirs(RELEASE_DIR, exist_ok=True)
135 os.makedirs(WORK_DIR, exist_ok=True)
136
137 section(f"Fetching ftp dir into {FTP_DIR}")
138 if not os.path.isdir(FTP_DIR):
139 os.makedirs(FTP_DIR)
140 # packaging/ftp.filt is the authoritative copy of the .filt filter file
141 # that controls which subtrees rsync excludes from the FTP mirror.
142 # Seed FTP_DIR/.filt from it so the bundled version is what step-1's
143 # rsync uses here, and so step-10-push-ftp propagates it back to the
144 # server. --exclude=/.filt below stops the server's copy from
145 # overwriting our bundled one on the way down.
146 filt = os.path.join(FTP_DIR, '.filt')
147 bundled_filt = os.path.realpath('packaging/ftp.filt')
148 if not os.path.isfile(bundled_filt):
149 die(f"{bundled_filt} not found; cannot seed .filt for the FTP pull.")
150 shutil.copyfile(bundled_filt, filt)
151 cmd_chk(['rsync', '-aivOHP', f'-f:_{filt}', '--exclude=/.filt',
152 f'{host}:{FTP_REMOTE_PATH}/', f'{FTP_DIR}/'])
153
154 section(f"Snapshotting html dir from {HTML_SRC} into {HTML_DIR}")
155 if not os.path.isdir(HTML_SRC):
156 die(f"{HTML_SRC} not found. This should be the in-tree rsync-web/ "
157 f"subdirectory; something is wrong with your checkout.")
158 os.makedirs(HTML_DIR, exist_ok=True)
159 cmd_chk(['rsync', '-aiv', f'{HTML_SRC}/', f'{HTML_DIR}/'])
160
161 # Then mirror non-git html content from the server, skipping files that
162 # the html git already provides (driven by the 'filt' file in HTML_DIR).
163 filt = os.path.join(HTML_DIR, 'filt')
164 if os.path.exists(filt):
165 tmp_filt = os.path.join(HTML_DIR, 'tmp-filt')
166 cmd_chk(f"sed -n -e 's/[-P]/H/p' '{filt}' >'{tmp_filt}'")
167 cmd_chk(['rsync', '-aivOHP', f'-f._{tmp_filt}',
168 f'{host}:{HTML_REMOTE_PATH}/', f'{HTML_DIR}/'])
169 os.unlink(tmp_filt)
170
171 print(f"\nFetch complete. Local dirs are now in {RELEASE_DIR}.")
172
173
174 # ---------- Step 2: prepare ----------
175
176 def step_2_prepare(args):
177 require_top_of_checkout()
178 os.makedirs(RELEASE_DIR, exist_ok=True)
179
180 if not os.path.isdir(FTP_DIR):
181 die(f"{FTP_DIR} does not exist. Run --step-1-fetch first.")
182
183 now = datetime.now().astimezone()
184 cl_today = now.strftime('* %a %b %d %Y')
185 year = now.strftime('%Y')
186 ztoday = now.strftime('%d %b %Y')
187 today = ztoday.lstrip('0')
188 tz_now = now.strftime('%z')
189 tz_num = tz_now[0:1].replace('+', '') + str(float(tz_now[1:3]) + float(tz_now[3:]) / 60)
190
191 curversion = get_rsync_version()
192 # Skip the version we are releasing: its NEWS entry may already be dated,
193 # in which case it would otherwise be taken for the previous release.
194 lastversion, last_protocol_version, pdate = get_NEWS_version_info(
195 skip_version=re.sub(r'(pre\d+|dev)$', '', curversion))
196 protocol_version, subprotocol_version = get_protocol_versions()
197
198 # Default next version: bump preN, or move dev -> pre1.
199 version = curversion
200 m = re.search(r'pre(\d+)', version)
201 if m:
202 version = re.sub(r'pre\d+', 'pre' + str(int(m[1]) + 1), version)
203 else:
204 version = version.replace('dev', 'pre1')
205
206 print(f"\nCurrent version (version.h): {curversion}")
207 print(f"Last released version (NEWS.md): {lastversion}")
208 print(f"Current protocol version: {protocol_version} (last released: {last_protocol_version})")
209
210 ans = input(f"\nVersion to release [{version}, '.' to drop the preN suffix]: ").strip()
211 if ans == '.':
212 version = re.sub(r'pre\d+', '', version)
213 elif ans:
214 version = ans
215 if not re.match(r'^[\d.]+(pre\d+)?$', version):
216 die(f'Invalid version: "{version}"')
217 version = re.sub(r'[-.]*pre[-.]*', 'pre', version)
218
219 if 'pre' in version and not curversion.endswith('dev'):
220 lastversion = curversion
221
222 ans = input(f"Previous version to diff against [{lastversion}]: ").strip()
223 if ans:
224 lastversion = ans
225 lastversion = re.sub(r'[-.]*pre[-.]*', 'pre', lastversion)
226
227 m = re.search(r'(pre\d+)', version)
228 pre = m[1] if m else ''
229 finalversion = re.sub(r'pre\d+', '', version)
230
231 release = '0.1' if pre else '1'
232 ans = input(f"RPM release number [{release}]: ").strip()
233 if ans:
234 release = ans
235 if pre:
236 release += '.' + pre
237
238 proto_changed = protocol_version != last_protocol_version
239 if proto_changed:
240 if finalversion in pdate:
241 proto_change_date = pdate[finalversion]
242 else:
243 while True:
244 ans = input(f"Date the protocol changed to {protocol_version} (dd Mmm yyyy): ").strip()
245 if re.match(r'^\d\d \w\w\w \d\d\d\d$', ans):
246 break
247 proto_change_date = ans
248 else:
249 proto_change_date = ' ' * 11
250
251 if 'pre' in lastversion:
252 if not pre:
253 die("Refusing to diff a release version against a pre-release version.")
254 srcdir = srcdiffdir = lastsrcdir = 'src-previews'
255 elif pre:
256 srcdir = srcdiffdir = 'src-previews'
257 lastsrcdir = 'src'
258 else:
259 srcdir = lastsrcdir = 'src'
260 srcdiffdir = 'src-diffs'
261
262 state = {
263 'version': version,
264 'lastversion': lastversion,
265 'finalversion': finalversion,
266 'pre': pre,
267 'release': release,
268 'protocol_version': protocol_version,
269 'subprotocol_version': subprotocol_version,
270 'proto_changed': proto_changed,
271 'proto_change_date': proto_change_date,
272 'srcdir': srcdir,
273 'srcdiffdir': srcdiffdir,
274 'lastsrcdir': lastsrcdir,
275 'today': today,
276 'ztoday': ztoday,
277 'cl_today': cl_today,
278 'year': year,
279 'tz_num': tz_num,
280 'master_branch': args.master_branch,
281 }
282 save_state(state)
283
284 section("Release info")
285 for k in ('version', 'lastversion', 'release', 'srcdir', 'srcdiffdir', 'lastsrcdir',
286 'protocol_version', 'proto_changed', 'proto_change_date'):
287 print(f" {k}: {state[k]}")
288 print(f"\nWrote {STATE_FILE}. Re-run --step-2-prepare to change anything.")
289
290
291 # ---------- Step 3: tweak version files ----------
292
293 def step_3_tweak(args):
294 require_top_of_checkout()
295 state = load_state()
296
297 version = state['version']
298 finalversion = state['finalversion']
299 pre = state['pre']
300 release = state['release']
301 today = state['today']
302 ztoday = state['ztoday']
303 cl_today = state['cl_today']
304 year = state['year']
305 tz_num = state['tz_num']
306 proto_changed = state['proto_changed']
307 proto_change_date = state['proto_change_date']
308 protocol_version = state['protocol_version']
309 srcdir = state['srcdir']
310
311 specvars = {
312 'Version:': finalversion,
313 'Release:': release,
314 '%define fullversion': f'%{{version}}{pre}',
315 'Released': version + '.',
316 '%define srcdir': srcdir,
317 }
318
319 tweak_files = ['version.h', 'rsync.h', 'NEWS.md']
320 tweak_files += glob.glob('packaging/*.spec')
321 tweak_files += glob.glob('packaging/*/*.spec')
322
323 for fn in tweak_files:
324 with open(fn, 'r', encoding='utf-8') as fh:
325 old_txt = txt = fh.read()
326 if fn == 'version.h':
327 x_re = re.compile(r'^(#define RSYNC_VERSION).*', re.M)
328 txt = replace_or_die(x_re, r'\1 "%s"' % version, txt,
329 f"Unable to update RSYNC_VERSION in {fn}")
330 x_re = re.compile(r'^(#define MAINTAINER_TZ_OFFSET).*', re.M)
331 txt = replace_or_die(x_re, r'\1 ' + tz_num, txt,
332 f"Unable to update MAINTAINER_TZ_OFFSET in {fn}")
333 elif fn == 'rsync.h':
334 x_re = re.compile(r'(#define\s+SUBPROTOCOL_VERSION)\s+(\d+)')
335 repl = lambda m: m[1] + ' ' + (
336 '0' if not pre or not proto_changed
337 else '1' if m[2] == '0'
338 else m[2])
339 txt = replace_or_die(x_re, repl, txt,
340 f"Unable to find SUBPROTOCOL_VERSION in {fn}")
341 elif fn == 'NEWS.md':
342 efv = re.escape(finalversion)
343 # Accept either "(UNRELEASED)" or an already-filled date, so a
344 # release entry that was dated by hand (or by an earlier run of
345 # this step) does not have to be reverted before releasing.
346 x_re = re.compile(
347 r'^# NEWS for rsync %s \((?:UNRELEASED|\d+ \w{3} \d{4})\)\s+## Changes in this version:\n' % efv
348 + r'(\n### PROTOCOL NUMBER:\s+- The protocol number was changed to \d+\.\n)?')
349 rel_day = 'UNRELEASED' if pre else today
350 repl = (f'# NEWS for rsync {finalversion} ({rel_day})\n\n'
351 + '## Changes in this version:\n')
352 if proto_changed:
353 repl += f'\n### PROTOCOL NUMBER:\n\n - The protocol number was changed to {protocol_version}.\n'
354 good_top = re.sub(r'\(.*?\)', '(UNRELEASED)', repl, 1)
355 msg = (f"The top of {fn} is not in the right format. It should be:\n" + good_top
356 + "(an already-filled release date in place of UNRELEASED is also accepted)")
357 txt = replace_or_die(x_re, repl, txt, msg)
358 x_re = re.compile(
359 r'^(\| )(\S{2} \S{3} \d{4})(\s+\|\s+%s\s+\| ).{11}(\s+\| )\S{2}(\s+\|+)$' % efv,
360 re.M)
361 repl = lambda m: (m[1] + (m[2] if pre else ztoday) + m[3]
362 + proto_change_date + m[4] + protocol_version + m[5])
363 txt = replace_or_die(x_re, repl, txt,
364 f'Unable to find "| ?? ??? {year} | {finalversion} | ... |" line in {fn}')
365 elif '.spec' in fn:
366 for var, val in specvars.items():
367 x_re = re.compile(r'^%s .*' % re.escape(var), re.M)
368 txt = replace_or_die(x_re, var + ' ' + val, txt,
369 f"Unable to update {var} in {fn}")
370 x_re = re.compile(r'^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)', re.M)
371 txt = replace_or_die(x_re, r'%s \1' % cl_today, txt,
372 f"Unable to update ChangeLog header in {fn}")
373 else:
374 die(f"Unrecognized file in tweak_files: {fn}")
375
376 if txt != old_txt:
377 print(f"Updating {fn}")
378 with open(fn, 'w', encoding='utf-8') as fh:
379 fh.write(txt)
380
381 cmd_chk(['packaging/year-tweak'])
382
383 section("git diff after tweaks")
384 cmd_run(['git', '--no-pager', 'diff'])
385
386
387 # ---------- Step 4: build ----------
388
389 def step_4_build(args):
390 require_top_of_checkout()
391 load_state() # just to ensure we've prepared
392
393 section("Running prepare-source + configure --prefix=/usr --with-rrsync + make + make gen")
394 # Always re-prepare so configure.sh is current; we run configure ourselves
395 # with the release-required flags rather than relying on the cached
396 # config.status (which may have been produced with different options).
397 if os.path.isfile('.fetch'):
398 cmd_chk(['./prepare-source', 'fetch'])
399 else:
400 cmd_chk(['./prepare-source'])
401
402 cmd_chk(['./configure', '--prefix=/usr', '--with-rrsync'])
403 cmd_chk(['make'])
404 cmd_chk(['make', 'gen'])
405
406
407 # ---------- Step 5: commit ----------
408
409 def step_5_commit(args):
410 require_top_of_checkout()
411 state = load_state()
412 version = state['version']
413
414 section("git status")
415 cmd_run(['git', 'status'])
416 if not confirm("Commit all current changes with the release message?"):
417 die("Aborted.")
418 cmd_chk(['git', 'commit', '-a', '-m', f'Preparing for release of {version} [buildall]'])
419
420
421 # ---------- Step 6: tag ----------
422
423 def step_6_tag(args):
424 require_top_of_checkout()
425 state = load_state()
426 version = state['version']
427 v_ver = 'v' + version
428
429 out = cmd_txt_chk(['git', 'tag', '-l', v_ver]).out
430 if out.strip():
431 if not confirm(f"Tag {v_ver} already exists. Delete and recreate?"):
432 die("Aborted.")
433 cmd_chk(['git', 'tag', '-d', v_ver])
434
435 # Prime the gpg agent so the actual tag signing won't prompt.
436 section("Priming gpg agent")
437 cmd_run("touch TeMp; gpg --sign TeMp; rm -f TeMp TeMp.gpg")
438
439 section(f"Creating signed tag {v_ver}")
440 out = cmd_txt(['git', 'tag', '-s', '-m', f'Version {version}.', v_ver],
441 capture='combined').out
442 print(out, end='')
443 if 'bad passphrase' in out.lower() or 'failed' in out.lower():
444 die("Tag creation failed.")
445
446
447 # ---------- Step 7: tarball + diff ----------
448
449 def step_7_tarball(args):
450 require_top_of_checkout()
451 state = load_state()
452
453 version = state['version']
454 lastversion = state['lastversion']
455 pre = state['pre']
456 srcdir = state['srcdir']
457 srcdiffdir = state['srcdiffdir']
458 lastsrcdir = state['lastsrcdir']
459
460 rsync_ver = 'rsync-' + version
461 rsync_lastver = 'rsync-' + lastversion
462 v_ver = 'v' + version
463
464 srctar_name = f"{rsync_ver}.tar.gz"
465 diff_name = f"{rsync_lastver}-{version}.diffs.gz"
466
467 srctar_file = os.path.join(FTP_DIR, srcdir, srctar_name)
468 diff_file = os.path.join(FTP_DIR, srcdiffdir, diff_name)
469 lasttar_file = os.path.join(FTP_DIR, lastsrcdir, rsync_lastver + '.tar.gz')
470
471 for d in (os.path.dirname(srctar_file), os.path.dirname(diff_file)):
472 os.makedirs(d, exist_ok=True)
473 if not os.path.isfile(lasttar_file):
474 die(f"Previous tarball not found: {lasttar_file}")
475
476 # Stage in ../release/work to keep the source checkout clean.
477 if os.path.isdir(WORK_DIR):
478 shutil.rmtree(WORK_DIR)
479 os.makedirs(WORK_DIR)
480
481 a_dir = os.path.join(WORK_DIR, 'a')
482 b_dir = os.path.join(WORK_DIR, 'b')
483
484 # Extract gen files from the previous tarball into work/a/.
485 tweaked_gen_files = [os.path.join(rsync_lastver, fn) for fn in GEN_FILES]
486 cmd_chk(['tar', '-C', WORK_DIR, '-xzf', lasttar_file, *tweaked_gen_files])
487 os.rename(os.path.join(WORK_DIR, rsync_lastver), a_dir)
488
489 # Copy current gen files (built in the top-level checkout) into work/b/.
490 os.makedirs(b_dir)
491 cmd_chk(['rsync', '-a', *GEN_FILES, b_dir + '/'])
492
493 section(f"Creating {diff_file}")
494 sed_script = r's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:' # no single quotes!
495 cmd_chk(
496 f"(git diff v{lastversion} {v_ver} -- ':!.github'; "
497 f"diff -upN {a_dir} {b_dir} | sed -r '{sed_script}') | gzip -9 >{diff_file}")
498
499 section(f"Creating {srctar_file}")
500 # Reuse work/b/ (which already holds the fresh gen files) as the release
501 # staging dir, then let "git archive" overlay the git-tracked source files
502 # on top. That way the tarball ends up with both gen files and source.
503 rsync_ver_dir = os.path.join(WORK_DIR, rsync_ver)
504 shutil.rmtree(a_dir)
505 os.rename(b_dir, rsync_ver_dir)
506 cmd_chk(f"git archive --format=tar --prefix={rsync_ver}/ {v_ver} | "
507 f"tar -C {WORK_DIR} -xf -")
508 cmd_chk(f"support/git-set-file-times --quiet --prefix={rsync_ver_dir}/")
509 cmd_chk(['fakeroot', 'tar', '-C', WORK_DIR, '-czf', srctar_file,
510 '--exclude=.github', rsync_ver])
511
512 # Leave staging in place; --step-8-update-ftp does its own thing.
513 print(f"\nCreated:\n {srctar_file}\n {diff_file}")
514
515
516 # ---------- Step 8: update ftp ----------
517
518 def step_8_update_ftp(args):
519 require_top_of_checkout()
520 state = load_state()
521
522 version = state['version']
523 lastversion = state['lastversion']
524 srcdir = state['srcdir']
525 srcdiffdir = state['srcdiffdir']
526
527 rsync_ver = 'rsync-' + version
528 rsync_lastver = 'rsync-' + lastversion
529 srctar_file = os.path.join(FTP_DIR, srcdir, f"{rsync_ver}.tar.gz")
530 diff_file = os.path.join(FTP_DIR, srcdiffdir,
531 f"{rsync_lastver}-{version}.diffs.gz")
532
533 section(f"Refreshing top-of-tree files in {FTP_DIR}")
534 md_files = ['README.md', 'NEWS.md', 'INSTALL.md']
535 html_files = [fn for fn in GEN_FILES if fn.endswith('.html')]
536 cmd_chk(['rsync', '-a', *md_files, *html_files, FTP_DIR + '/'])
537 cmd_chk(['./md-convert', '--dest', FTP_DIR, *md_files])
538
539 section(f"Regenerating {FTP_DIR}/ChangeLog.gz")
540 cmd_chk(f"git log --name-status | gzip -9 >{FTP_DIR}/ChangeLog.gz")
541
542 # Prime gpg agent and then sign the tar + diff.
543 section("Priming gpg agent")
544 cmd_run("touch TeMp; gpg --sign TeMp; rm -f TeMp TeMp.gpg")
545
546 for fn in (srctar_file, diff_file):
547 if not os.path.isfile(fn):
548 die(f"Missing file to sign: {fn}. Did --step-7-tarball run successfully?")
549 asc_fn = fn + '.asc'
550 if os.path.lexists(asc_fn):
551 os.unlink(asc_fn)
552 section(f"GPG-signing {fn}")
553 res = cmd_run(['gpg', '--batch', '-ba', fn])
554 if res.returncode not in (0, 2):
555 die("gpg signing failed.")
556
557
558 # ---------- Step 9: top-level hard links ----------
559
560 def step_9_toplinks(args):
561 require_top_of_checkout()
562 state = load_state()
563
564 pre = state['pre']
565 if pre:
566 print("Skipping: pre-releases do not get top-level hard links.")
567 return
568
569 version = state['version']
570 lastversion = state['lastversion']
571 srcdir = state['srcdir']
572 srcdiffdir = state['srcdiffdir']
573
574 rsync_ver = 'rsync-' + version
575 rsync_lastver = 'rsync-' + lastversion
576 srctar_file = os.path.join(FTP_DIR, srcdir, f"{rsync_ver}.tar.gz")
577 diff_file = os.path.join(FTP_DIR, srcdiffdir,
578 f"{rsync_lastver}-{version}.diffs.gz")
579
580 section("Removing stale top-level rsync-* files")
581 for find in [f'{FTP_DIR}/rsync-*.gz',
582 f'{FTP_DIR}/rsync-*.asc',
583 f'{FTP_DIR}/src-previews/rsync-*diffs.gz*']:
584 for fn in glob.glob(find):
585 os.unlink(fn)
586
587 top_link = [
588 srctar_file, srctar_file + '.asc',
589 diff_file, diff_file + '.asc',
590 ]
591 for fn in top_link:
592 target = re.sub(r'/src(-\w+)?/', '/', fn)
593 if os.path.lexists(target):
594 os.unlink(target)
595 os.link(fn, target)
596 print(f" linked {target}")
597
598
599 # ---------- Step 10: push ftp ----------
600
601 def step_10_push_ftp(args):
602 host = require_samba_host()
603 if not os.path.isdir(FTP_DIR):
604 die(f"{FTP_DIR} does not exist. Run --step-1-fetch first.")
605 section(f"rsync ftp dir to {host}")
606 rsync_with_confirm(['-aivOHP', '--chown=:rsync', '--del',
607 f'-f._{os.path.join(FTP_DIR, ".filt")}',
608 f'{FTP_DIR}/', f'{host}:{FTP_REMOTE_PATH}/'])
609
610
611 # ---------- Step 11: push html ----------
612
613 def step_11_push_html(args):
614 host = require_samba_host()
615 if not os.path.isdir(HTML_DIR):
616 die(f"{HTML_DIR} does not exist. Run --step-1-fetch first.")
617 section(f"rsync html dir to {host}")
618 filt = os.path.join(HTML_DIR, 'filt')
619 rsync_with_confirm(['-aivOHP', '--chown=:rsync', '--del',
620 f'-f._{filt}',
621 f'{HTML_DIR}/', f'{host}:{HTML_REMOTE_PATH}/'])
622
623
624 # ---------- Step 12: print push-git instructions ----------
625
626 def step_12_push_git(args):
627 state = load_state()
628 version = state['version']
629 master_branch = state['master_branch']
630 v_ver = 'v' + version
631
632 print(f"""\
633 {DASH_LINE}
634 Run these from the rsync-git checkout (this script does not push for you):
635
636 git push origin {master_branch}
637 git push origin {v_ver}
638
639 If you have a 'samba' remote configured (git.samba.org:/data/git/rsync.git):
640
641 git push samba {master_branch}
642 git push samba {v_ver}
643
644 Then upload the tarball + .asc to the GitHub release for {v_ver},
645 and announce on rsync-announce@, rsync@, and Discord.
646
647 NOTE! Also update the PPAs if needed
648 """)
649
650
651 # ---------- shared rsync-with-confirm ----------
652
653 def rsync_with_confirm(rsync_args):
654 """Run an rsync command in dry-run mode, then ask before running for real."""
655 cmd_run(['rsync', '--dry-run', *rsync_args])
656 if confirm("Run without --dry-run?"):
657 cmd_run(['rsync', *rsync_args])
658
659
660 # ---------- dispatch ----------
661
662 STEP_FUNCS = {
663 'step-1-fetch': step_1_fetch,
664 'step-2-prepare': step_2_prepare,
665 'step-3-tweak': step_3_tweak,
666 'step-4-build': step_4_build,
667 'step-5-commit': step_5_commit,
668 'step-6-tag': step_6_tag,
669 'step-7-tarball': step_7_tarball,
670 'step-8-update-ftp': step_8_update_ftp,
671 'step-9-toplinks': step_9_toplinks,
672 'step-10-push-ftp': step_10_push_ftp,
673 'step-11-push-html': step_11_push_html,
674 'step-12-push-git': step_12_push_git,
675 }
676
677
678 def signal_handler(sig, frame):
679 die("\nAborting due to SIGINT.")
680
681
682 def main():
683 parser = argparse.ArgumentParser(
684 description="Step-based release script for rsync.",
685 formatter_class=argparse.RawDescriptionHelpFormatter,
686 epilog="Run --list to see the steps. Each invocation runs exactly one --step-* option.")
687 parser.add_argument('--branch', '-b', dest='master_branch', default='master',
688 help="The branch to release (default: master).")
689 parser.add_argument('--list', action='store_true',
690 help="List all release steps and exit.")
691 grp = parser.add_mutually_exclusive_group()
692 for flag, descr in STEPS:
693 grp.add_argument('--' + flag, dest='step', action='store_const',
694 const=flag, help=descr)
695 args = parser.parse_args()
696
697 if args.list:
698 print("Release steps:")
699 for flag, descr in STEPS:
700 print(f" --{flag:18s} {descr}")
701 return
702
703 if not args.step:
704 parser.error("pick one --step-N-XX option (or --list to see them).")
705
706 signal.signal(signal.SIGINT, signal_handler)
707 os.environ['LESS'] = 'mqeiXR'
708 STEP_FUNCS[args.step](args)
709
710
711 if __name__ == '__main__':
712 main()
713
714 # vim: sw=4 et ft=python