Skip to content

Commit 9664be3

Browse files
authored
Simpler regex and pandoc example and tests (#3)
1 parent 1dcf7a8 commit 9664be3

File tree

10 files changed

+1065
-211
lines changed

10 files changed

+1065
-211
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: test
2+
on:
3+
push: {}
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.6", "3.7", "3.8", "3.9"]
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-python@v2
14+
with:
15+
python-version: ${{ matrix.python-version }}
16+
- run: pip install poetry
17+
- run: poetry install
18+
- run: ./scripts/test

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,39 @@ jobs:
4141
$ pip install changerelease
4242
$ changerelease sync --repo org/repo --token TOKEN
4343
```
44+
45+
## What if my changelog isn't in Markdown?
46+
47+
For changelogs written in reStructuredText or another syntax besides Markdown,
48+
you can run a conversion step before running changerelease.
49+
This can be a custom rendering script or something like [pandoc](https://pandoc.org/) to convert your changelog to Markdown.
50+
The only real expectation is that your version names are written in h2 headings (`## {version_name}`).
51+
52+
```yaml
53+
name: changerelease
54+
on:
55+
workflow_dispatch: {}
56+
push:
57+
paths: [CHANGELOG.md]
58+
branches: [master]
59+
tags: ["*"]
60+
61+
jobs:
62+
sync:
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v2
66+
67+
# Convert to markdown first
68+
# https://github.com/pandoc/pandoc-action-example
69+
- uses: docker://pandoc/core:2.9
70+
with:
71+
args: "CHANGELOG.rst -f rst -t markdown -o CR_CHANGELOG.md"
72+
73+
- uses: dropseed/changerelease@v1
74+
with:
75+
github_token: ${{ secrets.GITHUB_TOKEN }}
76+
# optional
77+
tag_prefix: v
78+
changelog: CR_CHANGELOG.md
79+
```

changerelease/changelog.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33

44
SKIP_VERSIONS = ["Unreleased"]
5+
RE_VERSION_HEADING = r"## "
6+
RE_VERSION_NAME = r"\[?([^\[\]\s]+)\]?"
7+
RE_VERSION_CONTENTS = r"([\s\S]+?)"
8+
RE_LINK_DEFINITIONS = r"\[.+\]: "
9+
RE_VERSION_HEADING_LINE = f"^{RE_VERSION_HEADING}{RE_VERSION_NAME}.*$"
510

611

712
class Changelog:
@@ -11,13 +16,13 @@ def __init__(self, path, contents):
1116
self.versions = self.parse_versions()
1217

1318
def parse_versions(self):
14-
version_names = re.findall("^## \[(.+)\].*$", self.contents, re.MULTILINE)
19+
version_names = re.findall(RE_VERSION_HEADING_LINE, self.contents, re.MULTILINE)
1520
version_names = [x for x in version_names if x not in SKIP_VERSIONS]
1621
return version_names
1722

1823
def parse_version_content(self, version):
1924
matches = re.findall(
20-
f"^## \[{version}\].*$([\s\S]+?)^(## |\[.+\]: )",
25+
f"^{RE_VERSION_HEADING}\[?{version}\]?.*${RE_VERSION_CONTENTS}^({RE_VERSION_HEADING}|{RE_LINK_DEFINITIONS})",
2126
self.contents,
2227
re.MULTILINE,
2328
)

0 commit comments

Comments
 (0)