Skip to content

Commit

Permalink
enh: add chores workflow as example
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsbck committed Dec 3, 2024
1 parent 36241ee commit a5a1eb9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 43 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/chores.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Tests
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: 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="# This file is part of Jaxley, a differentiable neuroscience simulator. Jaxley is\n# licensed under the Apache License Version 2.0, see <https://www.apache.org/licenses/>"
exit_code=0
while IFS= read -r file; do
header=$(head -n 2 "$file")
if [ "$header" != "$expected_header" ]; then
echo "❌ Missing or incorrect license header in $file"
exit_code=1
fi
done < <(find jaxley tests -name "*.py" -type f)
if [ $exit_code -ne 0 ]; then
echo "License header check failed"
exit 1
fi
- name: Ensure that the changelog reflects the changes
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"
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"
22 changes: 0 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Check formatting with black
run: |
black --check jaxley tests
- name: Check imports with isort
run: |
isort -c jaxley tests
- name: Ensure that the changelog reflects the changes
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"
exit 1
fi
- name: Test with pytest
run: |
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

0 comments on commit a5a1eb9

Please sign in to comment.