Last active
January 18, 2019 16:26
-
-
Save dmikurube/15a8c024cd33ad89100204a2efbb26bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import re | |
import subprocess | |
import sys | |
RELEASE_NOTE_PATTERN = re.compile("release-([0-9]+\.[0-9]+\.[0-9]+)\.rst") | |
def extract_metadata_from_logline(line): | |
author_name, author_email, author_date, committer_name, committer_email, committer_date = line.split(";") | |
if author_name != committer_name: | |
raise " Author: %s / Committer: %s" % (author_name, committer_name) | |
if author_email != committer_email: | |
raise " Author: %s / Committer: %s" % (author_email, committer_email) | |
if author_date != committer_date: | |
print >> sys.stderr, " Author Date: %s / Committer Date: %s" % (author_date, committer_date) | |
return { | |
"GIT_AUTHOR_NAME": author_name, | |
"GIT_AUTHOR_EMAIL": author_email, | |
"GIT_AUTHOR_DATE": author_date, | |
"GIT_COMMITTER_NAME": committer_name, | |
"GIT_COMMITTER_EMAIL": committer_email, | |
"GIT_COMMITTER_DATE": committer_date, | |
} | |
def process_file(filename, version): | |
print >> sys.stderr, "%s, %s:" % (version, filename) | |
commit = subprocess.check_output(['git', 'show-ref', "v%s" % version]).split()[0] | |
log = subprocess.check_output(['git', 'log', '--pretty=format:%aN;%ae;%aI;%cN;%ce;%cI', filename]) | |
loglines = log.splitlines() | |
if len(loglines) > 1: | |
print >> sys.stderr, " Multiple commits on %s" % filename | |
environment_variables = dict(os.environ) | |
environment_variables.update(extract_metadata_from_logline(loglines[0])) | |
print subprocess.check_output(['git', 'tag', '-a', "v%s" % version, commit, "-f", "-F", filename], env=environment_variables) | |
def main(argv): | |
for filename in sorted(os.listdir(".")): | |
if filename.endswith(".rst"): | |
matched = RELEASE_NOTE_PATTERN.match(filename) | |
if matched: | |
process_file(filename, matched.group(1)) | |
else: | |
raise " Invalid filename: %s" % filename | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment