Skip to content

Commit

Permalink
Merge pull request #188 from LabForComputationalVision/github-actions…
Browse files Browse the repository at this point in the history
…-fixes

GitHub actions fixes
  • Loading branch information
billbrod authored Jan 6, 2023
2 parents 5e4f209 + 90cfb8b commit 6c69ee9
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 85 deletions.
184 changes: 100 additions & 84 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: build
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # weekly
- cron: 0 0 * * 0 # weekly
pull_request:
branches:
- main
- main

jobs:
# based on https://slashgear.github.io/how-to-split-test-by-folder-with-github-action/
Expand All @@ -14,19 +14,23 @@ jobs:
outputs:
script: ${{ steps.get-scripts.outputs.script }}
steps:
- uses: actions/checkout@v2
- id: get-scripts
# it's weird to me, but the quotes around \n should *not* be escaped or it breaks
run: echo "::set-output name=script::$(ls tests/test*py | jq -R -s -c 'split("\n")[:-1]')"
- uses: actions/checkout@v3
- id: get-scripts
# we cd into tests so that the output of this is just e.g.,
# "test_tools.py", not "tests/test_tools.py", because we want to run
# pytest from inside the tests/ dir for coverage to work properly (note
# this is different than for the notebooks)
run: "echo \"script=$(cd tests/ && ls test*py | jq -R -s -c 'split(\"\\n\")[:-1]')\"\
\ >> $GITHUB_OUTPUT\n"
get_notebooks:
runs-on: ubuntu-latest
outputs:
notebook: ${{ steps.get-notebooks.outputs.nb }}
steps:
- uses: actions/checkout@v2
- id: get-notebooks
# it's weird to me, but the quotes around \n should *not* be escaped or it breaks
run: echo "::set-output name=nb::$(ls examples/*ipynb | jq -R -s -c 'split("\n")[:-1]')"
- uses: actions/checkout@v3
- id: get-notebooks
run: "echo \"nb=$(ls examples/*ipynb | jq -R -s -c 'split(\"\\n\")[:-1]')\"\
\ >> $GITHUB_OUTPUT\n"
notebooks:
runs-on: ubuntu-latest
needs: [get_notebooks]
Expand All @@ -37,39 +41,39 @@ jobs:
fail-fast: false
name: Execute notebooks
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.py
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v1
- name: Install dependencies
# nbclient 0.5.5 is the first version that includes jupyter execute
run: |
pip install --upgrade --upgrade-strategy eager .
pip install jupyter ipywidgets
pip install "nbclient>=0.5.5"
- name: Download TID2013 dataset
if: ${{ matrix.notebook == 'examples/04_Perceptual_distance.ipynb' }}
run: |
mkdir -p data
wget https://osf.io/7nfkz/download -O ./data/tid2013.rar
7z x ./data/tid2013.rar -o./data/tid2013/
- name: Run notebooks
if: ${{ matrix.notebook != 'examples/Demo_Eigendistortion.ipynb' }}
run: "jupyter execute ${{ matrix.notebook }}.ipynb --kernel_name=python3"
- name: Run notebooks
if: ${{ matrix.notebook == 'examples/Demo_Eigendistortion.ipynb' }}
# this notebook takes much longer than the rest (if run to completion,
# ~1hr on a laptop, more than 5 hours on the Github runners). We use
# papermill's parameters to reduce the max number of steps for
# eigendistortion synthesis here (we want to test that each cell runs,
# but we don't need synthesis to go to completion)
run: |
pip install --upgrade --upgrade-strategy eager papermill
papermill ${{ matrix.notebook }} examples/Demo_Eigendistortion_output.ipynb -p max_steps_frontend 10 -p max_steps_vgg 10 -k python3 --cwd examples/
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.py
- name: Setup FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
- name: Install dependencies
# nbclient 0.5.5 is the first version that includes jupyter execute
run: |
pip install --upgrade --upgrade-strategy eager .
pip install jupyter ipywidgets
pip install "nbclient>=0.5.5"
- name: Download TID2013 dataset
if: ${{ matrix.notebook == 'examples/04_Perceptual_distance.ipynb' }}
run: |
mkdir -p data
wget https://osf.io/7nfkz/download -O ./data/tid2013.rar
7z x ./data/tid2013.rar -o./data/tid2013/
- name: Run notebooks
if: ${{ matrix.notebook != 'examples/Demo_Eigendistortion.ipynb' }}
run: jupyter execute ${{ matrix.notebook }}.ipynb --kernel_name=python3
- name: Run notebooks
if: ${{ matrix.notebook == 'examples/Demo_Eigendistortion.ipynb' }}
# this notebook takes much longer than the rest (if run to completion,
# ~1hr on a laptop, more than 5 hours on the Github runners). We use
# papermill's parameters to reduce the max number of steps for
# eigendistortion synthesis here (we want to test that each cell runs,
# but we don't need synthesis to go to completion)
run: |
pip install --upgrade --upgrade-strategy eager papermill
papermill ${{ matrix.notebook }} examples/Demo_Eigendistortion_output.ipynb -p max_steps_frontend 10 -p max_steps_vgg 10 -k python3 --cwd examples/
tests:
runs-on: ubuntu-latest
needs: [get_test_scripts]
Expand All @@ -80,35 +84,46 @@ jobs:
fail-fast: false
name: Run pytest scripts
steps:
- uses: actions/checkout@v2
- name: Install Python 3
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.py
- name: Install dependencies
run: |
# using the --upgrade and --upgrade-strategy eager flags ensures that
# pip will always install the latest allowed version of all
# dependencies, to make sure the cache doesn't go stale
pip install --upgrade --upgrade-strategy eager .
pip install --upgrade --upgrade-strategy eager pytest-cov
- uses: actions/checkout@v3
- name: Install Python 3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.py
- name: Install dependencies
run: |
# using the --upgrade and --upgrade-strategy eager flags ensures that
# pip will always install the latest allowed version of all
# dependencies, to make sure the cache doesn't go stale
pip install --upgrade --upgrade-strategy eager .
pip install --upgrade --upgrade-strategy eager pytest-cov
- name: Run tests with pytest
if: ${{ matrix.test_script == 'tests/test_display.py' }}
- name: Run tests with pytest
if: ${{ matrix.test_script == 'test_display.py' }}
# we have two cores on the linux github action runners:
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
run: |
pip install --upgrade --upgrade-strategy eager pytest-xdist
pytest -n 2 --cov=plenoptic ${{ matrix.test_script }}
- name: Run tests with pytest
if: ${{ matrix.test_script != 'tests/test_display.py' }}
run: |
pip install --upgrade --upgrade-strategy eager pytest-xdist
# for some reason, need to run this in the tests/ dir in order to get
# coverage to work (I couldn't get an analogous .coveragerc working in
# the root directory)
cd tests/ && pytest -n 2 --cov=plenoptic ${{ matrix.test_script }}
# generate the xml file and move it to root dir for codecov
coverage xml -o ../coverage.xml
- name: Run tests with pytest
if: ${{ matrix.test_script != 'test_display.py' }}
# only test_display should parallelize across the cores, the others get
# slowed down by it
run: 'pytest --cov=plenoptic ${{ matrix.test_script }}'
- name: Upload to codecov
run: 'bash <(curl -s https://codecov.io/bash)'
run: |
# for some reason, need to run this in the tests/ dir in order to get
# coverage to work (I couldn't get an analogous .coveragerc working in
# the root directory)
cd tests/ && pytest --cov=plenoptic ${{ matrix.test_script }}
# generate the xml file and move it to root dir for codecov
coverage xml -o ../coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@858dd794fbb81941b6d60b0dca860878cba60fa9 # v3.1.1
all_tutorials_in_docs:
runs-on: ubuntu-latest
name: Check that all tutorial notebooks are included in docs
Expand All @@ -117,30 +132,31 @@ jobs:
matrix:
notebook: ${{fromJson(needs.get_notebooks.outputs.notebook)}}
steps:
- uses: actions/checkout@v2
- name: Check for file
shell: bash
run: if [[ -z "$(grep ${{ matrix.notebook }} docs/tutorials/*nblink)" ]] ; then exit 1; fi
- uses: actions/checkout@v3
- name: Check for file
shell: bash
run: if [[ -z "$(grep ${{ matrix.notebook }} docs/tutorials/*nblink)" ]] ; then
exit 1; fi
no_extra_nblinks:
runs-on: ubuntu-latest
name: Check that we don't have any extra nblink files
steps:
- uses: actions/checkout@v2
- name: Check same number of nblink and notebooks
shell: bash
run: |
n_nblink=0; for file in docs/tutorials/*nblink; do let "n_nblink+=1"; done;
n_ipynb=0; for file in examples/*ipynb; do let "n_ipynb+=1"; done;
if [[ $n_nblink != $n_ipynb ]]; then exit 1; fi;
- uses: actions/checkout@v3
- name: Check same number of nblink and notebooks
shell: bash
run: |
n_nblink=0; for file in docs/tutorials/*nblink; do let "n_nblink+=1"; done;
n_ipynb=0; for file in examples/*ipynb; do let "n_ipynb+=1"; done;
if [[ $n_nblink != $n_ipynb ]]; then exit 1; fi;
check:
if: always()
needs:
- notebooks
- tests
- notebooks
- tests
runs-on: ubuntu-latest
steps:
- name: Decide whether all tests and notebooks succeeded
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
- name: Decide whether all tests and notebooks succeeded
uses: re-actors/alls-green@afee1c1eac2a506084c274e9c02c8e0687b48d9e # v1.2.2
with:
jobs: ${{ toJSON(needs) }}
2 changes: 1 addition & 1 deletion jenkins/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy>=1.1
torch>=1.8,!=1.12.0
pyrtools>=1.0.0
pyrtools>=1.0.1
scipy>=1.0
matplotlib>=3.1
torchvision>=0.3
Expand Down
5 changes: 5 additions & 0 deletions .coveragerc → tests/.coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[paths]
source =
../plenoptic
*/site-packages/plenoptic

[run]
branch = True
source = plenoptic
Expand Down

0 comments on commit 6c69ee9

Please sign in to comment.