diff --git a/hack/backfill.py b/hack/backfill.py deleted file mode 100755 index 49b66d738..000000000 --- a/hack/backfill.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python3 - -import functools -import re - -import yaml - - -SEMVER = re.compile('^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$') - - -def version_key(v, minor): - match = SEMVER.match(v) - groups = match.groupdict() - v_minor = int(groups['minor']) - v_patch = int(groups['patch']) - if v_minor != minor: - v_patch = -v_patch - return (int(groups['major']), v_minor, v_patch, v) - - -data = {} -minors = [3, 4, 5, 6] -weights = ['candidate', 'fast', 'stable'] -for minor in minors: - data[minor] = {} - for weight in weights: - with open('channels/{}-4.{}.yaml'.format(weight, minor)) as f: - data[minor][weight] = yaml.safe_load(f) - -for minor, next_minor in zip(minors, minors[1:]): - for weight in weights: - versions = set(data[minor][weight]['versions']) - versions.update(v for v in data[next_minor][weight]['versions'] if v.startswith('4.{}.'.format(minor))) - data[minor][weight]['versions'] = sorted(versions, key=functools.partial(version_key, minor=minor)) - - versions = set(data[next_minor][weight]['versions']) - versions.update(v for v in data[minor][weight]['versions'] if v.startswith('4.{}.'.format(minor))) - data[next_minor][weight]['versions'] = sorted(versions, key=functools.partial(version_key, minor=next_minor)) - -for minor in minors: - for weight in weights: - with open('channels/{}-4.{}.yaml'.format(weight, minor), 'w') as f: - yaml.safe_dump(data[minor][weight], f, default_flow_style=False) diff --git a/hack/stabilization-changes.py b/hack/stabilization-changes.py index a9cc7c22f..ad83f0c17 100755 --- a/hack/stabilization-changes.py +++ b/hack/stabilization-changes.py @@ -315,28 +315,27 @@ def notify(message, webhook=None): def promote(version, channel_name, channel_path, subject, body, github_repo, github_token, upstream_remote, upstream_branch): - if not github_token: - raise ValueError('cannot promote without a configured GitHub token') - - process = subprocess.run(['git', 'remote', 'get-url', '--push', upstream_remote], check=True, capture_output=True, text=True) - upstream_uri = urllib.parse.urlsplit(process.stdout.strip()) - if upstream_uri.scheme != 'https': - raise ValueError('pushing by token requires HTTPS for security, so cannot use {} scheme {}'.format(upstream_remote, upstream_uri.scheme)) - _, have_user_info, host_info = upstream_uri.netloc.rpartition('@') - if have_user_info: - raise ValueError('remote {} configured with user info is not supported, because we expect to authenticate with the configured GitHub token'.format(upstream_remote)) - upstream_uri_with_token = urllib.parse.urlunsplit(upstream_uri._replace(netloc='{}@{}'.format(github_token, host_info))) - - subprocess.run(['git', 'fetch', upstream_remote], check=True) - branch = 'promote-{}-to-{}'.format(version, channel_name) - try: - subprocess.run(['git', 'show', branch], check=True, capture_output=True, text=True) - except subprocess.CalledProcessError as error: - if 'unknown revision or path not in the working tree' not in error.stderr: - raise - else: - raise ValueError('branch {} already exists; possibly waiting for an open pull request to merge'.format(branch)) - subprocess.run(['git', 'checkout', '-b', branch, '{}/{}'.format(upstream_remote, upstream_branch)], check=True) + if github_token: + process = subprocess.run(['git', 'remote', 'get-url', '--push', upstream_remote], check=True, capture_output=True, text=True) + upstream_uri = urllib.parse.urlsplit(process.stdout.strip()) + if upstream_uri.scheme != 'https': + raise ValueError('pushing by token requires HTTPS for security, so cannot use {} scheme {}'.format(upstream_remote, upstream_uri.scheme)) + _, have_user_info, host_info = upstream_uri.netloc.rpartition('@') + if have_user_info: + raise ValueError('remote {} configured with user info is not supported, because we expect to authenticate with the configured GitHub token'.format(upstream_remote)) + upstream_uri_with_token = urllib.parse.urlunsplit(upstream_uri._replace(netloc='{}@{}'.format(github_token, host_info))) + + subprocess.run(['git', 'fetch', upstream_remote], check=True) + branch = 'promote-{}-to-{}'.format(version, channel_name) + try: + subprocess.run(['git', 'show', branch], check=True, capture_output=True, text=True) + except subprocess.CalledProcessError as error: + if 'unknown revision or path not in the working tree' not in error.stderr: + raise + else: + raise ValueError('branch {} already exists; possibly waiting for an open pull request to merge'.format(branch)) + subprocess.run(['git', 'checkout', '-b', branch, '{}/{}'.format(upstream_remote, upstream_branch)], check=True) + with open(channel_path) as f: try: data = yaml.load(f, Loader=yaml.SafeLoader) @@ -350,6 +349,12 @@ def promote(version, channel_name, channel_path, subject, body, github_repo, git with open(channel_path, 'w') as f: yaml.safe_dump(data, f, default_flow_style=False) message = '{}\n\n{}\n'.format(subject, textwrap.fill(body, width=76)) + + if not github_token: + pull = github.PullRequest + pull.html_url = 'data://no-token-so-no-pull' + return pull + subprocess.run(['git', 'commit', '--file', '-', channel_path], check=True, encoding='utf-8', input=message) subprocess.run(['git', 'push', '-u', upstream_uri_with_token, branch], check=True)