Skip to content

Commit 868d90b

Browse files
committed
Add Generate Changelog Workflow
Adds a manual workflow to generate a changelog entry for a repo that either does not use `jupyter_releaser` or requires a changelog entry for an older release. Also supports changelogs written in RST.
1 parent b7ea1e6 commit 868d90b

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Generate Changelog
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
target:
6+
description: Target Owner/Repo
7+
required: true
8+
branch:
9+
description: The branch or reference name to filter pull requests by
10+
required: false
11+
convert_to_rst:
12+
description: Whether to convert to RST
13+
required: false
14+
since:
15+
description: Use PRs with activity since this date or git reference
16+
required: false
17+
until:
18+
description: Use PRs with activity until this date or git reference
19+
required: false
20+
jobs:
21+
build:
22+
runs-on: ${{ matrix.os }}-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: [ubuntu]
27+
python-version: ["3.9"]
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v1
31+
- name: Install Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v1
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
architecture: "x64"
36+
- name: Upgrade packaging dependencies
37+
run: |
38+
pip install --upgrade pip setuptools wheel --user
39+
- name: Install the Python dependencies
40+
run: |
41+
sudo apt-get install pandoc
42+
pip install pypandoc
43+
pip install -e .
44+
- name: List installed packages
45+
run: |
46+
pip freeze
47+
pip check
48+
- name: Generate the Changelog
49+
env:
50+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
export INPUT_BRANCH=${{ github.event.inputs.branch }}
53+
export INPUT_SINCE=${{ github.event.inputs.since }}
54+
export INPUT_UNTIL=${{ github.event.inputs.until }}
55+
export INPUT_CONVERT_TO_RST=${{ github.event.inputs.convert_to_rst }}
56+
python -m jupyter_releaser.actions.generate-changelog ${{ github.event.inputs.target }}
57+
cat changelog.md
58+
- uses: actions/upload-artifact@v2
59+
with:
60+
name: changelog
61+
path: changelog.md

.github/workflows/test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ jobs:
119119
if: ${{ matrix.os != 'ubuntu' }}
120120
run: |
121121
pytest -vv -s
122+
- name: Verify the Generate Changelog Action
123+
env:
124+
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
TARGET: https://github.com/jupyter-server/jupyter_releaser
126+
INPUT_BRANCH: master
127+
INPUT_SINCE: v0.3.0
128+
INPUT_UNTIL: v0.4.0
129+
run: |
130+
python -m jupyter_releaser.actions.generate-changelog ${{ env.TARGET }}
131+
cat changelog.md
122132
- name: Coverage
123133
run: |
124134
codecov
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import sys
3+
from pathlib import Path
4+
5+
from jupyter_releaser.changelog import get_version_entry
6+
7+
target = sys.argv[-1]
8+
branch = os.environ.get("INPUT_BRANCH")
9+
since = os.environ.get("INPUT_SINCE")
10+
until = os.environ.get("INPUT_UNTIL")
11+
convert_to_rst = os.environ.get("INPUT_CONVERT_TO_RST", "")
12+
13+
print("Generating changelog")
14+
print("target:", target)
15+
print("branch:", branch)
16+
print("convert to rst:", convert_to_rst)
17+
18+
output = get_version_entry(branch, target, "current", since=since, until=until)
19+
if convert_to_rst.lower() == "true":
20+
from pypandoc import convert_text
21+
22+
output = convert_text(output, "rst", "markdown")
23+
print("\n\n------------------------------")
24+
print(output, "------------------------------\n\n")
25+
Path("changelog.md").write_text(output, encoding="utf-8")

jupyter_releaser/changelog.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def get_version_entry(
4646
version,
4747
*,
4848
since=None,
49+
until=None,
4950
auth=None,
5051
resolve_backports=False,
5152
remote="origin",
@@ -62,6 +63,8 @@ def get_version_entry(
6263
The new version
6364
since: str
6465
Use PRs with activity since this date or git reference
66+
until: str, option
67+
Use PRs until this date or git reference
6568
auth : str, optional
6669
The GitHub authorization token
6770
resolve_backports: bool, optional
@@ -84,7 +87,9 @@ def get_version_entry(
8487

8588
util.log(f"Getting changes to {repo} since {since} on branch {branch}...")
8689

87-
until = util.run(f'git --no-pager log -n 1 {remote}/{branch} --pretty=format:"%H"')
90+
until = until or util.run(
91+
f'git --no-pager log -n 1 {remote}/{branch} --pretty=format:"%H"'
92+
)
8893
until = until.replace("%", "")
8994

9095
md = generate_activity_md(

0 commit comments

Comments
 (0)