mirror of
https://github.com/pyTooling/Actions.git
synced 2026-02-12 02:56:56 +08:00
run black
This commit is contained in:
66
tip.py
66
tip.py
@@ -14,19 +14,19 @@ print("· Get list of artifacts to be uploaded")
|
|||||||
args = []
|
args = []
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
if 'INPUT_FILES' in environ:
|
if "INPUT_FILES" in environ:
|
||||||
args = environ['INPUT_FILES'].split()
|
args = environ["INPUT_FILES"].split()
|
||||||
|
|
||||||
if len(argv) > 1:
|
if len(argv) > 1:
|
||||||
args = args + argv[1:]
|
args = args + argv[1:]
|
||||||
|
|
||||||
if len(args) == 1 and args[0] == 'none':
|
if len(args) == 1 and args[0] == "none":
|
||||||
files = []
|
files = []
|
||||||
print("! Skipping 'files' because it's set to 'none")
|
print("! Skipping 'files' because it's set to 'none")
|
||||||
else:
|
else:
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
stdout.flush()
|
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:
|
for item in args:
|
||||||
items = [fname for fname in glob(item, recursive=True) if not Path(fname).is_dir()]
|
items = [fname for fname in glob(item, recursive=True) if not Path(fname).is_dir()]
|
||||||
@@ -39,61 +39,65 @@ else:
|
|||||||
|
|
||||||
if len(files) < 1:
|
if len(files) < 1:
|
||||||
stdout.flush()
|
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)")
|
print("· Get GitHub API handler (authenticate)")
|
||||||
|
|
||||||
if 'GITHUB_TOKEN' in environ:
|
if "GITHUB_TOKEN" in environ:
|
||||||
gh = Github(environ["GITHUB_TOKEN"])
|
gh = Github(environ["GITHUB_TOKEN"])
|
||||||
elif 'INPUT_TOKEN' in environ:
|
elif "INPUT_TOKEN" in environ:
|
||||||
gh = Github(environ["INPUT_TOKEN"])
|
gh = Github(environ["INPUT_TOKEN"])
|
||||||
else:
|
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()
|
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"])
|
gh = Github(environ["GITHUB_USER"], environ["GITHUB_PASS"])
|
||||||
|
|
||||||
print("· Get Repository handler")
|
print("· Get Repository handler")
|
||||||
|
|
||||||
if 'GITHUB_REPOSITORY' not in environ:
|
if "GITHUB_REPOSITORY" not in environ:
|
||||||
stdout.flush()
|
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")
|
print("· Get Release handler")
|
||||||
|
|
||||||
tag = getenv('INPUT_TAG', 'tip')
|
tag = getenv("INPUT_TAG", "tip")
|
||||||
|
|
||||||
env_tag = None
|
env_tag = None
|
||||||
gh_ref = environ['GITHUB_REF']
|
gh_ref = environ["GITHUB_REF"]
|
||||||
is_prerelease = True
|
is_prerelease = True
|
||||||
is_draft = False
|
is_draft = False
|
||||||
|
|
||||||
if gh_ref[0:10] == 'refs/tags/':
|
if gh_ref[0:10] == "refs/tags/":
|
||||||
env_tag = gh_ref[10:]
|
env_tag = gh_ref[10:]
|
||||||
if env_tag != tag:
|
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-]+)*))?$"
|
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)
|
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:])
|
semver = re.search(rexp, env_tag[1:])
|
||||||
tag = env_tag
|
tag = env_tag
|
||||||
if semver == None:
|
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")
|
print(f"! Treat tag '{tag!s}' as a release")
|
||||||
is_prerelease = False
|
is_prerelease = False
|
||||||
else:
|
else:
|
||||||
if semver.group('prerelease') is None:
|
if semver.group("prerelease") is None:
|
||||||
# is a regular semver compilant tag
|
# is a regular semver compilant tag
|
||||||
is_prerelease = False
|
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)
|
# is semver compilant prerelease tag, thus a snapshot (we skip it)
|
||||||
print("! Skipping snapshot prerelease")
|
print("! Skipping snapshot prerelease")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
gh_tag = None
|
gh_tag = None
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
pass
|
pass
|
||||||
@@ -106,13 +110,15 @@ if gh_tag:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
err_msg = f"Tag/release '{tag!s}' does not exist and could not create it!"
|
err_msg = f"Tag/release '{tag!s}' does not exist and could not create it!"
|
||||||
if 'GITHUB_SHA' not in environ:
|
if "GITHUB_SHA" not in environ:
|
||||||
raise(Exception(err_msg))
|
raise (Exception(err_msg))
|
||||||
try:
|
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
|
is_draft = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise(Exception(err_msg))
|
raise (Exception(err_msg))
|
||||||
|
|
||||||
print("· Cleanup and/or upload artifacts")
|
print("· Cleanup and/or upload artifacts")
|
||||||
|
|
||||||
@@ -120,7 +126,7 @@ artifacts = files
|
|||||||
|
|
||||||
assets = gh_release.get_assets()
|
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...")
|
print("· RM set. All previous assets are being cleared...")
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
print(" ", asset.name)
|
print(" ", asset.name)
|
||||||
@@ -132,7 +138,7 @@ else:
|
|||||||
aname = str(Path(artifact).name)
|
aname = str(Path(artifact).name)
|
||||||
if asset.name == aname:
|
if asset.name == aname:
|
||||||
print(" - uploading tmp...")
|
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...")
|
print(" - removing...")
|
||||||
asset.delete_asset()
|
asset.delete_asset()
|
||||||
print(" - renaming tmp...")
|
print(" - renaming tmp...")
|
||||||
@@ -157,10 +163,10 @@ if is_draft:
|
|||||||
draft=False,
|
draft=False,
|
||||||
prerelease=is_prerelease,
|
prerelease=is_prerelease,
|
||||||
tag_name=gh_release.tag_name,
|
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):
|
if ("GITHUB_SHA" in environ) and (env_tag is None):
|
||||||
sha = environ['GITHUB_SHA']
|
sha = environ["GITHUB_SHA"]
|
||||||
print(f" > Force-push '{tag!s}' to {sha!s}")
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user