fix changelog generator (#811)
This commit is contained in:
parent
bc383f6039
commit
bbc94a9dec
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -1,9 +1,26 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
<!-- markdownlint-disable MD024 -->
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
<!-- None < 2022-09-09 18:02:15+00:00 -->
|
||||||
|
|
||||||
|
### BLUEPRINTS
|
||||||
|
|
||||||
|
- [[#809](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/809)] Renaming and moving blueprints ([juliocc](https://github.com/juliocc)) <!-- 2022-09-12 10:19:15+00:00 -->
|
||||||
|
|
||||||
|
### DOCUMENTATION
|
||||||
|
|
||||||
|
- [[#806](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/806)] Companion Guide ([ajlopezn](https://github.com/ajlopezn)) <!-- 2022-09-12 07:11:03+00:00 -->
|
||||||
|
|
||||||
|
### FAST
|
||||||
|
|
||||||
|
- [[#807](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/807)] FAST: refactor Gitlab template ([ludoo](https://github.com/ludoo)) <!-- 2022-09-12 05:26:49+00:00 -->
|
||||||
|
|
||||||
|
### TOOLS
|
||||||
|
|
||||||
|
- [[#810](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/810)] Fully recursive e2e test runner for examples ([juliocc](https://github.com/juliocc)) <!-- 2022-09-12 12:35:46+00:00 -->
|
||||||
|
|
||||||
## [18.0.0] - 2022-09-09
|
## [18.0.0] - 2022-09-09
|
||||||
|
|
||||||
|
@ -119,7 +136,6 @@ All notable changes to this project will be documented in this file.
|
||||||
- [[#680](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/680)] Tools: fix `ValueError` raised in `check_names.py` when overlong names are detected ([27Bslash6](https://github.com/27Bslash6)) <!-- 2022-06-16 08:01:59+00:00 -->
|
- [[#680](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/680)] Tools: fix `ValueError` raised in `check_names.py` when overlong names are detected ([27Bslash6](https://github.com/27Bslash6)) <!-- 2022-06-16 08:01:59+00:00 -->
|
||||||
- [[#672](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/672)] Module attribution and version updater tool, plus release automation ([rosmo](https://github.com/rosmo)) <!-- 2022-06-09 11:40:50+00:00 -->
|
- [[#672](https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/pull/672)] Module attribution and version updater tool, plus release automation ([rosmo](https://github.com/rosmo)) <!-- 2022-06-09 11:40:50+00:00 -->
|
||||||
|
|
||||||
|
|
||||||
## [16.0.0] - 2022-06-06
|
## [16.0.0] - 2022-06-06
|
||||||
|
|
||||||
- add support for [Spot VMs](https://cloud.google.com/compute/docs/instances/spot) to `gke-nodepool` module
|
- add support for [Spot VMs](https://cloud.google.com/compute/docs/instances/spot) to `gke-nodepool` module
|
||||||
|
@ -611,7 +627,6 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
- merge development branch with suite of new modules and end-to-end examples
|
- merge development branch with suite of new modules and end-to-end examples
|
||||||
|
|
||||||
|
|
||||||
<!-- markdown-link-check-disable -->
|
<!-- markdown-link-check-disable -->
|
||||||
[Unreleased]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v18.0.0...HEAD
|
[Unreleased]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v18.0.0...HEAD
|
||||||
[18.0.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v16.0.0...v18.0.0
|
[18.0.0]: https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/compare/v16.0.0...v18.0.0
|
||||||
|
|
|
@ -19,13 +19,17 @@ import collections
|
||||||
import ghapi.all
|
import ghapi.all
|
||||||
import iso8601
|
import iso8601
|
||||||
|
|
||||||
|
LINK_MARKER = '<!-- markdown-link-check-disable -->'
|
||||||
ORG = 'GoogleCloudPlatform'
|
ORG = 'GoogleCloudPlatform'
|
||||||
REPO = 'cloud-foundation-fabric'
|
REPO = 'cloud-foundation-fabric'
|
||||||
URL = f'https://github.com/{ORG}/{REPO}'
|
URL = f'https://github.com/{ORG}/{REPO}'
|
||||||
|
|
||||||
PullRequest = collections.namedtuple('PullRequest',
|
PullRequest = collections.namedtuple('PullRequest',
|
||||||
'id author title merged_at labels')
|
'id author title merged_at labels')
|
||||||
Release = collections.namedtuple('Release', 'name published since pulls')
|
FileRelease = collections.namedtuple('FileRelease',
|
||||||
|
'name published since content')
|
||||||
|
GitRelease = collections.namedtuple('GitRelease', 'name published since pulls')
|
||||||
|
Section = collections.namedtuple('Section', 'text')
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
|
@ -51,39 +55,41 @@ def changelog_load(path):
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
for l in f.readlines():
|
for l in f.readlines():
|
||||||
l = l.strip()
|
l = l.strip()
|
||||||
|
if l.startswith(LINK_MARKER):
|
||||||
|
break
|
||||||
if l.startswith('## '):
|
if l.startswith('## '):
|
||||||
name, _, date = l[3:].partition(' - ')
|
name, _, date = l[3:].partition(' - ')
|
||||||
releases.append(Release(name[1:-1], date, None, []))
|
releases.append(FileRelease(name[1:-1], date, None, []))
|
||||||
elif l.startswith('- '):
|
elif releases:
|
||||||
if not releases:
|
releases[-1].content.append(l)
|
||||||
raise Error(f'Pull found with no releases: {l}')
|
|
||||||
releases[-1].pulls.append(l)
|
|
||||||
return releases
|
return releases
|
||||||
except (IOError, OSError) as e:
|
except (IOError, OSError) as e:
|
||||||
raise Error(f'Cannot open {path}: {e.args[0]}')
|
raise Error(f'Cannot open {path}: {e.args[0]}')
|
||||||
|
|
||||||
|
|
||||||
def changelog_dumps(releases, overrides=None):
|
def changelog_dumps(file_releases, git_releases=None):
|
||||||
'Return formatted changelog from structured data, overriding versions.'
|
'Return formatted changelog from structured data, overriding versions.'
|
||||||
overrides = overrides or {}
|
git_releases = git_releases or {}
|
||||||
buffer = [
|
buffer = [
|
||||||
('# Changelog\n\n'
|
('# Changelog\n\n'
|
||||||
'All notable changes to this project will be documented in this file.\n')
|
'All notable changes to this project will be documented in this file.\n'
|
||||||
|
'<!-- markdownlint-disable MD024 -->\n')
|
||||||
]
|
]
|
||||||
ref_buffer = ['<!-- markdown-link-check-disable -->']
|
ref_buffer = ['<!-- markdown-link-check-disable -->']
|
||||||
for i, release in enumerate(releases):
|
for i, release in enumerate(file_releases):
|
||||||
name, published, _, pulls = release
|
name, published, _, items = release
|
||||||
prev_name = releases[i + 1].name if i + 1 < len(releases) else '0.1'
|
prev_name = file_releases[i +
|
||||||
|
1].name if i + 1 < len(file_releases) else '0.1'
|
||||||
if name != 'Unreleased':
|
if name != 'Unreleased':
|
||||||
buffer.append(f'## [{name}] - {published}\n')
|
buffer.append(f'## [{name}] - {published}')
|
||||||
ref_buffer.append(f'[{name}]: {URL}/compare/v{prev_name}...v{name}')
|
ref_buffer.append(f'[{name}]: {URL}/compare/v{prev_name}...v{name}')
|
||||||
else:
|
else:
|
||||||
buffer.append(f'## [{name}]\n')
|
buffer.append(f'## [{name}]')
|
||||||
ref_buffer.append(f'[Unreleased]: {URL}/compare/v{prev_name}...HEAD')
|
ref_buffer.append(f'[Unreleased]: {URL}/compare/v{prev_name}...HEAD')
|
||||||
override = overrides.get(name, overrides.get(f'v{name}'))
|
release = git_releases.get(name, git_releases.get(f'v{name}'))
|
||||||
if override:
|
if release:
|
||||||
buffer.append(f'<!-- {override.published} < {override.since} -->\n')
|
buffer.append(f'<!-- {release.published} < {release.since} -->')
|
||||||
pulls = group_pulls(override.pulls)
|
pulls = group_pulls(release.pulls)
|
||||||
for k in sorted(pulls.keys(), key=lambda s: s or ''):
|
for k in sorted(pulls.keys(), key=lambda s: s or ''):
|
||||||
if k is not None:
|
if k is not None:
|
||||||
buffer.append(f'### {k}\n')
|
buffer.append(f'### {k}\n')
|
||||||
|
@ -91,10 +97,8 @@ def changelog_dumps(releases, overrides=None):
|
||||||
buffer.append(format_pull(pull))
|
buffer.append(format_pull(pull))
|
||||||
buffer.append('')
|
buffer.append('')
|
||||||
else:
|
else:
|
||||||
for pull in pulls:
|
buffer.append('\n'.join(items))
|
||||||
buffer.append(pull)
|
return '\n'.join(buffer + ref_buffer + [''])
|
||||||
buffer.append('')
|
|
||||||
return '\n'.join(buffer + [''] + ref_buffer)
|
|
||||||
|
|
||||||
|
|
||||||
def format_pull(pull):
|
def format_pull(pull):
|
||||||
|
@ -157,10 +161,10 @@ def get_releases(api, filter_names=None):
|
||||||
for r in _paginate(api.repos.list_releases):
|
for r in _paginate(api.repos.list_releases):
|
||||||
published = iso8601.parse_date(r['published_at'])
|
published = iso8601.parse_date(r['published_at'])
|
||||||
if not filter_names or buffer.name in filter_names:
|
if not filter_names or buffer.name in filter_names:
|
||||||
yield Release(buffer.name, buffer.published, published, [])
|
yield GitRelease(buffer.name, buffer.published, published, [])
|
||||||
buffer = Buffer(r['name'], published)
|
buffer = Buffer(r['name'], published)
|
||||||
if buffer and (not filter_names or buffer.name in filter_names):
|
if buffer and (not filter_names or buffer.name in filter_names):
|
||||||
yield Release(buffer.name, buffer.published, None, [])
|
yield GitRelease(buffer.name, buffer.published, None, [])
|
||||||
|
|
||||||
|
|
||||||
@click.command
|
@click.command
|
||||||
|
@ -172,7 +176,7 @@ def get_releases(api, filter_names=None):
|
||||||
)
|
)
|
||||||
@click.option('--token', required=True, envvar='GH_TOKEN',
|
@click.option('--token', required=True, envvar='GH_TOKEN',
|
||||||
help='GitHub API token.')
|
help='GitHub API token.')
|
||||||
@click.option('--write/-w', is_flag=True, required=False, default=False,
|
@click.option('--write', '-w', is_flag=True, required=False, default=False,
|
||||||
help='Write modified changelog file.')
|
help='Write modified changelog file.')
|
||||||
@click.argument('changelog', required=False, default='CHANGELOG.md',
|
@click.argument('changelog', required=False, default='CHANGELOG.md',
|
||||||
type=click.Path(exists=True))
|
type=click.Path(exists=True))
|
||||||
|
|
Loading…
Reference in New Issue