Skip to content
Snippets Groups Projects
Commit be10d728 authored by Jaromír Hradil's avatar Jaromír Hradil
Browse files

Merge branch 'image-rotation-publish' into 'master'

Creating automatic image rotation news updates

See merge request !92
parents d3cb5bf9 01c8e852
No related branches found
No related tags found
1 merge request!92Creating automatic image rotation news updates
......@@ -33,6 +33,8 @@ deploy_cpanel:
- echo "{{</csv-table>}}" >> content/cloud/flavors/index.md
- cat content/cloud/flavors/index.md
- sed -i -e "s/BUILDIDTAG/$CI_COMMIT_SHORT_SHA/g" ./layouts/partials/site-footer.html
- curl https://cloud.gitlab-pages.ics.muni.cz/image-rotation/image-rotation-journal.md >> content/cloud/image-rotation/index.md
- python3 ci/image_rotation_news_gen.py
- hugo --config config.toml -D --destination=./public
- eval $(ssh-agent -s)
......@@ -48,5 +50,4 @@ deploy_cpanel:
- latest_commit=$(git log -1 --pretty=format:%h )
- "curl -H 'Cache-Control: no-cache' https://docs.cloud.muni.cz | grep $latest_commit"
only:
- master
- master
\ No newline at end of file
"""Generated dynamically image rotation news updates"""
import re
import datetime
DOC_NEWS_FILE = "content/cloud/news/index.md"
IMAGE_ROTATION_FILE = "content/cloud/image-rotation/index.md"
def get_image_update_log_dates():
"""Gets all image rotation update dates"""
with open(IMAGE_ROTATION_FILE, "r", encoding="utf-8") as rotate_file:
file_content = rotate_file.read()
return re.findall(
r"## Image rotation update from [0-9]{4}-[0-9]{2}-[0-9]{2}:", file_content
)
def generate_news(image_update_dates):
"""Generates news with image update news"""
with open(DOC_NEWS_FILE, "r", encoding="utf-8") as news_file:
news_content = news_file.readlines()
news_content = [line.strip() for line in news_content]
for update_date in image_update_dates:
update_date = datetime.datetime.strptime(
update_date, "## Image rotation update from %Y-%m-%d:"
)
for line_idx, line in enumerate(news_content):
if re.match(r".*\*\*[0-9]{4}-[0-9]{2}-[0-9]{2}\*\*.*", line):
news_date = line.split("**")[1]
news_date = datetime.datetime.strptime(news_date, "%Y-%m-%d")
if update_date > news_date or line_idx == len(news_content) - 1:
update_date = datetime.datetime.strftime(update_date, "%Y-%m-%d")
new_entry = [
f"**{update_date}** Image rotation update, details [here](https://docs.cloud.muni.cz/"
f"cloud/image-rotation/image-rotation-update-from-{update_date})",
]
news_content = (
news_content[:line_idx] + new_entry + [""] + news_content[line_idx:]
if line_idx != len(news_content) - 1
else news_content + [""] + new_entry
)
break
with open(DOC_NEWS_FILE, "w", encoding="utf-8") as news_file:
news_file.write("\n".join(news_content))
if __name__ == "__main__":
IMAGE_UPDATE_DATES = get_image_update_log_dates()
if IMAGE_UPDATE_DATES:
generate_news(IMAGE_UPDATE_DATES)
---
title: "Image rotation journal"
date: 2022-01-23T20:31:35+02:00
draft: false
disableToc: true
GeekdocHidden: true
---
# Image rotation news
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment