chromium: update.py: Implement automatic committing of the updates
This functionality saves some unnecessary work. (cherry picked from commit e143dc53b23a56621a2da13cf8698bea7521f94a)
This commit is contained in:
parent
1361a07a95
commit
c46ea2796f
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
"""This script automatically updates chromium, google-chrome, chromedriver, and ungoogled-chromium
|
"""This script automatically updates chromium, google-chrome, chromedriver, and ungoogled-chromium
|
||||||
via upstream-info.json."""
|
via upstream-info.json."""
|
||||||
|
# Usage: ./update.py [--commit]
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
@ -22,6 +23,7 @@ DEB_URL = 'https://dl.google.com/linux/chrome/deb/pool/main/g'
|
|||||||
BUCKET_URL = 'https://commondatastorage.googleapis.com/chromium-browser-official'
|
BUCKET_URL = 'https://commondatastorage.googleapis.com/chromium-browser-official'
|
||||||
|
|
||||||
JSON_PATH = dirname(abspath(__file__)) + '/upstream-info.json'
|
JSON_PATH = dirname(abspath(__file__)) + '/upstream-info.json'
|
||||||
|
COMMIT_MESSAGE_SCRIPT = dirname(abspath(__file__)) + '/get-commit-message.py'
|
||||||
|
|
||||||
|
|
||||||
def load_json(path):
|
def load_json(path):
|
||||||
@ -117,6 +119,21 @@ def channel_name_to_attr_name(channel_name):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def get_channel_key(item):
|
||||||
|
"""Orders Chromium channels by their name."""
|
||||||
|
channel_name = item[0]
|
||||||
|
if channel_name == 'stable':
|
||||||
|
return 0
|
||||||
|
if channel_name == 'beta':
|
||||||
|
return 1
|
||||||
|
if channel_name == 'dev':
|
||||||
|
return 2
|
||||||
|
if channel_name == 'ungoogled-chromium':
|
||||||
|
return 3
|
||||||
|
print(f'Error: Unexpected channel: {channel_name}', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def print_updates(channels_old, channels_new):
|
def print_updates(channels_old, channels_new):
|
||||||
"""Print a summary of the updates."""
|
"""Print a summary of the updates."""
|
||||||
print('Updates:')
|
print('Updates:')
|
||||||
@ -192,21 +209,31 @@ with urlopen(HISTORY_URL) as resp:
|
|||||||
channels[channel_name] = channel
|
channels[channel_name] = channel
|
||||||
|
|
||||||
|
|
||||||
with open(JSON_PATH, 'w') as out:
|
sorted_channels = OrderedDict(sorted(channels.items(), key=get_channel_key))
|
||||||
def get_channel_key(item):
|
if len(sys.argv) == 2 and sys.argv[1] == '--commit':
|
||||||
"""Orders Chromium channels by their name."""
|
for channel_name in sorted_channels.keys():
|
||||||
channel_name = item[0]
|
version_old = last_channels[channel_name]['version']
|
||||||
if channel_name == 'stable':
|
version_new = sorted_channels[channel_name]['version']
|
||||||
return 0
|
if LooseVersion(version_old) < LooseVersion(version_new):
|
||||||
if channel_name == 'beta':
|
last_channels[channel_name] = sorted_channels[channel_name]
|
||||||
return 1
|
with open(JSON_PATH, 'w') as out:
|
||||||
if channel_name == 'dev':
|
json.dump(last_channels, out, indent=2)
|
||||||
return 2
|
out.write('\n')
|
||||||
if channel_name == 'ungoogled-chromium':
|
attr_name = channel_name_to_attr_name(channel_name)
|
||||||
return 3
|
commit_message = f'{attr_name}: {version_old} -> {version_new}'
|
||||||
print(f'Error: Unexpected channel: {channel_name}', file=sys.stderr)
|
if channel_name == 'stable':
|
||||||
sys.exit(1)
|
body = subprocess.check_output([COMMIT_MESSAGE_SCRIPT]).decode('utf-8')
|
||||||
sorted_channels = OrderedDict(sorted(channels.items(), key=get_channel_key))
|
prefix = f'chromium: TODO -> {version_new}'
|
||||||
json.dump(sorted_channels, out, indent=2)
|
if not body.startswith(prefix):
|
||||||
out.write('\n')
|
print("Error: Couldn't fetch the the release notes for the following update:")
|
||||||
|
print(commit_message)
|
||||||
|
sys.exit(1)
|
||||||
|
body = body.removeprefix(prefix)
|
||||||
|
commit_message += body
|
||||||
|
subprocess.run(['git', 'add', JSON_PATH], check=True)
|
||||||
|
subprocess.run(['git', 'commit', '--file=-'], input=commit_message.encode(), check=True)
|
||||||
|
else:
|
||||||
|
with open(JSON_PATH, 'w') as out:
|
||||||
|
json.dump(sorted_channels, out, indent=2)
|
||||||
|
out.write('\n')
|
||||||
print_updates(last_channels, sorted_channels)
|
print_updates(last_channels, sorted_channels)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user