mirror of https://github.com/streamlink/streamlink
Change log as markdown refactor (#1667)
* rename CHANGELOG to md * symlink the change log in to the docs * include the recommonmark parser for md file * reformatted the CHANGELOG md file, should look more or less the same as the RST * refactored the release scripts to handle/generate the new format * file is a bad variable name * couple of minor tweaks, mainly style * Fix git shortlog being highlighted as Python in the docs * update manifest to include changelog.md instead of rst
This commit is contained in:
parent
4ba7f84f7d
commit
deffd929d1
File diff suppressed because it is too large
Load Diff
1729
CHANGELOG.rst
1729
CHANGELOG.rst
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,5 @@
|
|||
include AUTHORS
|
||||
include CHANGELOG.rst
|
||||
include CHANGELOG.md
|
||||
include README.md
|
||||
include LICENSE*
|
||||
include *requirements.txt
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
sphinx>=1.6,<1.7
|
||||
|
||||
recommonmark
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../CHANGELOG.md
|
|
@ -1,6 +0,0 @@
|
|||
.. _changelog:
|
||||
|
||||
Changelog
|
||||
=========
|
||||
|
||||
.. include:: ../CHANGELOG.rst
|
|
@ -24,7 +24,10 @@ extensions = ['sphinx.ext.autodoc', 'ext_argparse', 'ext_github', 'ext_releasere
|
|||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
source_suffix = ['.rst', '.md']
|
||||
source_parsers = {
|
||||
'.md': 'recommonmark.parser.CommonMarkParser',
|
||||
}
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
|
|
@ -1,61 +1,121 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from sys import exit, stderr
|
||||
import argparse
|
||||
import logging
|
||||
import re
|
||||
from os import getenv, path
|
||||
from re import split, IGNORECASE
|
||||
from requests import get, patch
|
||||
from pprint import pprint
|
||||
from sys import exit
|
||||
|
||||
import requests
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
RE_LOG_HEADER = re.compile(r"## streamlink\s+(\d+\.\d+\.\d+(?:-\S+)?)\s+\(\d{4}-\d{2}-\d{2}\)\n+", flags=re.IGNORECASE)
|
||||
RE_GITLOG = re.compile(r"(.*?)(```text\n.*?\n```)", re.DOTALL)
|
||||
TEMPLATE = """
|
||||
{changelog}
|
||||
|
||||
## Installation
|
||||
|
||||
### Installing with Pip:
|
||||
|
||||
```sh
|
||||
sudo pip install streamlink
|
||||
```
|
||||
|
||||
### Manual installation:
|
||||
|
||||
```sh
|
||||
curl -L https://github.com/streamlink/streamlink/releases/download/$2/streamlink-$2.tar.gz -O streamlink.tar.gz
|
||||
tar xvf streamlink.tar.gz
|
||||
cd streamlink
|
||||
sudo python setup.py install
|
||||
```
|
||||
|
||||
## Supporting Streamlink
|
||||
|
||||
If you think that this application is helpful, please consider supporting the maintainers by [donating via the Open collective](https://opencollective.com/streamlink). Not only becoming a backer, but also a sponsor for the (open source) project.
|
||||
|
||||
|
||||
RE_LOG_HEADER = r"streamlink\s+(\d+\.\d+\.\d+(?:-\S+)?)\s+\(\d{4}-\d{2}-\d{2}\)\n(?:-|=){3,}\n+"
|
||||
{gitlog}
|
||||
"""
|
||||
|
||||
|
||||
def checkEnvVar(v):
|
||||
if not getenv(v):
|
||||
raise AssertionError("Missing env var {0}\n".format(v))
|
||||
|
||||
|
||||
def githubAPI(method, url, **kwargs):
|
||||
url = "https://api.github.com/repos/{0}/releases/{1}".format(getenv("TRAVIS_REPO_SLUG"), url)
|
||||
def github_api_call(method, repo, url, api_key, **kwargs):
|
||||
url = "https://api.github.com/repos/{0}/releases/{1}".format(repo, url)
|
||||
headers = {
|
||||
"Accept": "application/vnd.github.v3+json",
|
||||
"User-Agent": getenv("TRAVIS_REPO_SLUG"),
|
||||
"Authorization": "token {0}".format(getenv("RELEASES_API_KEY"))
|
||||
"User-Agent": repo,
|
||||
"Authorization": "token {0}".format(api_key)
|
||||
}
|
||||
return (get if method != "PATCH" else patch)(url, headers=headers, **kwargs)
|
||||
return (requests.get if method != "PATCH" else requests.patch)(url, headers=headers, **kwargs)
|
||||
|
||||
|
||||
try:
|
||||
# Make sure that all required env vars are set
|
||||
[checkEnvVar(v) for v in ["TRAVIS_REPO_SLUG", "TRAVIS_TAG", "RELEASES_API_KEY"]]
|
||||
def main(tag, repo, api_key, dry_run=False):
|
||||
try:
|
||||
cl_path = path.abspath(path.join(path.dirname(__file__), "../CHANGELOG.md"))
|
||||
log.debug("Opening changelog file: {}".format(cl_path))
|
||||
|
||||
# Parse changelog file
|
||||
file = path.abspath("{0}/{1}".format(path.dirname(__file__), "../CHANGELOG.rst"))
|
||||
contents = open(file).read()
|
||||
if not contents:
|
||||
raise AssertionError("Missing changelog file")
|
||||
with open(cl_path, 'r') as fh:
|
||||
contents = fh.read()
|
||||
if not contents:
|
||||
raise ValueError("Missing changelog file")
|
||||
|
||||
changelogs = split(RE_LOG_HEADER, contents, flags=IGNORECASE)[1:]
|
||||
changelogs = {v: changelogs[i + 1] for i, v in enumerate(changelogs) if i % 2 == 0}
|
||||
log.debug("Parsing change log file")
|
||||
changelogs = RE_LOG_HEADER.split(contents)[1:]
|
||||
changelogs = {v: changelogs[i + 1] for i, v in enumerate(changelogs) if i % 2 == 0}
|
||||
|
||||
if not getenv("TRAVIS_TAG") in changelogs:
|
||||
raise AssertionError("Missing changelog for current release")
|
||||
log.debug("Found {} change logs".format(len(changelogs)))
|
||||
|
||||
# Get release ID
|
||||
res = githubAPI("GET", "tags/{0}".format(getenv("TRAVIS_TAG")))
|
||||
data = res.json()
|
||||
if "id" not in data:
|
||||
raise AssertionError("Missing id from Github API response")
|
||||
if tag not in changelogs:
|
||||
raise KeyError("Missing changelog for current release")
|
||||
|
||||
# Update release name and body
|
||||
payload = {
|
||||
"name": "Streamlink {0}".format(getenv("TRAVIS_TAG")),
|
||||
"body": changelogs[getenv("TRAVIS_TAG")]
|
||||
}
|
||||
githubAPI("PATCH", data["id"], json=payload)
|
||||
log.debug("Getting the current release ID for {}#{}".format(repo, tag))
|
||||
res = github_api_call("GET", repo, "tags/{0}".format(tag), api_key)
|
||||
if res.status_code >= 400:
|
||||
log.debug("Release ID fetch failed:")
|
||||
log.debug(res.text)
|
||||
raise ValueError("Unable to get release ID, check API KEY")
|
||||
|
||||
print("Github release {0} has been successfully updated".format(getenv("TRAVIS_TAG")))
|
||||
exit(0)
|
||||
data = res.json()
|
||||
if "id" not in data:
|
||||
raise KeyError("Missing id from Github API response")
|
||||
|
||||
changelog, gitlog = RE_GITLOG.search(changelogs[tag]).groups()
|
||||
|
||||
# Update release name and body
|
||||
payload = {
|
||||
"name": "Streamlink {0}".format(tag),
|
||||
"body": TEMPLATE.format(changelog=changelog.strip(), gitlog=gitlog.strip())
|
||||
}
|
||||
if not dry_run:
|
||||
github_api_call("PATCH", repo, data["id"], api_key, json=payload)
|
||||
else:
|
||||
print("[dry-run] Would have updated the GitHub release with the following:")
|
||||
pprint(payload)
|
||||
|
||||
print("Github release {} has been successfully updated".format(tag))
|
||||
return 0
|
||||
|
||||
except Exception:
|
||||
log.exception("Failed to update release info.")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Update release information for GitHub Release")
|
||||
parser.add_argument("--debug", help="Enable debug logging", action="store_true")
|
||||
parser.add_argument("-n", "--dry-run", help="Do nothing, but say what would have happened (--api-key not required)", action="store_true")
|
||||
parser.add_argument("--tag", help="The TAG to update, by default uses env.TRAVIS_TAG", default=getenv("TRAVIS_TAG"))
|
||||
parser.add_argument("--repo", help="The REPO to update, by default uses env.TRAVIS_REPO_SLUG", default=getenv("TRAVIS_REPO_SLUG"))
|
||||
parser.add_argument("--api-key", help="The APIKEY to update, by default uses env.RELEASES_API_KEY", default=getenv("RELEASES_API_KEY"))
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
|
||||
|
||||
if args.tag and args.repo and args.api_key:
|
||||
exit(main(args.tag, args.repo, args.api_key, args.dry_run))
|
||||
else:
|
||||
parser.error("--tag, --repo, and --api-key are all required options")
|
||||
|
||||
except Exception as e:
|
||||
stderr.write("{0}\n".format(str(e)))
|
||||
exit(1)
|
||||
|
|
|
@ -62,37 +62,13 @@ clone() {
|
|||
changelog() {
|
||||
cd $CLI
|
||||
echo "Getting commit changes. Writing to ../changes.txt"
|
||||
LOG=$(git shortlog --email --no-merges --pretty=%s ${1}.. | sed 's/^/ /')
|
||||
echo "Streamlink $2
|
||||
LOG=$(git shortlog --email --no-merges --pretty=%s ${1}..)
|
||||
echo "
|
||||
!!!WRITE YOUR RELEASE NOTES HERE!!!
|
||||
|
||||
!!!WRITE YOUR RELEASE NOTES HERE!!
|
||||
|
||||
# Installation
|
||||
|
||||
**Installing with Pip:**
|
||||
|
||||
\`\`\`sh
|
||||
sudo pip install streamlink
|
||||
\`\`\`
|
||||
|
||||
**Manual installation:**
|
||||
|
||||
\`\`\`sh
|
||||
curl -L https://github.com/streamlink/streamlink/releases/download/$2/streamlink-$2.tar.gz -O streamlink.tar.gz
|
||||
tar xvf streamlink.tar.gz
|
||||
cd streamlink
|
||||
sudo python setup.py install
|
||||
\`\`\`
|
||||
|
||||
# Supporting Streamlink
|
||||
|
||||
If you think that this application is helpful, please consider supporting the maintainers by [donating via the Open collective](https://opencollective.com/streamlink). Not only becoming a backer, but also a sponsor for the (open source) project.
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
$LOG" > ../changes.txt
|
||||
\`\`\`text
|
||||
${LOG}
|
||||
\`\`\`" > ../changes.txt
|
||||
echo "Changelog has been written to changes.txt"
|
||||
echo "!!PLEASE REVIEW BEFORE CONTINUING!!"
|
||||
echo "Open changes.txt and add the release information"
|
||||
|
@ -100,16 +76,15 @@ $LOG" > ../changes.txt
|
|||
cd ..
|
||||
}
|
||||
|
||||
changelog_rst() {
|
||||
echo "Generating CHANGELOG.rst"
|
||||
changelog_md() {
|
||||
echo "Generating CHANGELOG.md"
|
||||
CHANGES=$(cat changes.txt)
|
||||
cd $CLI
|
||||
DATE=$(date +"%Y-%m-%d")
|
||||
CHANGELOG=$(cat CHANGELOG.rst)
|
||||
CHANGELOG=$(cat CHANGELOG.md)
|
||||
HEADER="$CLI $1 ($DATE)"
|
||||
UNDERLINE=$(printf %s "$HEADER" | tr -c '-' '[-*]')
|
||||
echo -e "$HEADER\n$UNDERLINE\n$CHANGES\n\n$CHANGELOG" >CHANGELOG.rst
|
||||
echo "Changes have been written to CHANGELOG.rst"
|
||||
echo -e "# $HEADER\n$CHANGES\n\n$CHANGELOG" >CHANGELOG.md
|
||||
echo "Changes have been written to CHANGELOG.md"
|
||||
cd ..
|
||||
}
|
||||
|
||||
|
@ -274,7 +249,7 @@ main() {
|
|||
changelog $PREV_VERSION $VERSION
|
||||
;;
|
||||
"Generate changelog for release")
|
||||
changelog_rst $VERSION
|
||||
changelog_md $VERSION
|
||||
;;
|
||||
"Create PR")
|
||||
git_commit $VERSION
|
||||
|
|
Loading…
Reference in New Issue