11# a clone of the ruby example https://gist.github.com/valeriomazzeo/5491aee76f758f7352e2e6611ce87ec1
22import os
3+ from os import path
4+
35import re
46
57import click
8+ from click import Path
69from github import Github , UnknownObjectException
710# from valid8 import validate not compliant with python 2.7
811
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