Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
eine committed Oct 17, 2021
1 parent 090df19 commit c5d6639
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions tip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
args = []
files = []

if 'INPUT_FILES' in environ:
args = environ['INPUT_FILES'].split()
if "INPUT_FILES" in environ:
args = environ["INPUT_FILES"].split()

if len(argv) > 1:
args = args + argv[1:]

if len(args) == 1 and args[0] == 'none':
if len(args) == 1 and args[0] == "none":
files = []
print("! Skipping 'files' because it's set to 'none")
else:
if len(args) == 0:
stdout.flush()
raise(Exception("Glob patterns need to be provided as positional arguments or through envvar 'INPUT_FILES'!"))
raise (Exception("Glob patterns need to be provided as positional arguments or through envvar 'INPUT_FILES'!"))

for item in args:
items = [fname for fname in glob(item, recursive=True) if not Path(fname).is_dir()]
Expand All @@ -39,61 +39,65 @@

if len(files) < 1:
stdout.flush()
raise(Exception('Empty list of files to upload/update!'))
raise (Exception("Empty list of files to upload/update!"))

print("· Get GitHub API handler (authenticate)")

if 'GITHUB_TOKEN' in environ:
if "GITHUB_TOKEN" in environ:
gh = Github(environ["GITHUB_TOKEN"])
elif 'INPUT_TOKEN' in environ:
elif "INPUT_TOKEN" in environ:
gh = Github(environ["INPUT_TOKEN"])
else:
if 'GITHUB_USER' not in environ or 'GITHUB_PASS' not in environ:
if "GITHUB_USER" not in environ or "GITHUB_PASS" not in environ:
stdout.flush()
raise(Exception("Need credentials to authenticate! Please, provide 'GITHUB_TOKEN', 'INPUT_TOKEN', or 'GITHUB_USER' and 'GITHUB_PASS'"))
raise (
Exception(
"Need credentials to authenticate! Please, provide 'GITHUB_TOKEN', 'INPUT_TOKEN', or 'GITHUB_USER' and 'GITHUB_PASS'"
)
)
gh = Github(environ["GITHUB_USER"], environ["GITHUB_PASS"])

print("· Get Repository handler")

if 'GITHUB_REPOSITORY' not in environ:
if "GITHUB_REPOSITORY" not in environ:
stdout.flush()
raise(Exception("Repository name not defined! Please set 'GITHUB_REPOSITORY"))
raise (Exception("Repository name not defined! Please set 'GITHUB_REPOSITORY"))

gh_repo = gh.get_repo(environ['GITHUB_REPOSITORY'])
gh_repo = gh.get_repo(environ["GITHUB_REPOSITORY"])

print("· Get Release handler")

tag = getenv('INPUT_TAG', 'tip')
tag = getenv("INPUT_TAG", "tip")

env_tag = None
gh_ref = environ['GITHUB_REF']
gh_ref = environ["GITHUB_REF"]
is_prerelease = True
is_draft = False

if gh_ref[0:10] == 'refs/tags/':
if gh_ref[0:10] == "refs/tags/":
env_tag = gh_ref[10:]
if env_tag != tag:
rexp = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
semver = re.search(rexp, env_tag)
if semver == None and env_tag[0] == 'v':
if semver == None and env_tag[0] == "v":
semver = re.search(rexp, env_tag[1:])
tag = env_tag
if semver == None:
print(f'! Could not get semver from {gh_ref!s}')
print(f"! Could not get semver from {gh_ref!s}")
print(f"! Treat tag '{tag!s}' as a release")
is_prerelease = False
else:
if semver.group('prerelease') is None:
if semver.group("prerelease") is None:
# is a regular semver compilant tag
is_prerelease = False
elif getenv('INPUT_SNAPSHOTS', 'true') == 'true':
elif getenv("INPUT_SNAPSHOTS", "true") == "true":
# is semver compilant prerelease tag, thus a snapshot (we skip it)
print("! Skipping snapshot prerelease")
sys.exit()

gh_tag = None
try:
gh_tag = gh_repo.get_git_ref(f'tags/{tag!s}')
gh_tag = gh_repo.get_git_ref(f"tags/{tag!s}")
except Exception as e:
stdout.flush()
pass
Expand All @@ -106,21 +110,23 @@
pass
else:
err_msg = f"Tag/release '{tag!s}' does not exist and could not create it!"
if 'GITHUB_SHA' not in environ:
raise(Exception(err_msg))
if "GITHUB_SHA" not in environ:
raise (Exception(err_msg))
try:
gh_release = gh_repo.create_git_tag_and_release(tag, "", tag, "", environ['GITHUB_SHA'], 'commit', draft=True, prerelease=is_prerelease)
gh_release = gh_repo.create_git_tag_and_release(
tag, "", tag, "", environ["GITHUB_SHA"], "commit", draft=True, prerelease=is_prerelease
)
is_draft = True
except Exception as e:
raise(Exception(err_msg))
raise (Exception(err_msg))

print("· Cleanup and/or upload artifacts")

artifacts = files

assets = gh_release.get_assets()

if getenv('INPUT_RM', 'false') == 'true':
if getenv("INPUT_RM", "false") == "true":
print("· RM set. All previous assets are being cleared...")
for asset in assets:
print(" ", asset.name)
Expand All @@ -132,7 +138,7 @@
aname = str(Path(artifact).name)
if asset.name == aname:
print(" - uploading tmp...")
new_asset = gh_release.upload_asset(artifact, name=f'tmp.{aname!s}')
new_asset = gh_release.upload_asset(artifact, name=f"tmp.{aname!s}")
print(" - removing...")
asset.delete_asset()
print(" - renaming tmp...")
Expand All @@ -157,10 +163,10 @@
draft=False,
prerelease=is_prerelease,
tag_name=gh_release.tag_name,
target_commitish=gh_release.target_commitish
target_commitish=gh_release.target_commitish,
)

if ('GITHUB_SHA' in environ) and (env_tag is None):
sha = environ['GITHUB_SHA']
if ("GITHUB_SHA" in environ) and (env_tag is None):
sha = environ["GITHUB_SHA"]
print(f" > Force-push '{tag!s}' to {sha!s}")
gh_repo.get_git_ref(f'tags/{tag!s}').edit(sha)
gh_repo.get_git_ref(f"tags/{tag!s}").edit(sha)

0 comments on commit c5d6639

Please sign in to comment.