From d70750efb653eb296f411d3bd220d8dfbffdee46 Mon Sep 17 00:00:00 2001 From: Alexey Pustovalov Date: Tue, 20 Feb 2024 00:42:03 +0900 Subject: [PATCH] Added workflow to update Red Hat Container Catalog --- .github/scripts/rhel_description.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/scripts/rhel_description.py b/.github/scripts/rhel_description.py index 124b91343..6165d7efb 100644 --- a/.github/scripts/rhel_description.py +++ b/.github/scripts/rhel_description.py @@ -4,20 +4,32 @@ import json import markdown import os -repository_description = '' +repository_description = None if ("DESCRIPTION_FILE" not in os.environ): print("Description file environment variable is not specified") sys.exit(1) +if ("PYXIS_API_TOKEN" not in os.environ): + print("API token environment variable is not specified") + sys.exit(1) +if ("API_URL" not in os.environ): + print("API URL environment variable is not specified") + sys.exit(1) +if ("PROJECT_ID" not in os.environ): + print("RedHat project ID environment variable is not specified") + sys.exit(1) if (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.md')): - repository_description=markdown.markdownFromFile(input=os.environ["DESCRIPTION_FILE"] + '.md') + file = open(os.environ["DESCRIPTION_FILE"] + '.md', mode='r') + markdown_data = file.read() + file.close() + repository_description=markdown.markdown(markdown_data) elif (os.path.isfile(os.environ["DESCRIPTION_FILE"] + '.html')): file = open(os.environ["DESCRIPTION_FILE"] + '.html', mode='r') repository_description = file.read() file.close() -if (len(repository_description)) == 0: +if (repository_description is None or len(repository_description) == 0): print("No description") sys.exit(1) @@ -28,4 +40,4 @@ data['container']['repository_description'] = repository_description[:32768] headers = {'accept' : 'application/json', 'X-API-KEY' : os.environ["PYXIS_API_TOKEN"], 'Content-Type' : 'application/json'} result = requests.patch(os.environ["API_URL"] + os.environ["PROJECT_ID"], headers = headers, data = json.dumps(data)) print(result) -print(json.loads(r.content)['last_update_date']) \ No newline at end of file +print(json.loads(r.content)['last_update_date'])