From 1c26dfdf6e6eed59b5d60adb0f4816690ad32a01 Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Fri, 27 Sep 2024 09:58:46 +0200 Subject: [PATCH 1/5] Automatic formatting of Social media release announcement A python script that depends on packages (in requirements.txt) * requests * markdown able to format a social media post announcing our releases. The script will pick, for each operator, the latest tag name and related URL to release note, and format a message in raw markdown and HTML. suggested use $ python -m venv venv $ source venv/bin/activate $ pip install -r requirements.txt $ python ./product_release_post.py Limitations There's a (currently unhandled) rate limit to the use of APIs. It is enough for around 10 retries. When reached the script fails with error ``` KeyError: 'tag_name' ``` Signed-off-by: Carlo Lobrano --- product_release_post.py | 56 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 2 files changed, 58 insertions(+) create mode 100755 product_release_post.py create mode 100644 requirements.txt diff --git a/product_release_post.py b/product_release_post.py new file mode 100755 index 0000000..3e8460a --- /dev/null +++ b/product_release_post.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# vi: set ft=python : +import requests +import markdown + +products_map = { + "NMO": "node-maintenance-operator", + "NHC": "node-healthcheck-operator", + "SNR": "self-node-remediation", + "FAR": "fence-agents-remediation", + "MDR": "machine-deletion-remediation", +} +# print(requests.get(f'https://api.github.com/repos/medik8s/{products_map["MDR"]}/releases/latest').json()) + +def get_latest_version(op_shortname:str) -> dict[str,str]: + response = requests.get(f'https://api.github.com/repos/medik8s/{products_map[op_shortname]}/releases/latest') + return {"tag":response.json()["tag_name"], "link": response.json()["html_url"]} + + +NMO = get_latest_version("NMO") +NHC = get_latest_version("NHC") +SNR = get_latest_version("SNR") +FAR = get_latest_version("FAR") +MDR = get_latest_version("MDR") + +TEMPLATE = f""" +Medik8s New Releases + +The Medik8s team is thrilled to announce the new releases of ours operators + +* Node Maintenance Operator (NMO) {NMO["tag"]} +* Node Healthcheck Operator (NHC) {NHC["tag"]} +* Self Node Remediation (SNR) {SNR["tag"]} +* Fence Agents Remediation (FAR) {FAR["tag"]} +* Machine Deletion Remediation (MDR) {MDR["tag"]} + +see our release notes for the complete list of changes +* NHC [{NMO['tag']} release note]({NMO['link']}) +* SNR [{NHC['tag']} release note]({NHC['link']}) +* NMO [{SNR['tag']} release note]({SNR['link']}) +* FAR [{FAR['tag']} release note]({FAR['link']}) +* MDR [{MDR['tag']} release note]({MDR['link']}) + +Feel free to explore the new operators and contact us if you need any assistance. + +Do not forget to visit https://www.medik8s.io/ for the latest information on the team's operators, +Best regards from the Medik8s team. + +""" + +print("Raw version:") +print(TEMPLATE) + +print("\nFormatted HTML version") +print(markdown.markdown(TEMPLATE)) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..95094be --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests>=2.32 +markdown>=3.7 From 35e6f40c3ac6e032e507f6417d23d8f693d87b9a Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Tue, 22 Oct 2024 17:46:30 +0200 Subject: [PATCH 2/5] Use dedicated folder and fix format * Use dedicated folder ProductReleaseAnnouncement * Announce the Operators and report the link to the release notes in the same list --- .../product_rel_announcement.py | 21 +++++++------------ .../requirements.txt | 0 2 files changed, 8 insertions(+), 13 deletions(-) rename product_release_post.py => ProductReleaseAnnouncement/product_rel_announcement.py (64%) rename requirements.txt => ProductReleaseAnnouncement/requirements.txt (100%) diff --git a/product_release_post.py b/ProductReleaseAnnouncement/product_rel_announcement.py similarity index 64% rename from product_release_post.py rename to ProductReleaseAnnouncement/product_rel_announcement.py index 3e8460a..8d03e81 100755 --- a/product_release_post.py +++ b/ProductReleaseAnnouncement/product_rel_announcement.py @@ -29,22 +29,17 @@ def get_latest_version(op_shortname:str) -> dict[str,str]: The Medik8s team is thrilled to announce the new releases of ours operators -* Node Maintenance Operator (NMO) {NMO["tag"]} -* Node Healthcheck Operator (NHC) {NHC["tag"]} -* Self Node Remediation (SNR) {SNR["tag"]} -* Fence Agents Remediation (FAR) {FAR["tag"]} -* Machine Deletion Remediation (MDR) {MDR["tag"]} - -see our release notes for the complete list of changes -* NHC [{NMO['tag']} release note]({NMO['link']}) -* SNR [{NHC['tag']} release note]({NHC['link']}) -* NMO [{SNR['tag']} release note]({SNR['link']}) -* FAR [{FAR['tag']} release note]({FAR['link']}) -* MDR [{MDR['tag']} release note]({MDR['link']}) +* Node Maintenance Operator (NMO) {NMO['tag']} ([release note]({NMO['link']})) +* Node Healthcheck Operator (NHC) {NHC['tag']} ([release note]({NHC['link']})) +* Self Node Remediation (SNR) {SNR['tag']} ([release note]({SNR['link']})) +* Fence Agents Remediation (FAR) {FAR['tag']} ([release note]({FAR['link']})) +* Machine Deletion Remediation (MDR) {MDR['tag']} ([release note]({MDR['link']})) + +see our release notes for the complete list of changes. Feel free to explore the new operators and contact us if you need any assistance. -Do not forget to visit https://www.medik8s.io/ for the latest information on the team's operators, +Do not forget to visit [https://www.medik8s.io/](https://www.medik8s.io/) for the latest information on the team's operators, Best regards from the Medik8s team. """ diff --git a/requirements.txt b/ProductReleaseAnnouncement/requirements.txt similarity index 100% rename from requirements.txt rename to ProductReleaseAnnouncement/requirements.txt From e4ec6d4db39314752018ca903655f46adc91f3ed Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Tue, 22 Oct 2024 18:08:07 +0200 Subject: [PATCH 3/5] Move main code into a main() function Signed-off-by: Carlo Lobrano --- .../product_rel_announcement.py | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/ProductReleaseAnnouncement/product_rel_announcement.py b/ProductReleaseAnnouncement/product_rel_announcement.py index 8d03e81..600d7e4 100755 --- a/ProductReleaseAnnouncement/product_rel_announcement.py +++ b/ProductReleaseAnnouncement/product_rel_announcement.py @@ -4,27 +4,15 @@ import requests import markdown -products_map = { - "NMO": "node-maintenance-operator", - "NHC": "node-healthcheck-operator", - "SNR": "self-node-remediation", - "FAR": "fence-agents-remediation", - "MDR": "machine-deletion-remediation", -} -# print(requests.get(f'https://api.github.com/repos/medik8s/{products_map["MDR"]}/releases/latest').json()) - -def get_latest_version(op_shortname:str) -> dict[str,str]: - response = requests.get(f'https://api.github.com/repos/medik8s/{products_map[op_shortname]}/releases/latest') - return {"tag":response.json()["tag_name"], "link": response.json()["html_url"]} - -NMO = get_latest_version("NMO") -NHC = get_latest_version("NHC") -SNR = get_latest_version("SNR") -FAR = get_latest_version("FAR") -MDR = get_latest_version("MDR") +def main(): + NMO = get_latest_version("node-maintenance-operator") + NHC = get_latest_version("node-healthcheck-operator") + SNR = get_latest_version("self-node-remediation") + FAR = get_latest_version("fence-agents-remediation") + MDR = get_latest_version("machine-deletion-remediation") -TEMPLATE = f""" + TEMPLATE = f""" Medik8s New Releases The Medik8s team is thrilled to announce the new releases of ours operators @@ -41,11 +29,28 @@ def get_latest_version(op_shortname:str) -> dict[str,str]: Do not forget to visit [https://www.medik8s.io/](https://www.medik8s.io/) for the latest information on the team's operators, Best regards from the Medik8s team. - """ -print("Raw version:") -print(TEMPLATE) + print("Raw version:") + print(TEMPLATE) + + print("\nFormatted HTML version") + print(markdown.markdown(TEMPLATE)) + + +def get_latest_version(op_name:str) -> dict[str,str]: + """ + Get the latest version of an Medik8s operator. + + :param op_name: The name of the operator to retrieve the latest version for. + :return: A dictionary with the latest version tag and link to the release note. + """ + response = requests.get(f'https://api.github.com/repos/medik8s/{op_name}/releases/latest') + return {"tag":response.json()["tag_name"], "link": response.json()["html_url"]} + + +if __name__ == "__main__": + main() + + -print("\nFormatted HTML version") -print(markdown.markdown(TEMPLATE)) From 43a59e58c3174087af764f95d5465fc8d3ff1ec8 Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Tue, 22 Oct 2024 18:31:10 +0200 Subject: [PATCH 4/5] Add argument parser logic Add Usage doc and argument parsing logic with docopt-ng. The script now write the announcement post in: * release.md Markdown file if using the flag --markdown/-m * release.html file if using the flag --html/-w the flags can be used together to have two formats. --- .../product_rel_announcement.py | 26 ++++++++++++++++--- ProductReleaseAnnouncement/requirements.txt | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ProductReleaseAnnouncement/product_rel_announcement.py b/ProductReleaseAnnouncement/product_rel_announcement.py index 600d7e4..fbc6f04 100755 --- a/ProductReleaseAnnouncement/product_rel_announcement.py +++ b/ProductReleaseAnnouncement/product_rel_announcement.py @@ -1,11 +1,26 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # vi: set ft=python : +""" +Auto-generate social media posts for Medik8s release announcements by filling in the latest tags and +release information. + +Usage: + product_rel_announcement.py --markdown + product_rel_announcement.py --html + product_rel_announcement.py --html --markdown + +Options: + -m, --markdown Write the release announcement file release.md, in Markdown format + -w, --html Write the release announcement file release.html, in HTML format +""" import requests import markdown +from docopt import docopt def main(): + arguments = docopt(__doc__) NMO = get_latest_version("node-maintenance-operator") NHC = get_latest_version("node-healthcheck-operator") SNR = get_latest_version("self-node-remediation") @@ -31,11 +46,14 @@ def main(): Best regards from the Medik8s team. """ - print("Raw version:") - print(TEMPLATE) + if arguments['--markdown']: + with open('release.md', 'w') as f: + f.write(TEMPLATE) - print("\nFormatted HTML version") - print(markdown.markdown(TEMPLATE)) + if arguments['--html']: + with open('release.html', 'w') as f: + html = markdown.markdown(TEMPLATE) + f.write(html) def get_latest_version(op_name:str) -> dict[str,str]: diff --git a/ProductReleaseAnnouncement/requirements.txt b/ProductReleaseAnnouncement/requirements.txt index 95094be..23a876d 100644 --- a/ProductReleaseAnnouncement/requirements.txt +++ b/ProductReleaseAnnouncement/requirements.txt @@ -1,2 +1,3 @@ requests>=2.32 markdown>=3.7 +docopt-ng>=0.9.0 From 1c9eb9f3b32f4ac5f534da7796a2c35fa3f549c1 Mon Sep 17 00:00:00 2001 From: Carlo Lobrano Date: Mon, 28 Oct 2024 15:16:18 +0100 Subject: [PATCH 5/5] Minor fixes in message format Signed-off-by: Carlo Lobrano --- ProductReleaseAnnouncement/product_rel_announcement.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProductReleaseAnnouncement/product_rel_announcement.py b/ProductReleaseAnnouncement/product_rel_announcement.py index fbc6f04..0debebe 100755 --- a/ProductReleaseAnnouncement/product_rel_announcement.py +++ b/ProductReleaseAnnouncement/product_rel_announcement.py @@ -30,7 +30,7 @@ def main(): TEMPLATE = f""" Medik8s New Releases -The Medik8s team is thrilled to announce the new releases of ours operators +The Medik8s team is thrilled to announce the new releases of ours operators: * Node Maintenance Operator (NMO) {NMO['tag']} ([release note]({NMO['link']})) * Node Healthcheck Operator (NHC) {NHC['tag']} ([release note]({NHC['link']})) @@ -38,7 +38,7 @@ def main(): * Fence Agents Remediation (FAR) {FAR['tag']} ([release note]({FAR['link']})) * Machine Deletion Remediation (MDR) {MDR['tag']} ([release note]({MDR['link']})) -see our release notes for the complete list of changes. +See our release notes for the complete list of changes. Feel free to explore the new operators and contact us if you need any assistance.