Skip to content

Commit

Permalink
fix: refactor workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsbck committed Dec 3, 2024
1 parent bb3141f commit 6236ab0
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 140 deletions.
99 changes: 0 additions & 99 deletions .github/workflows/chores.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/regression_tests.yml
Original file line number Diff line number Diff line change
@@ -1,39 +0,0 @@
# .github/workflows/regression_tests.yml
name: Regression Tests

on:
pull_request:
branches:
- main

jobs:
regression_tests:
name: regression_tests
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0 # This ensures we can checkout main branch too

- 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: Run benchmarks and compare to baseline
if: github.event.pull_request.base.ref == 'main'
run: |
# Check if regression test results exist in main branch
if [ -f 'git cat-file -e main:tests/regression_test_baselines.json' ]; then
git checkout main tests/regression_test_baselines.json
else
echo "No regression test results found in main branch"
fi
pytest -m regression
127 changes: 125 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,103 @@ name: Tests
on:
push:
branches:
- main
- main
pull_request:
branches:
- main

jobs:
build:
chores:
name: Chores
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_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 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"
# Regular Tests Job
pytest:
name: Tests
runs-on: ubuntu-20.04

Expand All @@ -32,3 +122,36 @@ jobs:
run: |
pip install pytest pytest-cov
pytest tests/ -m "not regression" --cov=jaxley --cov-report=xml
# Regression Tests Job
regression_tests:
name: Regression Tests
runs-on: ubuntu-20.04
needs: pytest # This ensures that regression tests only run if the pytest job is successful

steps:
- uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0 # This ensures we can checkout the main branch too

- 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: Run benchmarks and compare to baseline
if: github.event.pull_request.base.ref == 'main' # Run only for PRs targeting the 'main' branch
run: |
# Check if regression test results exist in main branch
if git cat-file -e main:tests/regression_test_baselines.json; then
git checkout main tests/regression_test_baselines.json
else
echo "No regression test results found in main branch"
fi
pytest -m regression

0 comments on commit 6236ab0

Please sign in to comment.