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

fix(git, build): provide version to auto-changelog #31

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
- name: Install base dependencies
run: poetry install --sync --only base
- name: Bump version and changelog
run: poetry run invoke release.install release.build -- -v ${{ github.event.inputs.version }}
run: |
entry="$(poetry run invoke release.install release.build -- -v ${{ github.event.inputs.version }})"
echo "entry=$entry" >> $GITHUB_OUTPUT
- name: Create pull request
uses: peter-evans/create-pull-request@v5.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "release: v${{ github.event.inputs.version }}"
title: "release: v${{ github.event.inputs.version }}"
body: >
This PR is auto-generated by
[create-pull-request](https://github.com/peter-evans/create-pull-request).
body: ${{ steps.vars.outputs.entry }}
branch: release/${{ github.event.inputs.version }}
23 changes: 21 additions & 2 deletions make/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import re
from pathlib import Path
from typing import Pattern

from invoke.config import Config
from invoke.tasks import task
Expand All @@ -19,6 +20,20 @@ def install(c: Config) -> None:
c.run("poetry install --sync --only base,release")


def get_changelog_entry(v: str, /) -> str:
"""Get CHANGELOG.md entry with specified version."""
v: str = re.escape(v)

pattern: Pattern = rf"(?:^|\n)##\sv{v}[^\n]*\n(.*?)(?=\n##?\s|$)"

with open("CHANGELOG.md") as f:
changelog: str = f.read()

if entry := re.search(pattern, changelog, flags=re.DOTALL):
return entry.group(1).strip()
return "No changelog entry found."


@task
def build(c: Config, *, v: str) -> None:
"""Build release."""
Expand All @@ -39,7 +54,11 @@ def build(c: Config, *, v: str) -> None:
f.write(re.sub(r'__version__ = ".*"', f'__version__ = "{v}"', init))

# bump project version - pyproject.toml
c.run(f"poetry version {v}")
c.run(f"poetry version -q {v}")

# auto-generate CHANGELOG.md entry
c.run("poetry run auto-changelog -- --tag-prefix v --github")
c.run(f"poetry run -q auto-changelog -- --tag-prefix v --github -v v{v}")

# print latest changelog entry
entry: str = get_changelog_entry(v)
print(entry) # noqa: T201