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

Ensure Changelog is updated with every PR. #537

Merged
merged 10 commits into from
Dec 18, 2024
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
93 changes: 87 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ name: Tests
on:
push:
branches:
- main
- main
pull_request:
branches:
- main

jobs:
build:
name: Tests
chores:
name: Chores
runs-on: ubuntu-20.04

steps:
Expand All @@ -27,16 +27,97 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Check formatting with black
id: black
if: always() # Run this step even if the previous one fails
run: |
black --check jaxley tests

- name: Check imports with isort
id: isort
if: always() # Run this step even if the previous one fails
run: |
isort -c jaxley tests

- name: Check license headers
id: license
if: always() # Run this step even if the previous one fails
run: |
expected_header_1="# This file is part of Jaxley, a differentiable neuroscience simulator. Jaxley is"
expected_header_2="# licensed under the Apache License Version 2.0, see <https://www.apache.org/licenses/>"

exit_code=0

while IFS= read -r file; do
# Extract the first two lines of the file
file_header_1=$(head -n 1 "$file")
file_header_2=$(head -n 2 "$file" | tail -n 1)

# Compare the first line
if [ "$file_header_1" != "$expected_header_1" ]; then
echo "❌ Incorrect first line in $file"
exit_code=1
fi

# Compare the second line
if [ "$file_header_2" != "$expected_header_2" ]; then
echo "❌ Incorrect second line in $file"
exit_code=1
fi
done < <(find jaxley tests -name "*.py" -type f)

if [ $exit_code -ne 0 ]; then
exit 1
fi

- name: Ensure that the changelog was updated
id: changelog
if: always() # Run this step even if the previous one fails
run: |
# Ensure the main branch is up-to-date
git fetch origin main

# Check if CHANGELOG.md was updated
changed_files=$(git diff --name-only origin/main)
if echo "$changed_files" | grep -q 'CHANGELOG.md'; then
echo "CHANGELOG.md was updated"
else
echo "CHANGELOG.md was not updated. Please add your changes if significant. Otherwise, this check can be safely ignored."
exit 1
fi

- name: Final check
run: |
if [[ "${{ steps.black.outcome }}" != "success" ||
"${{ steps.isort.outcome }}" != "success" ||
"${{ steps.license.outcome }}" != "success" ||
"${{ steps.changelog.outcome }}" != "success" ]]; then
echo "❌ Some checks failed!"
exit 1
fi
echo "✅ All checks passed"

pytest:
name: Pytest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
with:
lfs: true

- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/ -m "not regression" --cov=jaxley --cov-report=xml
pytest tests/ -m "not regression" --cov=jaxley --cov-report=xml
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
net.record("i_IonotropicSynapse")
```
- Add regression tests and supporting workflows for maintaining baselines (#475, #546, @jnsbck).
- Regression tests can be triggered by commenting on a PR.
- Regression tests can be triggered by commenting "/test_regression" on a PR.
- Regression tests can be done locally by running `NEW_BASELINE=1 pytest -m regression` i.e. on `main` and then `pytest -m regression` on `feature`, which will produce a test report (printed to the console and saved to .txt).

- refactor plotting (#539, @jnsbck).
Expand All @@ -21,6 +21,8 @@ net.vis()

- Allow parameter sharing for groups of different sizes, i.e. due to inhomogenous numbers of compartments or for synapses with the same (pre-)synaptic parameters but different numbers of post-synaptic partners. (#514, @jnsbck)

- changelog added to CI

# 0.5.0

### API changes
Expand Down
21 changes: 0 additions & 21 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@
import pytest


def list_files(directory):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".py"):
yield os.path.join(root, file)


license_txt = """# This file is part of Jaxley, a differentiable neuroscience simulator. Jaxley is
# licensed under the Apache License Version 2.0, see <https://www.apache.org/licenses/>"""


@pytest.mark.parametrize("dir", ["../jaxley", "."])
def test_license(dir):
for i, file in enumerate(list_files(dir)):
with open(file, "r") as f:
header = f.read(len(license_txt))
assert (
header == license_txt
), f"File {file} does not have the correct license header"


def test_rm_all_deprecated_functions():
from jaxley.__version__ import __version__ as package_version

Expand Down