Skip to content

Commit e93a910

Browse files
committed
Updated to latest version of github release script. Now robust to blanks in changelog sections and able to upload files.
1 parent 1cc0a85 commit e93a910

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

ci_tools/github_release.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# a clone of the ruby example https://gist.github.com/valeriomazzeo/5491aee76f758f7352e2e6611ce87ec1
22
import os
3+
from os import path
4+
35
import re
46

57
import click
8+
from click import Path
69
from github import Github, UnknownObjectException
710
# from valid8 import validate not compliant with python 2.7
811

@@ -14,8 +17,10 @@
1417
@click.option('-r', '--repo-slug', help='Repo slug. i.e.: apple/swift')
1518
@click.option('-cf', '--changelog-file', help='Changelog file path')
1619
@click.option('-d', '--doc-url', help='Documentation url')
20+
@click.option('-df', '--data-file', help='Data file to upload', type=Path(exists=True, file_okay=True, dir_okay=False,
21+
resolve_path=True))
1722
@click.argument('tag')
18-
def create_or_update_release(user, pwd, secret, repo_slug, changelog_file, doc_url, tag):
23+
def create_or_update_release(user, pwd, secret, repo_slug, changelog_file, doc_url, data_file, tag):
1924
"""
2025
Creates or updates (TODO)
2126
a github release corresponding to git tag <TAG>.
@@ -38,7 +43,7 @@ def create_or_update_release(user, pwd, secret, repo_slug, changelog_file, doc_u
3843
click.echo("Logged in as {user_name}".format(user_name=g.get_user()))
3944

4045
# 2- CHANGELOG VALIDATION
41-
regex_pattern = "[\s\S]*[\n][#]+[\s]*(?P<title>[\S ]*%s[\S ]*)[\n]+(?P<body>[\s\S]*?)[\n]*(\n#|$)" % re.escape(tag)
46+
regex_pattern = "[\s\S]*[\n][#]+[\s]*(?P<title>[\S ]*%s[\S ]*)[\n]+?(?P<body>[\s\S]*?)[\n]*?(\n#|$)" % re.escape(tag)
4247
changelog_section = re.compile(regex_pattern)
4348
if changelog_file is not None:
4449
# validate('changelog_file', changelog_file, custom=os.path.exists,
@@ -87,6 +92,13 @@ def create_or_update_release(user, pwd, secret, repo_slug, changelog_file, doc_u
8792
message=message,
8893
draft=False, prerelease=False)
8994

95+
# add the asset file if needed
96+
if data_file is not None:
97+
release = None
98+
while release is None:
99+
release = repo.get_release(tag)
100+
release.upload_asset(path=data_file, label=path.split(data_file)[1], content_type="application/gzip")
101+
90102
# --- Memo ---
91103
# release.target_commitish # 'master'
92104
# release.tag_name # '0.5.0'

0 commit comments

Comments
 (0)