Skip to content
Draft
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
52 changes: 45 additions & 7 deletions .github/workflows/changelog_entry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,56 @@ on:
pull_request:
branches: [ main ]

permissions:
contents: read

jobs:
check-changelog:
name: Check changelog fragment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Check for changelog fragment
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
FRAGMENTS=$(find changelog.d -type f ! -name '.gitkeep' | wc -l)
if [ "$FRAGMENTS" -eq 0 ]; then
echo "::error::No changelog fragment found in changelog.d/"
echo "Add one with: echo 'Description.' > changelog.d/\$(git branch --show-current).<type>.md"
echo "Types: added, changed, fixed, removed, breaking"
exit 1
fi
python - <<'PYTHON'
import os
import subprocess
import tomllib
from pathlib import Path

with open("pyproject.toml", "rb") as pyproject:
config = tomllib.load(pyproject)["tool"]["towncrier"]
directory = Path(config["directory"])
types = {entry["directory"] for entry in config["type"]}

# HEAD is GitHub's test merge commit for this pull request.
added = subprocess.check_output([
"git", "diff", "--find-renames", "--diff-filter=A", "--name-only",
"-z", os.environ["BASE_SHA"], "HEAD", "--", str(directory),
])
for name in filter(None, added.split(b"\0")):
path = Path(os.fsdecode(name))
stem, _, category = path.name.removesuffix(".md").rpartition(".")
if (
path.parent == directory
and stem.strip()
and category in types
and path.is_file()
and not path.is_symlink()
):
break
else:
print(
f"::error::Add a changelog fragment at {directory}/<name>.<type>.md."
f" Configured types: {', '.join(sorted(types))}."
)
raise SystemExit(1)
PYTHON
16 changes: 5 additions & 11 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
- All files must end with a newline character
- **ALWAYS run `make format` before committing** - this will auto-fix most style issues
- Run `make lint` after formatting to check if there are any remaining issues
- Code formatting uses `ruff format` (79-char line length configured in pyproject.toml)
- `ruff format` uses its default 88-character line length. The Makefile sets a 79-character wrap width for `docformatter`.

## Changelog Requirements
- Every PR must include a `changelog.d/` file at the root
- Format:
```yaml
- bump: patch|minor|major
changes:
added|changed|removed|fixed:
- Description of change
```
- The file must not be empty and must end with a newline
- Every PR targeting `main` must add a fragment under the root `changelog.d/` directory.
- Name it `changelog.d/<name>.<type>.md`, for example `changelog.d/fix-copy-performance.fixed.md`.
- The types in `pyproject.toml` determine the version bump. Use `fixed` or `changed` for a patch, `added` or `removed` for a minor bump, and `breaking` for a major bump.
- Write a brief description of the change in Markdown and end the file with a newline.

## Testing
- Install development dependencies first: `make install` or `pip install -e ".[dev]"`
Expand All @@ -37,7 +32,6 @@
## Dependencies
- Dependencies are managed in `pyproject.toml`
- Optional dependencies go in `[project.optional-dependencies]`
- When removing dependencies, also remove from `microdf/_optional.py` VERSIONS dict

## Documentation
- Documentation notebooks are in `docs/` directory
Expand Down
1 change: 1 addition & 0 deletions changelog.d/fix-copy-performance.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed O(N²) weight linking in MicroDataFrame.copy()
4 changes: 0 additions & 4 deletions changelog.d/fix-copy-performance.yaml

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/migrate-to-app-token.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Migrate versioning workflow from the expired POLICYENGINE_GITHUB PAT to a short-lived GitHub App token, matching the pattern already used by policyengine-us and policyengine-api.
4 changes: 0 additions & 4 deletions changelog.d/migrate-to-app-token.yaml

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/require-pr-fragment.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Require each pull request to add a changelog fragment with a configured type.
40 changes: 40 additions & 0 deletions tests/ci/test_bump_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pathlib import Path
from runpy import run_path

import pytest

script = run_path(str(Path(__file__).resolve().parents[2] / ".github/bump_version.py"))
infer_bump = script["infer_bump"]
bump_version = script["bump_version"]


@pytest.mark.parametrize(
("names", "expected"),
[
(["change.fixed.md"], "patch"),
(["change.changed"], "patch"),
(["fix.fixed.md", "feature.added.md"], "minor"),
(["feature.removed.md"], "minor"),
(["feature.added.md", "api.breaking.md"], "major"),
],
)
def test_infer_bump(tmp_path, names, expected):
for name in names:
(tmp_path / name).touch()
assert infer_bump(tmp_path) == expected


def test_infer_bump_without_fragments(tmp_path, capsys):
(tmp_path / ".gitkeep").touch()
with pytest.raises(SystemExit) as exc:
infer_bump(tmp_path)
assert exc.value.code == 1
assert capsys.readouterr().err == "No changelog fragments found\n"


@pytest.mark.parametrize(
("bump", "expected"),
[("major", "2.0.0"), ("minor", "1.3.0"), ("patch", "1.2.10")],
)
def test_bump_version(bump, expected):
assert bump_version("1.2.9", bump) == expected
Loading