Skip to content

Commit

Permalink
Keep only a release blog post feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed May 31, 2024
1 parent ac68ef8 commit 25cb7b1
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 1,087 deletions.
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
DateTime==4.3.0
requests==2.23.0
toml==0.10.2

requests==2.23.0
6 changes: 3 additions & 3 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Script to release new gtk-rs crates version.
"""

__version__ = '0.0.1'
__author__ = 'Guillaume Gomez'
__version__ = "0.0.1"
__author__ = "Guillaume Gomez"


__all__ = ['consts', 'github', 'my_toml', 'release', 'utils', 'args', 'globals']
__all__ = ["consts", "github", "release", "utils", "args"]
160 changes: 7 additions & 153 deletions src/args.py
Original file line number Diff line number Diff line change
@@ -1,192 +1,46 @@
import getopt

# local imports
from utils import write_error, write_msg
import consts


class UpdateType:
MAJOR = 0
MEDIUM = 1
MINOR = 2

@staticmethod
def create_from_string(version_s):
version_s = version_s.lower()
if version_s == 'major':
return UpdateType.MAJOR
if version_s == 'medium':
return UpdateType.MEDIUM
if version_s == 'minor':
return UpdateType.MINOR
return None

@staticmethod
def to_str(update):
if update == UpdateType.MAJOR:
return "MAJOR"
if update == UpdateType.MEDIUM:
return "MEDIUM"
if update == UpdateType.MINOR:
return "MINOR"
return "UNKNOWN"


def get_answer(text):
while True:
text = input(f'{text} [Y/n] ').strip().lower()
if len(text) == 0 or text == 'y':
return True
if text == 'n':
return False
write_msg(f'-> Invalid answer "{text}": only "Y" and "n" are expected')


def is_sys_crate(crate):
return crate.endswith('-sys') or crate.endswith('-sys-rs')


def get_up_type(crate, mode, pick_update_type_for_crates, default_updates):
if mode is None and pick_update_type_for_crates is False:
return None
if is_sys_crate(crate) and default_updates['sys'] is not None:
return default_updates['sys']
if not is_sys_crate(crate) and default_updates['non-sys'] is not None:
return default_updates['non-sys']
while pick_update_type_for_crates is True:
text = input(f'Which kind of update do you want for "{crate}"? [MINOR/MEDIUM/MAJOR] ')
text = text.strip().lower()
mode = UpdateType.create_from_string(text)
if mode is not None:
if (is_sys_crate(crate) and
get_answer('Do you want to use this release for all other sys crates?')):
default_updates['sys'] = mode
elif (not is_sys_crate(crate) and
get_answer('Do you want to use this release for all other non-sys crates?')):
default_updates['non-sys'] = mode
break
write_msg(f'Invalid update type received: "{text}". Accepted values: (MINOR|MEDIUM|MAJOR)')
return mode


def ask_updates_confirmation(crates):
write_msg("Recap' of picked updates:")
for crate in crates:
crate_name = crate['crate']['crate']
update = UpdateType.to_str(crate['up-type'])
write_msg(f"[{crate_name}] => {update}")
return get_answer('Do you agree with this?')


def write_help():
write_msg("release.py accepts the following options:")
write_msg("")
write_msg(" * -h | --help : display this message")
write_msg(" * -t <token> | --token=<token> : give the github token")
write_msg(" * -m <mode> | --mode=<mode> : give the update type (MINOR|MEDIUM|MAJOR)")
write_msg(" * --no-push : performs all operations but doesn't push anything")
write_msg(" * -c <crate> | --crate=<crate> : only update the given crate (for test purpose"
" mainly)")
write_msg(" * --badges-only : only update the badges on the website")
write_msg(" * --tags-only : only create new tags")
write_msg(" * --blog-only : only create blog post")
write_msg(" * --pick-crates : add an interactive way to pick crates")
write_msg(" * --pick-update-type-for-crates: pick an update type for each crate")


class Arguments:
def __init__(self):
self.token = None
self.mode = None
self.no_push = False
self.specified_crate = None
self.tags_only = False
self.blog_only = False
self.crates = consts.CRATE_LIST

@staticmethod
def parse_arguments(argv):
# pylint: disable=too-many-branches,too-many-return-statements
try:
opts = getopt.getopt(argv,
"ht:m:c:",
["help", "token=", "mode=", "no-push", "crate",
"badges-only", "tags-only", "pick-update-type-for-crates",
"pick-crates", "blog-only"])[0] # second argument is "args"
opts = getopt.getopt(argv, "ht:m:c:", ["help", "token="])[
0
] # second argument is "args"
except getopt.GetoptError:
write_help()
return None

instance = Arguments()

pick_update_type_for_crates = False

for opt, arg in opts:
if opt in ('-h', '--help'):
if opt in ("-h", "--help"):
write_help()
return None
if opt in ("-t", "--token"):
instance.token = arg
elif opt in ("-m", "--mode"):
instance.mode = UpdateType.create_from_string(arg)
if instance.mode is None:
write_error(f'{opt}: Invalid update type received. Accepted values: '
'(MINOR|MEDIUM|MAJOR)')
return None
elif opt == "--no-push":
instance.no_push = True
elif opt in ('-c', '--crate'):
instance.specified_crate = arg
elif opt == '--tags-only':
instance.tags_only = True
elif opt == '--blog-only':
instance.blog_only = True
elif opt == '--pick-crates':
instance.crates = []
elif opt == '--pick-update-type-for-crates':
pick_update_type_for_crates = True
else:
write_msg(f'"{opt}": unknown option')
write_msg('Use "-h" or "--help" to see help')
return None
if instance.token is None and instance.no_push is False and instance.blog_only is False:
if instance.token is None:
# In this case, I guess it's not an issue to not have a github token...
write_error('Missing token argument.')
return None
# To make pylint happy.
not_only_checks = (instance.tags_only is False or
instance.blog_only is False)
if (instance.mode is None and
not_only_checks is False and
pick_update_type_for_crates is False):
write_error('Missing update type argument.')
write_error("Missing token argument.")
return None

default_updates = {"sys": None, "non-sys": None}
if len(instance.crates) == 0:
for crate in consts.CRATE_LIST:
if get_answer(f'Do you want to include "{crate}" in this release?') is True:
instance.crates.append(
{
'up-type': get_up_type(crate['crate'],
instance.mode,
pick_update_type_for_crates,
default_updates),
'crate': crate,
})
if ask_updates_confirmation(instance.crates) is False:
write_msg('OK! Aborting then!')
return None
else:
instance.crates = [
{
'up-type': get_up_type(crate['crate'],
instance.mode,
pick_update_type_for_crates,
default_updates),
'crate': crate,
} for crate in instance.crates]
if (pick_update_type_for_crates is True and
ask_updates_confirmation(instance.crates) is False):
write_msg('OK! Aborting then!')
return None
return instance
65 changes: 15 additions & 50 deletions src/consts.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,24 @@
GH_API_URL = 'https://api.github.com'
from datetime import date


GH_API_URL = "https://api.github.com"
GITHUB_URL = "https://github.com"
GIT_URL = "[email protected]:"

ORGANIZATION = "gtk-rs"
MASTER_TMP_BRANCH = "master-release-update"

BLOG_REPO = "gtk-rs.github.io"

CRATE_LIST = [
# Sys crates
{"crate": "glib-sys", "repository": "gtk-rs-core", "path": "glib/sys"},
{"crate": "gobject-sys", "repository": "gtk-rs-core", "path": "glib/gobject-sys"},
{"crate": "graphene-sys", "repository": "gtk-rs-core", "path": "graphene/sys"},
{"crate": "gio-sys", "repository": "gtk-rs-core", "path": "gio/sys"},
{"crate": "pango-sys", "repository": "gtk-rs-core", "path": "pango/sys"},
{"crate": "gdk-pixbuf-sys", "repository": "gtk-rs-core", "path": "gdk-pixbuf/sys"},
{"crate": "glib-macros", "repository": "gtk-rs-core", "path": "glib-macros"},
# glib must be published before cairo-sys (because of macros)
{"crate": "glib", "repository": "gtk-rs-core", "path": "glib"},
{"crate": "cairo-sys-rs", "repository": "gtk-rs-core", "path": "cairo/sys"},
{"crate": "pangocairo-sys", "repository": "gtk-rs-core", "path": "pangocairo/sys"},
{"crate": "atk-sys", "repository": "gtk3-rs", "path": "atk/sys"},
{"crate": "gdkx11-sys", "repository": "gtk3-rs", "path": "gdkx11/sys"},
{"crate": "gdk-sys", "repository": "gtk3-rs", "path": "gdk/sys"},
{"crate": "gdkwayland-sys", "repository": "gtk3-rs", "path": "gdkwayland/sys"},
{"crate": "gtk-sys", "repository": "gtk3-rs", "path": "gtk/sys"},
{"crate": "gdk4-sys", "repository": "gtk4-rs", "path": "gdk4/sys"},
{"crate": "gdk4-wayland-sys", "repository": "gtk4-rs", "path": "gdk4-wayland/sys"},
{"crate": "gdk4-x11-sys", "repository": "gtk4-rs", "path": "gdk4-x11/sys"},
{"crate": "gsk4-sys", "repository": "gtk4-rs", "path": "gsk4/sys"},
{"crate": "gtk4-sys", "repository": "gtk4-rs", "path": "gtk4/sys"},

# Non-sys crates
{"crate": "gtk3-macros", "repository": "gtk3-rs", "path": "gtk3-macros"},
{"crate": "gtk4-macros", "repository": "gtk4-rs", "path": "gtk4-macros"},
{"crate": "graphene", "repository": "gtk-rs-core", "path": "graphene"},
{"crate": "atk", "repository": "gtk3-rs", "path": "atk"},
{"crate": "gio", "repository": "gtk-rs-core", "path": "gio"},
{"crate": "pango", "repository": "gtk-rs-core", "path": "pango"},
{"crate": "cairo-rs", "repository": "gtk-rs-core", "path": "cairo"},
{"crate": "gdk-pixbuf", "repository": "gtk-rs-core", "path": "gdk-pixbuf"},
{"crate": "gdk", "repository": "gtk3-rs", "path": "gdk"},
{"crate": "gdkwayland", "repository": "gtk3-rs", "path": "gdkwayland"},
{"crate": "gtk", "repository": "gtk3-rs", "path": "gtk"},
{"crate": "gdkx11", "repository": "gtk3-rs", "path": "gdkx11"},
{"crate": "pangocairo", "repository": "gtk-rs-core", "path": "pangocairo"},
{"crate": "gdk4", "repository": "gtk4-rs", "path": "gdk4"},
{"crate": "gdk4-wayland", "repository": "gtk4-rs", "path": "gdk4-wayland"},
{"crate": "gdk4-x11", "repository": "gtk4-rs", "path": "gdk4-x11"},
{"crate": "gsk4", "repository": "gtk4-rs", "path": "gsk4"},
{"crate": "gtk4", "repository": "gtk4-rs", "path": "gtk4"},
# {"crate": "gtk-test", "repository": "gtk-test", "path": ""},
]
CORE_RELEASE_DATE = date.fromisoformat('2024-02-04')
GTK4_RELEASE_DATE = CORE_RELEASE_DATE

EXAMPLES = [
{"repository": "gtk3-rs", "path": "examples"},
{"repository": "gtk4-rs", "path": "examples"},
REPOSITORIES = [
{
"name": "gtk-rs-core",
"date": CORE_RELEASE_DATE,
},
{
"name": "gtk4-rs",
"date": GTK4_RELEASE_DATE,
},
]
Loading

0 comments on commit 25cb7b1

Please sign in to comment.