1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-18 11:11:34 +03:00
vimr/bin/set_appcast.py

55 lines
1.6 KiB
Python
Raw Normal View History

2020-11-17 22:02:23 +03:00
#!/usr/bin/env python3
2016-10-14 16:58:58 +03:00
2018-03-04 13:36:20 +03:00
# pip3 install requests
# pip3 install Markdown
2016-10-14 16:58:58 +03:00
2018-03-04 13:36:20 +03:00
# We use python of brew due to some pip packages.
2016-10-20 21:59:32 +03:00
import io
2016-10-14 16:58:58 +03:00
import json
2022-03-19 13:14:59 +03:00
import subprocess
import sys
2016-10-14 16:58:58 +03:00
from datetime import datetime
from string import Template
2022-03-19 13:14:59 +03:00
import markdown
import requests
SIGN_UPDATE = './build/SourcePackages/artifacts/sparkle/bin/sign_update'
2016-10-14 16:58:58 +03:00
file_path = sys.argv[1]
bundle_version = sys.argv[2]
marketing_version = sys.argv[3]
tag_name = sys.argv[4]
2016-10-22 10:59:15 +03:00
is_snapshot = True if len(sys.argv) > 5 and sys.argv[5] == "true" else False
2016-10-14 16:58:58 +03:00
2022-03-19 13:14:59 +03:00
file_signature = subprocess.check_output([SIGN_UPDATE, file_path]).decode('utf-8').strip()
2016-10-14 16:58:58 +03:00
appcast_template_file = open('resources/appcast_template.xml', 'r')
appcast_template = Template(appcast_template_file.read())
appcast_template_file.close()
2022-03-19 13:14:59 +03:00
release_response = requests.get('https://api.github.com/repos/qvacua/vimr/releases/tags/{0}'.format(tag_name))
2016-10-14 16:58:58 +03:00
release_json = json.loads(release_response.content)
title = release_json['name']
download_url = release_json['assets'][0]['browser_download_url']
release_notes_url = release_json['html_url']
release_notes = release_json['body']
2016-10-22 11:06:54 +03:00
appcast = appcast_template.substitute(
2016-10-14 16:58:58 +03:00
title=title,
release_notes=markdown.markdown(release_notes),
release_notes_link=release_notes_url,
publication_date=datetime.now().isoformat(),
file_url=download_url,
bundle_version=bundle_version,
marketing_version=marketing_version,
2022-03-19 13:14:59 +03:00
signature_output=file_signature
2016-10-22 11:06:54 +03:00
)
2016-10-14 16:58:58 +03:00
2016-10-14 22:59:36 +03:00
appcast_file_name = 'appcast_snapshot.xml' if is_snapshot else 'appcast.xml'
2017-11-30 00:59:49 +03:00
with io.open('build/Build/Products/Release/{0}'.format(appcast_file_name), 'w+') as appcast_file:
2016-10-20 21:59:32 +03:00
appcast_file.write(appcast)