2019-04-08 16:01:54 +00:00
|
|
|
import collections
|
|
|
|
import copy
|
|
|
|
import io
|
|
|
|
import logging
|
|
|
|
import os
|
2020-06-29 11:57:21 +00:00
|
|
|
import random
|
2020-01-29 13:34:12 +00:00
|
|
|
import sys
|
2019-04-08 16:01:54 +00:00
|
|
|
import tarfile
|
2020-06-29 11:57:21 +00:00
|
|
|
import time
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
import util
|
|
|
|
|
|
|
|
|
2020-04-15 13:35:16 +00:00
|
|
|
def yield_candidates():
|
|
|
|
for page in range(1, 100):
|
2020-05-08 08:04:09 +00:00
|
|
|
url = f'https://api.github.com/repos/ClickHouse/ClickHouse/tags?per_page=100&page={page}'
|
2020-06-29 11:57:21 +00:00
|
|
|
github_token = os.getenv('GITHUB_TOKEN')
|
|
|
|
if github_token:
|
|
|
|
headers = {'authorization': f'OAuth {github_token}'}
|
|
|
|
else:
|
|
|
|
headers = {}
|
|
|
|
for candidate in requests.get(url, headers=headers).json():
|
2020-04-15 13:35:16 +00:00
|
|
|
yield candidate
|
2020-06-29 11:57:21 +00:00
|
|
|
time.sleep(random.random() * 3)
|
2020-04-15 13:35:16 +00:00
|
|
|
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
def choose_latest_releases(args):
|
2020-03-19 06:28:58 +00:00
|
|
|
logging.info('Collecting release candidates')
|
2020-06-29 11:57:21 +00:00
|
|
|
seen_stable = collections.OrderedDict()
|
|
|
|
seen_lts = collections.OrderedDict()
|
2020-01-28 10:18:09 +00:00
|
|
|
candidates = []
|
2020-04-15 13:35:16 +00:00
|
|
|
stable_count = 0
|
|
|
|
lts_count = 0
|
2020-01-28 10:18:09 +00:00
|
|
|
|
2020-04-15 13:35:16 +00:00
|
|
|
for tag in yield_candidates():
|
2020-01-29 13:34:12 +00:00
|
|
|
if isinstance(tag, dict):
|
|
|
|
name = tag.get('name', '')
|
2020-04-15 13:35:16 +00:00
|
|
|
is_stable = 'stable' in name
|
|
|
|
is_lts = 'lts' in name
|
|
|
|
is_unstable = not (is_stable or is_lts)
|
2020-01-29 13:34:12 +00:00
|
|
|
is_in_blacklist = ('v18' in name) or ('prestable' in name) or ('v1.1' in name)
|
|
|
|
if is_unstable or is_in_blacklist:
|
|
|
|
continue
|
|
|
|
major_version = '.'.join((name.split('.', 2))[:2])
|
2020-06-29 11:57:21 +00:00
|
|
|
if major_version not in seen_lts:
|
2020-04-15 13:35:16 +00:00
|
|
|
if (stable_count >= args.stable_releases_limit) and (lts_count >= args.lts_releases_limit):
|
2020-01-29 13:34:12 +00:00
|
|
|
break
|
2020-04-15 13:35:16 +00:00
|
|
|
|
|
|
|
payload = (name, tag.get('tarball_url'), is_lts,)
|
2020-06-29 11:57:21 +00:00
|
|
|
logging.debug(payload)
|
2020-04-15 13:35:16 +00:00
|
|
|
if is_lts:
|
|
|
|
if lts_count < args.lts_releases_limit:
|
2020-06-29 11:57:21 +00:00
|
|
|
seen_lts[major_version] = payload
|
|
|
|
try:
|
|
|
|
del seen_stable[major_version]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2020-04-15 13:35:16 +00:00
|
|
|
lts_count += 1
|
|
|
|
else:
|
|
|
|
if stable_count < args.stable_releases_limit:
|
2020-06-29 11:57:21 +00:00
|
|
|
if major_version not in seen_stable:
|
|
|
|
seen_stable[major_version] = payload
|
|
|
|
stable_count += 1
|
2020-04-15 13:35:16 +00:00
|
|
|
|
|
|
|
logging.debug(
|
|
|
|
f'Stables: {stable_count}/{args.stable_releases_limit} LTS: {lts_count}/{args.lts_releases_limit}'
|
|
|
|
)
|
2020-01-29 13:34:12 +00:00
|
|
|
else:
|
|
|
|
logging.fatal('Unexpected GitHub response: %s', str(candidates))
|
|
|
|
sys.exit(1)
|
|
|
|
|
2020-06-29 11:57:21 +00:00
|
|
|
logging.info('Found LTS releases: %s', ', '.join(seen_lts.keys()))
|
|
|
|
logging.info('Found stable releases: %s', ', '.join(seen_stable.keys()))
|
|
|
|
return sorted(list(seen_lts.items()) + list(seen_stable.items()))
|
2020-03-13 19:35:03 +00:00
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
|
|
def process_release(args, callback, release):
|
2020-04-15 13:35:16 +00:00
|
|
|
name, (full_name, tarball_url, is_lts,) = release
|
|
|
|
logging.info(f'Building docs for {full_name}')
|
2019-04-08 16:01:54 +00:00
|
|
|
buf = io.BytesIO(requests.get(tarball_url).content)
|
|
|
|
tar = tarfile.open(mode='r:gz', fileobj=buf)
|
|
|
|
with util.temp_dir() as base_dir:
|
|
|
|
tar.extractall(base_dir)
|
2020-03-19 06:28:58 +00:00
|
|
|
args = copy.copy(args)
|
2019-04-08 16:01:54 +00:00
|
|
|
args.version_prefix = name
|
2019-12-10 08:15:38 +00:00
|
|
|
args.is_stable_release = True
|
2019-04-08 16:01:54 +00:00
|
|
|
args.docs_dir = os.path.join(base_dir, os.listdir(base_dir)[0], 'docs')
|
2020-03-30 08:25:29 +00:00
|
|
|
callback(args)
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def build_releases(args, callback):
|
|
|
|
for release in args.stable_releases:
|
2020-01-29 16:03:20 +00:00
|
|
|
process_release(args, callback, release)
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
|
|
|
2020-03-13 19:35:03 +00:00
|
|
|
def get_events(args):
|
|
|
|
events = []
|
|
|
|
skip = True
|
|
|
|
with open(os.path.join(args.docs_dir, '..', 'README.md')) as f:
|
|
|
|
for line in f:
|
|
|
|
if skip:
|
|
|
|
if 'Upcoming Events' in line:
|
|
|
|
skip = False
|
|
|
|
else:
|
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
line = line.strip().split('](')
|
|
|
|
if len(line) == 2:
|
|
|
|
tail = line[1].split(') ')
|
|
|
|
events.append({
|
|
|
|
'signup_link': tail[0],
|
|
|
|
'event_name': line[0].replace('* [', ''),
|
|
|
|
'event_date': tail[1].replace('on ', '').replace('.', '')
|
|
|
|
})
|
|
|
|
return events
|
2020-04-15 13:35:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
class DummyArgs(object):
|
|
|
|
lts_releases_limit = 1
|
|
|
|
stable_releases_limit = 3
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.DEBUG,
|
|
|
|
stream=sys.stderr
|
|
|
|
)
|
|
|
|
for item in choose_latest_releases(DummyArgs()):
|
|
|
|
print(item)
|