Ensure Changelog is updated with every PR. #1512
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
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 | ||
run: | | ||
black --check jaxley tests || exit 1 | ||
continue-on-error: true | ||
- name: Check imports with isort | ||
id: isort | ||
run: | | ||
isort -c jaxley tests || exit 1 | ||
continue-on-error: true | ||
- name: Check license headers | ||
id: license | ||
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 | ||
file_header_1=$(head -n 1 "$file") | ||
file_header_2=$(head -n 2 "$file" | tail -n 1) | ||
if [ "$file_header_1" != "$expected_header_1" ]; then | ||
echo "❌ Incorrect first line in $file" | ||
exit_code=1 | ||
fi | ||
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 | ||
run: | | ||
git fetch origin main | ||
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: Set success flags | ||
id: success_flags | ||
run: | | ||
if [[ "${{ steps.black.outcome }}" == "success" && | ||
"${{ steps.isort.outcome }}" == "success" && | ||
"${{ steps.license.outcome }}" == "success" ]]; then | ||
echo "chores_success=true" >> $GITHUB_ENV | ||
else | ||
echo "chores_success=false" >> $GITHUB_ENV | ||
fi | ||
- name: Final check | ||
id: final_check | ||
run: | | ||
# Check if black, isort, license, and changelog steps passed | ||
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 | ||
needs: chores # Ensure pytest only runs if chores finishes | ||
# Run pytest only if chores steps (except changelog) were successful | ||
if: ${{ needs.chores.result == 'success' && env.chores_success == 'true' }} | ||
Check failure on line 108 in .github/workflows/tests.yml GitHub Actions / TestsInvalid workflow file
|
||
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 | ||
regression_tests: | ||
name: Regression Tests | ||
runs-on: ubuntu-20.04 | ||
needs: pytest # Ensure regression tests are only run if pytest job passes | ||
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 |