From c5556bb20e3f4c1cb984acab17bb342aad5ce303 Mon Sep 17 00:00:00 2001 From: Colm Talbot Date: Fri, 23 Feb 2024 09:29:04 -0600 Subject: [PATCH] TST: Add GitHub action testing (#24) * TST: Create unit-tests.yml * TST: try explicit version * TST: Remove unnecessary setup python * TST: disable precommit tests * TST: typo * TST: add pre-commit tests * TST: try installing jupyter for pre-commit * TST: add install/import tests * TST: just install basic version * TST: typo fixes * TST: done run executable tests on windows * TST: another attempt to disable executable tests for windows * TST: remove executable tests * DOC: add documentation job * DOC: make sure to pull tags for docs job * BLD: upload docs as an artifact --- .github/workflows/basic-install.yml | 47 +++++++++++++++++++++++++++++ .github/workflows/pages.yml | 46 ++++++++++++++++++++++++++++ .github/workflows/pre-commit.yml | 20 ++++++++++++ .github/workflows/unit-tests.yml | 34 +++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 .github/workflows/basic-install.yml create mode 100644 .github/workflows/pages.yml create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/basic-install.yml b/.github/workflows/basic-install.yml new file mode 100644 index 00000000..920a5789 --- /dev/null +++ b/.github/workflows/basic-install.yml @@ -0,0 +1,47 @@ +name: Clean install + +on: + push: + branches: [ "github-main" ] + pull_request: + branches: [ "github-main" ] + +jobs: + build: + + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: ["3.9", "3.10", "3.11"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install + run: python -m pip install . + - name: List environment + run: python -m pip list installed + - name: Test imports + run: | + python -c "import bilby" + python -c "import bilby.bilby_mcmc" + python -c "import bilby.core" + python -c "import bilby.core.prior" + python -c "import bilby.core.sampler" + python -c "import bilby.core.utils" + python -c "import bilby.gw" + python -c "import bilby.gw.detector" + python -c "import bilby.gw.eos" + python -c "import bilby.gw.likelihood" + python -c "import bilby.gw.sampler" + python -c "import bilby.hyper" + python -c "import cli_bilby" + python test/import_test.py + # - if: ${{ matrix.os != "windows-latest" }} + # run: | + # for script in $(pip show -f bilby | grep "bin\/" | xargs -I {} basename {}); do + # ${script} --help; + # done diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 00000000..9e1d2fa3 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,46 @@ +name: GitHub Pages + +on: + push: + branches: + - github-main + pull_request: + branches: + - github-main + +jobs: + deploy: + runs-on: ubuntu-latest + container: containers.ligo.org/lscsoft/bilby/v2-bilby-python310 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + - name: install + run: python -m pip install . + - name: Run jupyter notebooks + run: | + python -m ipykernel install + cd examples/tutorials + jupyter nbconvert --to notebook --execute *.ipynb --output-dir ../../docs + cd - + - name: Build docs + run: | + cd docs + make clean + make html + cd - + # Upload the build docs as an artifact until we expose the pages + - uses: actions/upload-artifact@v4 + with: + name: docs-html + path: docs/_build/html/ + # Disable docs deployment until we move primarily to GitHub + # - name: Deploy + # uses: peaceiris/actions-gh-pages@v3 + # if: ${{ github.ref == 'refs/heads/master' }} + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # publish_dir: . diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..c8d912d5 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,20 @@ +name: pre-commit + +on: + push: + branches: [ "github-main" ] + pull_request: + branches: [ "github-main" ] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + - name: Install jupyter + run: | + python -m pip install jupyterlab + - uses: pre-commit/action@v3.0.1 + - uses: pre-commit-ci/lite-action@v1.0.2 + if: always() diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 00000000..b14f5e83 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,34 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "github-main" ] + pull_request: + branches: [ "github-main" ] + +jobs: + build: + + runs-on: ubuntu-latest + container: containers.ligo.org/lscsoft/bilby/v2-bilby-python310 + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v3 + - name: Install package + run: | + python -m pip install . + conda list --show-channel-urls + # - name: Run precommits + # run: | + # pre-commit run --all-files --verbose --show-diff-on-failure + - name: Run unit tests + run: | + pytest --cov=bilby --durations 10 + - name: Run sampler tests + run: | + pytest test/integration/sampler_run_test.py --durations 10 -v