Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Generate Changelog Workflow #106

Merged
merged 2 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/generate-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Generate Changelog
on:
workflow_dispatch:
inputs:
target:
description: Target Owner/Repo
required: true
branch:
description: The branch or reference name to filter pull requests by
required: false
convert_to_rst:
description: Whether to convert to RST
required: false
since:
description: Use PRs with activity since this date or git reference
required: false
until:
description: Use PRs with activity until this date or git reference
required: false
jobs:
build:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu]
python-version: ["3.9"]
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: "x64"
- name: Upgrade packaging dependencies
run: |
pip install --upgrade pip setuptools wheel --user
- name: Install the Python dependencies
run: |
sudo apt-get install pandoc
pip install pypandoc
pip install -e .
- name: List installed packages
run: |
pip freeze
pip check
- name: Generate the Changelog
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export INPUT_BRANCH=${{ github.event.inputs.branch }}
export INPUT_SINCE=${{ github.event.inputs.since }}
export INPUT_UNTIL=${{ github.event.inputs.until }}
export INPUT_CONVERT_TO_RST=${{ github.event.inputs.convert_to_rst }}
python -m jupyter_releaser.actions.generate-changelog ${{ github.event.inputs.target }}
cat changelog.md
- uses: actions/upload-artifact@v2
with:
name: changelog
path: changelog.md
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ jobs:
if: ${{ matrix.os != 'ubuntu' }}
run: |
pytest -vv -s
- name: Verify the Generate Changelog Action
env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET: https://github.com/jupyter-server/jupyter_releaser
INPUT_BRANCH: master
INPUT_SINCE: v0.3.0
INPUT_UNTIL: v0.4.0
run: |
python -m jupyter_releaser.actions.generate-changelog ${{ env.TARGET }}
cat changelog.md
- name: Coverage
run: |
codecov
25 changes: 25 additions & 0 deletions jupyter_releaser/actions/generate-changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import sys
from pathlib import Path

from jupyter_releaser.changelog import get_version_entry

target = sys.argv[-1]
branch = os.environ.get("INPUT_BRANCH")
since = os.environ.get("INPUT_SINCE")
until = os.environ.get("INPUT_UNTIL")
convert_to_rst = os.environ.get("INPUT_CONVERT_TO_RST", "")

print("Generating changelog")
print("target:", target)
print("branch:", branch)
print("convert to rst:", convert_to_rst)

output = get_version_entry(branch, target, "current", since=since, until=until)
if convert_to_rst.lower() == "true":
from pypandoc import convert_text

output = convert_text(output, "rst", "markdown")
print("\n\n------------------------------")
print(output, "------------------------------\n\n")
Path("changelog.md").write_text(output, encoding="utf-8")
7 changes: 6 additions & 1 deletion jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_version_entry(
version,
*,
since=None,
until=None,
auth=None,
resolve_backports=False,
remote="origin",
Expand All @@ -62,6 +63,8 @@ def get_version_entry(
The new version
since: str
Use PRs with activity since this date or git reference
until: str, option
Use PRs until this date or git reference
auth : str, optional
The GitHub authorization token
resolve_backports: bool, optional
Expand All @@ -84,7 +87,9 @@ def get_version_entry(

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

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

md = generate_activity_md(
Expand Down