From c85c6c603f633d9a24061b95a2bbe753a8933186 Mon Sep 17 00:00:00 2001 From: jnsbck-uni Date: Tue, 3 Dec 2024 19:48:35 +0100 Subject: [PATCH] fix: added workflow deps --- .github/workflows/tests.yml | 61 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f55ddc3f..c682e8fe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 " 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" @@ -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" || @@ -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