Skip to content

Commit ff81141

Browse files
CI: added a check that CHANGELOG.md is modified on feature branches
1 parent d2bfbf6 commit ff81141

File tree

3 files changed

+109
-47
lines changed

3 files changed

+109
-47
lines changed

.github/workflows/main.yml

Lines changed: 76 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,88 @@
11
name: Python Tests
22

33
on:
4-
push:
4+
push:
55
branches:
66
- '*'
77

88
jobs:
9-
test:
9+
changelog-check:
10+
# Do not run this on master itself
11+
if: github.ref != 'refs/heads/master'
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # we need history to diff properly
18+
19+
- &install-task # define a YAML anchor to re-use this task in other jobs
20+
name: Install task to make use of Taskfile.yml
21+
run: |
22+
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
23+
task --version
24+
25+
- name: Verify CHANGELOG.md was updated
26+
run: |
27+
task check-changelog
28+
29+
test:
30+
needs: changelog-check # ensures this runs first
1031
runs-on: ubuntu-latest
1132
strategy:
1233
matrix:
1334
python-version: [3.11, 3.12, 3.13, 3.14]
35+
1436
steps:
15-
- uses: actions/checkout@v4
16-
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v5
18-
with:
19-
python-version: ${{ matrix.python-version }}
20-
check-latest: true
21-
- name: Install task to make use of Taskfile.yml
22-
run: |
23-
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
24-
task --version
25-
- name: Install dependencies
26-
run: |
27-
task dependencies-with-pip
28-
pip install -U coveralls
29-
- name: Run tests with pytest
30-
run: |
31-
task tests-with-cov
32-
- name: Coveralls
33-
uses: coverallsapp/github-action@v2.3.6
34-
with:
35-
github-token: ${{ secrets.GITHUB_TOKEN }}
36-
file: .coverage
37-
deploy:
38-
needs: test
39-
runs-on: ubuntu-latest
40-
if: github.ref == 'refs/heads/master'
41-
environment:
42-
name: pypi-deployment
43-
steps:
44-
- uses: actions/checkout@v4
45-
- name: Set up Python
46-
uses: actions/setup-python@v5
47-
with:
48-
python-version: 3.12
49-
- name: Install Build Tools
50-
run: |
51-
pip install -U build twine
52-
- name: Set Twine Environment Variables
53-
run: |
54-
echo "TWINE_USERNAME=${{ secrets.PYPI_USERNAME }}" >> $GITHUB_ENV
55-
echo "TWINE_PASSWORD=${{ secrets.PYPI_PASSWORD }}" >> $GITHUB_ENV
56-
- name: Build and Upload to PyPI
57-
run: |
58-
python -m build
59-
twine upload dist/*
37+
- uses: actions/checkout@v4
38+
39+
- name: Set up Python ${{ matrix.python-version }}
40+
uses: actions/setup-python@v5
41+
with:
42+
python-version: ${{ matrix.python-version }}
43+
check-latest: true
44+
45+
- *install-task # see above
46+
47+
- name: Install dependencies
48+
run: |
49+
task dependencies-with-pip
50+
pip install -U coveralls
51+
52+
- name: Run tests with pytest
53+
run: |
54+
task tests-with-cov
55+
56+
- name: Coveralls
57+
uses: coverallsapp/github-action@v2.3.6
58+
with:
59+
github-token: ${{ secrets.GITHUB_TOKEN }}
60+
file: .coverage
61+
62+
deploy:
63+
needs: test
64+
runs-on: ubuntu-latest
65+
if: github.ref == 'refs/heads/master'
66+
environment:
67+
name: pypi-deployment
68+
steps:
69+
- uses: actions/checkout@v4
70+
71+
- name: Set up Python
72+
uses: actions/setup-python@v5
73+
with:
74+
python-version: 3.12
75+
76+
- name: Install Build Tools
77+
run: |
78+
pip install -U build twine
79+
80+
- name: Set Twine Environment Variables
81+
run: |
82+
echo "TWINE_USERNAME=${{ secrets.PYPI_USERNAME }}" >> $GITHUB_ENV
83+
echo "TWINE_PASSWORD=${{ secrets.PYPI_PASSWORD }}" >> $GITHUB_ENV
84+
85+
- name: Build and Upload to PyPI
86+
run: |
87+
python -m build
88+
twine upload dist/*

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- added `Taskfile.yml` and use it in CI
1111
- removed `create_pdoc.sh`
1212
- moved `examples` out of the package
13+
- CI: added a check that `CHANGELOG.md` is modified on feature branches
1314

1415
## Pedantic 2.4.0
1516
- migrate from unittest to pytest

Taskfile.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,42 @@ tasks:
2424
desc: Runs the tests with coverage
2525
cmds:
2626
- pytest --doctest-modules --cov=pedantic --cov-branch --cov-report= --cov-report=term
27+
silent: true
2728
docs:
2829
desc: Creates the HTML documentation
2930
cmds:
3031
- rm -rf ./docs
3132
- pip install pdoc
3233
- pdoc -o docs pedantic
3334
- google-chrome ./docs/index.html
35+
silent: true
36+
check-changelog:
37+
desc: Fails if CHANGELOG.md was not modified compared to master
38+
silent: true
39+
cmds:
40+
- |
41+
set -e
42+
43+
echo "Checking that CHANGELOG.md was updated..."
44+
45+
# Ensure we have master available (works both locally and in CI)
46+
if git show-ref --verify --quiet refs/remotes/origin/master; then
47+
BASE=origin/master
48+
elif git show-ref --verify --quiet refs/heads/master; then
49+
BASE=master
50+
else
51+
echo "❌ Could not find master branch to diff against."
52+
exit 1
53+
fi
54+
55+
# Fetch latest master if we're in a repo with a remote
56+
git fetch origin master >/dev/null 2>&1 || true
57+
58+
if git diff --name-only "$BASE"...HEAD | grep -qx "CHANGELOG.md"; then
59+
echo "✅ CHANGELOG.md was updated."
60+
else
61+
echo "❌ CHANGELOG.md was NOT updated."
62+
echo ""
63+
echo "Please add an entry describing your change."
64+
exit 1
65+
fi

0 commit comments

Comments
 (0)