From 3260da83b9e24ef3be0b746362111798fb06ee12 Mon Sep 17 00:00:00 2001 From: guarin <43336610+guarin@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:33:17 +0100 Subject: [PATCH] Check for code changes in github actions (#1500) * Use dorny/paths-filter instead of paths-ignore filters --- .github/workflows/test.yml | 88 +++++++++++++----------- .github/workflows/test_code_format.yml | 2 + .github/workflows/test_minimal_deps.yml | 66 ++++++++++-------- .github/workflows/test_setup.yml | 90 ++++++++++++++----------- 4 files changed, 142 insertions(+), 104 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3c2d1fb60..45dac72be 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,54 +2,64 @@ name: Unit Tests on: push: - paths-ignore: - - 'docs/**' - - 'examples/**' - - 'benchmarks/**' + branches: + - master pull_request: - paths-ignore: - - 'docs/**' - - 'examples/**' - - 'benchmarks/**' workflow_dispatch: - - jobs: + detect-code-changes: + name: Detect Code Changes + runs-on: ubuntu-latest + outputs: + run-tests: ${{ steps.filter.outputs.run-tests }} + steps: + - uses: actions/checkout@v3 + - uses: dorny/paths-filter@v3 + id: filter + with: + list-files: shell + filters: | + run-tests: + - '!docs/**' + - '!examples/**' + - '!benchmarks/**' + test: name: Test + needs: detect-code-changes + if: needs.detect-code-changes.outputs.run-tests == 'true' runs-on: ubuntu-latest strategy: matrix: python: ["3.7", "3.10"] - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - name: Hack to get setup-python to work on nektos/act - run: | - if [ ! -f "/etc/lsb-release" ] ; then - echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release - fi - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: general-env-${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('requirements/**') }} - - name: Install Dependencies and lightly - run: pip install -e '.[all]' - - name: Run Pytest - run: | - export LIGHTLY_SERVER_LOCATION="localhost:-1" - pip install pytest-cov - python -m pytest -s -v --runslow --cov=./lightly --cov-report=xml --ignore=./lightly/openapi_generated/ - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - fail_ci_if_error: false - files: ./coverage.xml - token: ${{ secrets.CODECOV_TOKEN }} + - name: Checkout Code + uses: actions/checkout@v3 + - name: Hack to get setup-python to work on nektos/act + run: | + if [ ! -f "/etc/lsb-release" ] ; then + echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release + fi + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + - uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: general-env-${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('requirements/**') }} + - name: Install Dependencies and lightly + run: pip install -e '.[all]' + - name: Run Pytest + run: | + export LIGHTLY_SERVER_LOCATION="localhost:-1" + pip install pytest-cov + python -m pytest -s -v --runslow --cov=./lightly --cov-report=xml --ignore=./lightly/openapi_generated/ + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + fail_ci_if_error: false + files: ./coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/test_code_format.yml b/.github/workflows/test_code_format.yml index 61eb862fb..33886b7c1 100644 --- a/.github/workflows/test_code_format.yml +++ b/.github/workflows/test_code_format.yml @@ -2,6 +2,8 @@ name: Code Format Check on: push: + branches: + - master pull_request: workflow_dispatch: diff --git a/.github/workflows/test_minimal_deps.yml b/.github/workflows/test_minimal_deps.yml index 3817d4ab6..a7dc12bcb 100644 --- a/.github/workflows/test_minimal_deps.yml +++ b/.github/workflows/test_minimal_deps.yml @@ -2,42 +2,54 @@ name: Minimal Dependency Tests on: push: - paths-ignore: - - 'docs/**' - - 'examples/**' - - 'benchmarks/**' + branches: + - master pull_request: - paths-ignore: - - 'docs/**' - - 'examples/**' - - 'benchmarks/**' workflow_dispatch: jobs: + detect-code-changes: + name: Detect Code Changes + runs-on: ubuntu-latest + outputs: + run-tests: ${{ steps.filter.outputs.run-tests }} + steps: + - uses: actions/checkout@v3 + - uses: dorny/paths-filter@v3 + id: filter + with: + list-files: shell + filters: | + run-tests: + - '!docs/**' + - '!examples/**' + - '!benchmarks/**' + test: name: Test + needs: detect-code-changes + if: needs.detect-code-changes.outputs.run-tests == 'true' runs-on: ubuntu-latest strategy: matrix: python: ["3.7"] - steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - name: Cache Python Dependencies - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: minimal-env-${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('requirements/minimal_requirements.txt') }} - - name: Install Minimal Dependencies - run: pip install -r requirements/minimal_requirements.txt - - name: Install Package Without Dependencies - run: pip install --no-deps . - - name: Run Tests - run: | - export LIGHTLY_SERVER_LOCATION="localhost:-1" - python -m pytest -s -v --runslow + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + - name: Cache Python Dependencies + uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: minimal-env-${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('requirements/minimal_requirements.txt') }} + - name: Install Minimal Dependencies + run: pip install -r requirements/minimal_requirements.txt + - name: Install Package Without Dependencies + run: pip install --no-deps . + - name: Run Tests + run: | + export LIGHTLY_SERVER_LOCATION="localhost:-1" + python -m pytest -s -v --runslow diff --git a/.github/workflows/test_setup.yml b/.github/workflows/test_setup.yml index d09fd2b7b..561294285 100644 --- a/.github/workflows/test_setup.yml +++ b/.github/workflows/test_setup.yml @@ -2,50 +2,64 @@ name: check setup.py on: push: - paths-ignore: - - 'docs/**' + branches: + - master pull_request: - paths-ignore: - - 'docs/**' workflow_dispatch: jobs: + detect-code-changes: + name: Detect Code Changes + runs-on: ubuntu-latest + outputs: + run-tests: ${{ steps.filter.outputs.run-tests }} + steps: + - uses: actions/checkout@v3 + - uses: dorny/paths-filter@v3 + id: filter + with: + list-files: shell + filters: | + run-tests: + - '!docs/**' + test: name: Test setup.py + needs: detect-code-changes + if: needs.detect-code-changes.outputs.run-tests == 'true' runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - name: Hack to get setup-python to work on nektos/act - run: | - if [ ! -f "/etc/lsb-release" ] ; then - echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release - fi - - name: Set up Python 3.7 - uses: actions/setup-python@v4 - with: - python-version: 3.7 - - uses: actions/cache@v2 - with: - path: ${{ env.pythonLocation }} - key: cache_v2_${{ env.pythonLocation }}-${{ hashFiles('requirements/**') }} - - name: Install Dependencies and lightly - run: pip install . - - name: basic tests of CLI - run: | - LIGHTLY_SERVER_LOCATION="localhost:-1" - lightly-crop --help - lightly-train --help - lightly-embed --help - lightly-magic --help - lightly-download --help - lightly-version - - name: test of CLI on a real dataset - run: | - LIGHTLY_SERVER_LOCATION="localhost:-1" - git clone https://github.com/alexeygrigorev/clothing-dataset-small clothing_dataset_small - INPUT_DIR_1="clothing_dataset_small/test/dress" - lightly-train input_dir=$INPUT_DIR_1 trainer.max_epochs=1 loader.num_workers=6 - lightly-embed input_dir=$INPUT_DIR_1 + - name: Checkout Code + uses: actions/checkout@v3 + - name: Hack to get setup-python to work on nektos/act + run: | + if [ ! -f "/etc/lsb-release" ] ; then + echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release + fi + - name: Set up Python 3.7 + uses: actions/setup-python@v4 + with: + python-version: 3.7 + - uses: actions/cache@v2 + with: + path: ${{ env.pythonLocation }} + key: cache_v2_${{ env.pythonLocation }}-${{ hashFiles('requirements/**') }} + - name: Install Dependencies and lightly + run: pip install . + - name: basic tests of CLI + run: | + LIGHTLY_SERVER_LOCATION="localhost:-1" + lightly-crop --help + lightly-train --help + lightly-embed --help + lightly-magic --help + lightly-download --help + lightly-version + - name: test of CLI on a real dataset + run: | + LIGHTLY_SERVER_LOCATION="localhost:-1" + git clone https://github.com/alexeygrigorev/clothing-dataset-small clothing_dataset_small + INPUT_DIR_1="clothing_dataset_small/test/dress" + lightly-train input_dir=$INPUT_DIR_1 trainer.max_epochs=1 loader.num_workers=6 + lightly-embed input_dir=$INPUT_DIR_1