Skip to content

Commit

Permalink
fix: added workflow deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsbck committed Dec 3, 2024
1 parent 2936dc4 commit c85c6c6
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,43 @@ jobs:
- name: Check formatting with black
id: black
if: always() # Run this step even if the previous one fails
run: |
black --check jaxley tests
black --check jaxley tests || exit 1
continue-on-error: true

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

- 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
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
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"
Expand All @@ -87,8 +75,21 @@ jobs:
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" ||
Expand All @@ -101,10 +102,10 @@ jobs:
pytest:
name: Pytest
runs-on: ubuntu-20.04
needs: chores # Ensure pytest runs only after chores are completed
needs: chores # Ensure pytest only runs if chores finishes

# Run pytest only if black, isort, and license pass
if: ${{ success() && steps.black.outcome == 'success' && steps.isort.outcome == 'success' && steps.license.outcome == 'success' }}
# Run pytest only if chores steps (except changelog) were successful
if: ${{ needs.chores.result == 'success' && env.chores_success == 'true' }}

steps:
- uses: actions/checkout@v3
Expand Down

0 comments on commit c85c6c6

Please sign in to comment.