releaser: refactor; add func GetListOfArtifacts

This commit is contained in:
umarcor
2021-12-20 02:41:08 +01:00
parent 08a19429d4
commit cea369d703

View File

@@ -22,16 +22,17 @@
# SPDX-License-Identifier: Apache-2.0 # # SPDX-License-Identifier: Apache-2.0 #
# ==================================================================================================================== # # ==================================================================================================================== #
import re import re
from sys import argv, stdout, exit as sys_exit from sys import argv as sys_argv, stdout, exit as sys_exit
from os import environ, getenv from os import environ, getenv
from glob import glob from glob import glob
from pathlib import Path from pathlib import Path
from github import Github, GithubException from github import Github, GithubException
def GetListOfArtifacts(argv):
print("· Get list of artifacts to be uploaded") print("· Get list of artifacts to be uploaded")
args = [] args = []
files = []
if "INPUT_FILES" in environ: if "INPUT_FILES" in environ:
args = environ["INPUT_FILES"].split() args = environ["INPUT_FILES"].split()
@@ -39,13 +40,14 @@ if "INPUT_FILES" in environ:
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].lower() == "none":
files = []
print("! Skipping 'files' because it's set to 'none") print("! Skipping 'files' because it's set to 'none")
return []
elif len(args) == 0: elif 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'!"))
else: else:
files = []
for item in args: for item in args:
print(f" glob({item!s}):") print(f" glob({item!s}):")
for fname in [fname for fname in glob(item, recursive=True) if not Path(fname).is_dir()]: for fname in [fname for fname in glob(item, recursive=True) if not Path(fname).is_dir()]:
@@ -54,10 +56,14 @@ else:
continue continue
print(f" - {fname!s}") print(f" - {fname!s}")
files.append(fname) files.append(fname)
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!"))
return files
files = GetListOfArtifacts(sys_argv)
print("· Get GitHub API handler (authenticate)") print("· Get GitHub API handler (authenticate)")