Skip to content

Commit

Permalink
chore(buildtool): Auto-deprecate old Spinnaker versions (#43) (#57)
Browse files Browse the repository at this point in the history
The publish_changelog function in the buildtool currently
publishes a new changelog for the newly-released Spinnaker version.
After publishing a patch version, the release manager needs to
manually edit the spinnaker.github.io repository to deprecate the
prior patch version, which is unnecessary manual toil.

This change updates the publish_changelog so that, in addition to
publishing a new changelog, it also deprecates the changelog
corresponding to the prior patch release. If this is the first
patch release of a minor version, it will short-circuit and will
not deprecate anything. (Maybe at some point we could update it
to deprecate the last patch release of the N-3 minor version but
for now that will stay manual.)

This also adds a newline at the end of each generated changelog,
as this always gets added when eventually deprecating it (whether
manually or via this script), increasing the diff.

Co-authored-by: Eric Zimanyi <ezimanyi@google.com>
  • Loading branch information
spinnakerbot and ezimanyi committed Mar 20, 2020
1 parent c85b194 commit 4108511
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion dev/buildtool/changelog_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import collections
import copy
import datetime
import fileinput
import logging
import os
import re
Expand Down Expand Up @@ -450,6 +451,17 @@ def prepare_local_repository_files(self, repository):
if repository.name != SPINNAKER_GITHUB_IO_REPOSITORY_NAME:
raise_and_log_error(UnexpectedError('Got "%s"' % repository.name))

updated_files = []
new_version = self.write_new_version(repository)
updated_files.append(new_version)

old_version = self.deprecate_prior_version(repository)
if old_version is not None:
updated_files.append(old_version)

return updated_files

def write_new_version(self, repository):
timestamp = '{:%Y-%m-%d %H:%M:%S +0000}'.format(datetime.datetime.utcnow())
version = self.options.spinnaker_version
changelog_filename = '{version}-changelog.md'.format(version=version)
Expand All @@ -474,9 +486,33 @@ def prepare_local_repository_files(self, repository):
major=major, minor=minor))
f.write(header)
f.write('<script src="%s.js"/>' % self.options.changelog_gist_url)
f.write('\n')

return target_path

return [target_path]
def get_prior_version(self, version):
major, minor, patch = version.split('.')
patch = int(patch)
if patch == 0:
return None
return '.'.join([major, minor, str(patch - 1)])

def deprecate_prior_version(self, repository):
priorVersion = self.get_prior_version(self.options.spinnaker_version)
if priorVersion is None:
return None

changelog_filename = '{version}-changelog.md'.format(version=priorVersion)
target_path = os.path.join(repository.git_dir,
'_changelogs', changelog_filename)

logging.debug('Deprecating prior version %s', target_path)
for line in fileinput.input(target_path, inplace=True):
line = line.rstrip()
if line.startswith('tags: '):
line = line + ' deprecated'
print(line)
return target_path

class PushChangelogFactory(CommandFactory):
def __init__(self, **kwargs):
Expand Down

0 comments on commit 4108511

Please sign in to comment.