Skip to content

Commit

Permalink
[auto release notes] Don't forget to convert the markdown release not…
Browse files Browse the repository at this point in the history
…es automatically into HTML and upload them into the appcasts repo
  • Loading branch information
christofmuc committed Jul 9, 2023
1 parent 3894e34 commit ba6c9e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytest==7.1.3
mdutils>=1.4.0
requests>=2.31.0
lxml>=4.9.3
lxml>=4.9.3
markdown>=3.4.3
21 changes: 18 additions & 3 deletions write_appcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile
from datetime import datetime, timezone

import markdown as markdown
import requests
from lxml import etree as ET

Expand Down Expand Up @@ -96,7 +97,7 @@ def get_file_sha(repo_owner, repo_name, file_path, access_token):
return sha


def upload_to_github(updated_xml, repo_owner, repo_name, file_path):
def upload_to_github(updated_xml, repo_owner, repo_name, file_path, is_update: bool):
# Encode the XML content as base64
base64_content = base64.b64encode(updated_xml).decode().strip()

Expand All @@ -111,14 +112,25 @@ def upload_to_github(updated_xml, repo_owner, repo_name, file_path):
data = {
"message": f"Update {file_path}",
"content": base64_content,
"sha": get_file_sha(repo_owner, repo_name, file_path, access_token)
}
if is_update:
# The file already exists
data["sha"] = get_file_sha(repo_owner, repo_name, file_path, access_token)

# Send the API request to update the file
response = requests.put(api_url, json=data, headers=headers)
response.raise_for_status()


def convert_markdown_to_html(markdown_file):
# Read the Markdown file
with open(markdown_file, 'r', encoding='utf-8') as file:
markdown_text = file.read()

# Convert Markdown to HTML
return markdown.markdown(markdown_text)


if __name__ == "__main__":
new_version = get_latest_git_tag()
print(f"Latest Git tag used as appcast version: {new_version}")
Expand All @@ -134,4 +146,7 @@ def upload_to_github(updated_xml, repo_owner, repo_name, file_path):
tmpfile = os.path.join(tmpdir, "appcast.xml")
download_file("https://raw.githubusercontent.com/christofmuc/appcasts/master/KnobKraft-Orm/test_appcast.xml", tmpfile)
new_file = add_release(tmpfile, new_version, sparkle_signature)
upload_to_github(new_file, "christofmuc", "appcasts", "KnobKraft-Orm/test_appcast.xml")
upload_to_github(new_file, "christofmuc", "appcasts", "KnobKraft-Orm/test_appcast.xml", True)
release_notes = os.path.join("release_notes", f"{new_version}.md")
release_notes_as_html = convert_markdown_to_html(release_notes)
upload_to_github(new_file, "christofmuc", "appcasts", f"KnobKraft-Orm/{new_version}.html", False)

0 comments on commit ba6c9e3

Please sign in to comment.