Skip to content

Commit

Permalink
Upgrade release script
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Apr 10, 2024
1 parent 99b27d7 commit ef1c313
Showing 1 changed file with 136 additions and 40 deletions.
176 changes: 136 additions & 40 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ from datetime import datetime
from termcolor import colored
from urllib.parse import urlparse

# on Tuxfamily
ssh_path = 'galette/galette-repository/plugins/'
ssh_host = 'ssh.tuxfamily.org'
galette_dl_repo = 'http://download.tuxfamily.org/galette/plugins/'
is_local = False

local_dl_repo = os.path.join(
os.path.dirname(
os.path.dirname(os.path.abspath(__file__))
Expand All @@ -22,19 +27,23 @@ sign = True
assume_yes = False
nightly = False
ssh_key = False
tag_commit = None


def print_err(msg):
"""
Display colored error message
"""
print(colored(msg, 'red', attrs=['bold']))


def get_numeric_version(ver):
"""
Returns all numeric version
"""
return re.findall(r'\d+', ver)


def valid_version(ver):
"""
Check if provided version is valid.
Expand All @@ -44,6 +53,7 @@ def valid_version(ver):
"""
return '.'.join(get_numeric_version(ver)) == ver


def incr_version(ver):
"""
Increment version number
Expand All @@ -52,6 +62,7 @@ def incr_version(ver):
version[-1] = str(int(version[-1]) + 1)
return version


def propose_version():
"""
Propose new minor and major versions,
Expand All @@ -63,24 +74,24 @@ def propose_version():
for tagref in tagrefs:
tag = tagref.tag
if valid_version(tag.tag):
#last minor version is always the last one :)
# last minor version is always the last one :)
if tag.tag > last_minor:
last_minor = tag.tag

#last major version
# last major version
if len(tag.tag) == 5 and tag.tag > last_major:
last_major = tag.tag

if verbose:
print('last minor: %s | last major %s' % (last_minor, last_major))

#no version provided. propose one
# no version provided. propose one
new_minor = None
new_major = None

if len(last_minor) == 5:
#if the latest is a major version
new_minor = last_minor + ('.1')
# if the latest is a major version
new_minor = last_minor + '.1'
else:
new_minor = '.'.join(incr_version(last_minor))

Expand All @@ -91,19 +102,24 @@ def propose_version():
major: %s
""" % (new_minor, new_major))


def get_latest_version():
"""
Look for latest version
"""
global tag_commit

last = None
for tagref in tagrefs:
tag = tagref.tag
if valid_version(tag.tag):
#last minor version is always the last one :)
if last == None or tag.tag > last:
last = tag.tag
if tag is not None and valid_version(tag.tag):
# last minor version is always the last one :)
if last is None or tag.tag > last.tag:
last = tag

tag_commit = last.hexsha
return last.tag

return last

def is_existing_version(ver):
"""
Expand Down Expand Up @@ -135,6 +151,7 @@ def ask_user_confirm(msg):
"Invalid input. Please enter 'yes' or 'no' (or 'y' or 'n')."
)


def get_rel_name(buildver):
"""
Build archive name from command line parameters
Expand All @@ -157,10 +174,13 @@ def get_rel_name(buildver):

return archive_name


def _do_build(ver):
"""
Proceed build
"""
global is_local

exists = False
ascexists = False
rel_name = get_rel_name(ver)
Expand All @@ -171,33 +191,40 @@ def _do_build(ver):
)

if not force:
#first check if a version
# first check if a version
local = False
ascLocal = False

url = galette_dl_repo + '/' + archive_name
urlasc = '%s.asc' % url
parsed = urlparse(url)
ascparsed = urlparse(urlasc)

connection = http.client.HTTPConnection(parsed[1], 80)
connection.request('HEAD', parsed[2])
response = connection.getresponse()
exists = response.status == 200
if is_local:
exists = os.path.isfile(url)
else:
parsed = urlparse(url)

connection = http.client.HTTPConnection(parsed[1], 80)
connection.request('HEAD', parsed[2])
response = connection.getresponse()
exists = response.status == 200

if not exists:
#also check from local repo
# also check from local repo
exists = os.path.exists(galette_archive)
if exists:
local = True

connection = http.client.HTTPConnection(ascparsed[1], 80)
connection.request('HEAD', ascparsed[2])
response = connection.getresponse()
ascexists = response.status == 200
if is_local:
ascexists = os.path.isfile(urlasc)
else:
ascparsed = urlparse(urlasc)
connection = http.client.HTTPConnection(ascparsed[1], 80)
connection.request('HEAD', ascparsed[2])
response = connection.getresponse()
ascexists = response.status == 200

if not ascexists:
#also check from local repo
# also check from local repo
ascexists = os.path.exists(
os.path.join(
local_dl_repo,
Expand All @@ -213,7 +240,7 @@ def _do_build(ver):
loctxt = ''
if local:
loctxt = 'locally '
msg = 'Relase %s already %sexists' % (rel_name, loctxt)
msg = 'Release %s already %sexists' % (rel_name, loctxt)

if ascexists:
loctxt = ''
Expand Down Expand Up @@ -257,7 +284,7 @@ def _do_build(ver):
typever,
galette_archive
))
print('Archive command: %s' % (archive_cmd))
print('Archive command: %s' % archive_cmd)

if commit and extra:
print('Archiving GIT commit %s' % commit)
Expand All @@ -278,33 +305,63 @@ def _do_build(ver):
)

if upload:
do_scp(galette_archive)
do_upload(galette_archive)


def do_sign(archive):
sign_cmd = 'gpg --detach-sign --armor %s' % archive
p1 = subprocess.Popen(sign_cmd, shell=True)
p1.communicate()


def do_upload(galette_archive):
"""
proceed file upload
:param galette_archive:
:return:
"""
global is_local

if is_local:
do_cp(galette_archive)
else:
do_scp(galette_archive)


def do_scp(archive):
global ssh_key
global ssh_key, ssh_host, ssh_path

path = 'galette/galette-repository/plugins/'
path = ssh_path
if extra:
path += 'dev/'

if ssh_key:
scp_cmd = 'scp -i %s %s* ssh.tuxfamily.org:%s' % (ssh_key, archive, path)
scp_cmd = 'scp -i %s %s* %s:%s' % (ssh_key, archive, ssh_host, path)
else:
scp_cmd = 'scp -r %s* ssh.tuxfamily.org:%s' % (archive, path)
scp_cmd = 'scp -r %s* %s:%s' % (archive, ssh_host, path)
print(scp_cmd)
p1 = subprocess.Popen(scp_cmd, shell=True)
p1.communicate()


def do_cp(archive):
global galette_dl_repo

path = galette_dl_repo
if extra:
path = os.path.join(path, 'dev')

shutil.copyfile(
archive,
os.path.join(path, os.path.basename(archive))
)


def add_libs(rel_name, galette_archive):
"""
Add external libraries to the archive
"""
galette = tarfile.open(galette_archive, 'r|bz2')
galette = tarfile.open(galette_archive, 'r|bz2', format=tarfile.GNU_FORMAT)
src_dir = os.path.join(local_dl_repo, 'src')
if not os.path.exists(src_dir):
os.makedirs(src_dir)
Expand Down Expand Up @@ -400,7 +457,7 @@ def add_libs(rel_name, galette_archive):
]:
os.remove(os.path.join(root, filename))

galette = tarfile.open(galette_archive, 'w|bz2')
galette = tarfile.open(galette_archive, 'w|bz2', format=tarfile.GNU_FORMAT)

for i in os.listdir(src_dir):
galette.add(
Expand All @@ -411,9 +468,10 @@ def add_libs(rel_name, galette_archive):
galette.close()
shutil.rmtree(src_dir)


def valid_commit(repo, c):
"""
Validate commit existance in repository
Validate commit existence in repository
"""
global commit

Expand Down Expand Up @@ -444,7 +502,7 @@ def main():
"""
Main method
"""
global verbose, tagrefs, force, extra, assume_yes, nightly, sign, ssh_key
global verbose, tagrefs, force, extra, assume_yes, nightly, sign, ssh_key, repo, ssh_host, ssh_path, galette_dl_repo, is_local

parser = argparse.ArgumentParser(description='Release Galette Maps Plugin')
group = parser.add_mutually_exclusive_group()
Expand Down Expand Up @@ -487,15 +545,36 @@ def main():
help='Build nightly',
action="store_true"
)
parser.add_argument(
'-l',
'--local',
help='Use local copy (defined from galette_dl_repo) rather than SSH',
action='store_true'
)
parser.add_argument(
'-k',
'--ssh-key',
help='SSH key to be used for uploading',
)
parser.add_argument(
'-H',
'--ssh-host',
help='SSH host to upload to (default %s)' % ssh_host
)
parser.add_argument(
'-P',
'--ssh-path',
help='Path on SSH host (default %s)' % ssh_path
)
parser.add_argument(
'-d',
'--download-url',
help='Download URL (default %s)' % galette_dl_repo
)
parser.add_argument('-f', action='store_true')
args = parser.parse_args()

verbose=args.verbose
verbose = args.verbose

if verbose:
print(args)
Expand All @@ -508,10 +587,26 @@ def main():
force = ask_user_confirm(
'Are you *REALLY* sure you mean -f when you typed -f? [yes/No] '
)
assume_yes=args.assume_yes
assume_yes = args.assume_yes

if args.local:
if not args.download_url:
print_err('download_url is mandatory for local builds!')
sys.exit(1)
is_local = args.local

else:
if args.ssh_key:
ssh_key = args.ssh_key

if args.ssh_key:
ssh_key = args.ssh_key
if args.ssh_host:
ssh_host = args.ssh_host

if args.ssh_path:
ssh_path = args.ssh_path

if args.download_url:
galette_dl_repo = args.download_url

build = False
buildver = None
Expand Down Expand Up @@ -543,7 +638,7 @@ def main():
print_err('%s is not a valid version number!' % args.version)
sys.exit(1)
else:
#check if specified version exists
# check if specified version exists
if not is_existing_version(args.version):
print_err('%s does not exist!' % args.version)
else:
Expand All @@ -557,11 +652,12 @@ def main():
build = True
else:
build = ask_user_confirm(
'Do you want to build Galette Maps Plugin version %s? [Yes/no] ' % buildver
'Do you want to build Galette Auto Plugin version %s? [Yes/no] ' % buildver
)

if build:
_do_build(buildver)


if __name__ == "__main__":
main()

0 comments on commit ef1c313

Please sign in to comment.