|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + release: |
| 8 | + types: [created] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + python-version: [3.9] |
| 19 | + backend: [tensorflow, jax, torch, numpy] |
| 20 | + name: Run tests |
| 21 | + runs-on: ubuntu-latest |
| 22 | + env: |
| 23 | + PYTHON: ${{ matrix.python-version }} |
| 24 | + KERAS_HOME: .github/workflows/config/${{ matrix.backend }} |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + - name: Check for changes in keras/src/applications |
| 28 | + uses: dorny/paths-filter@v3 |
| 29 | + id: filter |
| 30 | + with: |
| 31 | + filters: | |
| 32 | + applications: |
| 33 | + - 'keras/src/applications/**' |
| 34 | + - name: Set up Python |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: ${{ matrix.python-version }} |
| 38 | + - name: Get pip cache dir |
| 39 | + id: pip-cache |
| 40 | + run: | |
| 41 | + python -m pip install --upgrade pip setuptools |
| 42 | + echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT |
| 43 | + - name: pip cache |
| 44 | + uses: actions/cache@v4 |
| 45 | + with: |
| 46 | + path: ${{ steps.pip-cache.outputs.dir }} |
| 47 | + key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }} |
| 48 | + - name: Install dependencies |
| 49 | + run: | |
| 50 | + pip install -r requirements.txt --progress-bar off --upgrade |
| 51 | + pip uninstall -y keras keras-nightly |
| 52 | + pip install tf_keras==2.16.0 --progress-bar off --upgrade |
| 53 | + pip install -e "." --progress-bar off --upgrade |
| 54 | + - name: Test applications with pytest |
| 55 | + if: ${{ steps.filter.outputs.applications == 'true' }} |
| 56 | + run: | |
| 57 | + pytest keras/src/applications --cov=keras/src/applications |
| 58 | + coverage xml --include='keras/src/applications/*' -o apps-coverage.xml |
| 59 | + - name: Codecov keras.applications |
| 60 | + if: ${{ steps.filter.outputs.applications == 'true' }} |
| 61 | + uses: codecov/codecov-action@v4 |
| 62 | + with: |
| 63 | + env_vars: PYTHON,KERAS_HOME |
| 64 | + flags: keras.applications,keras.applications-${{ matrix.backend }} |
| 65 | + files: apps-coverage.xml |
| 66 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 67 | + fail_ci_if_error: false |
| 68 | + - name: Test integrations |
| 69 | + if: ${{ matrix.backend != 'numpy'}} |
| 70 | + run: | |
| 71 | + python integration_tests/import_test.py |
| 72 | + python integration_tests/numerical_test.py |
| 73 | + - name: Test TF-specific integrations |
| 74 | + if: ${{ matrix.backend == 'tensorflow'}} |
| 75 | + run: | |
| 76 | + python integration_tests/tf_distribute_training_test.py |
| 77 | + - name: Test Torch-specific integrations |
| 78 | + if: ${{ matrix.backend == 'torch'}} |
| 79 | + run: | |
| 80 | + pytest integration_tests/torch_workflow_test.py |
| 81 | + - name: Test with pytest |
| 82 | + run: | |
| 83 | + pytest keras --ignore keras/src/applications --cov=keras |
| 84 | + coverage xml --omit='keras/src/applications/*,keras/api' -o core-coverage.xml |
| 85 | + - name: Codecov keras |
| 86 | + uses: codecov/codecov-action@v4 |
| 87 | + with: |
| 88 | + env_vars: PYTHON,KERAS_HOME |
| 89 | + flags: keras,keras-${{ matrix.backend }} |
| 90 | + files: core-coverage.xml |
| 91 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 92 | + fail_ci_if_error: false |
| 93 | + |
| 94 | + format: |
| 95 | + name: Check the code format |
| 96 | + runs-on: ubuntu-latest |
| 97 | + steps: |
| 98 | + - uses: actions/checkout@v4 |
| 99 | + - name: Set up Python 3.9 |
| 100 | + uses: actions/setup-python@v5 |
| 101 | + with: |
| 102 | + python-version: '3.9' |
| 103 | + - name: Get pip cache dir |
| 104 | + id: pip-cache |
| 105 | + run: | |
| 106 | + python -m pip install --upgrade pip setuptools |
| 107 | + echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT |
| 108 | + - name: pip cache |
| 109 | + uses: actions/cache@v4 |
| 110 | + with: |
| 111 | + path: ${{ steps.pip-cache.outputs.dir }} |
| 112 | + key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }} |
| 113 | + - name: Install dependencies |
| 114 | + run: | |
| 115 | + pip install -r requirements.txt --progress-bar off --upgrade |
| 116 | + pip uninstall -y keras keras-nightly |
| 117 | + pip install -e "." --progress-bar off --upgrade |
| 118 | + - name: Lint |
| 119 | + run: bash shell/lint.sh |
| 120 | + - name: Check for API changes |
| 121 | + run: | |
| 122 | + bash shell/api_gen.sh |
| 123 | + git status |
| 124 | + clean=$(git status | grep "nothing to commit") |
| 125 | + if [ -z "$clean" ]; then |
| 126 | + echo "Please run shell/api_gen.sh to generate API." |
| 127 | + exit 1 |
| 128 | + fi |
0 commit comments