From e955973ff6a712fa7341a2515310ab5e49e4c4da Mon Sep 17 00:00:00 2001 From: jnsbck <65561470+jnsbck@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:11:23 +0100 Subject: [PATCH] Ensure Changelog is updated with every PR. (#537) * add: add changelog tests. Should fail since no changelog changes made yet. * doc: edit changelog * enh: add chores workflow as example * fix: rename tests to chores * fix: fix license header test * fix: refactor workflows * fix: small fixes * fix: rebase and rm regression tests from tests * fix: rebase regression_tests to main * fix: more informative printout --- .github/workflows/tests.yml | 93 ++++++++++++++++++++++++++++++++++--- CHANGELOG.md | 4 +- tests/test_misc.py | 21 --------- 3 files changed, 90 insertions(+), 28 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1750f290..9a228cd5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: @@ -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 " + + 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 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 54144e69..4756040b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). @@ -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 diff --git a/tests/test_misc.py b/tests/test_misc.py index 75698747..ca384ebf 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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 """ - - -@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