From 6f48bdbb23043bc39f90dd853f601c069f5b735b Mon Sep 17 00:00:00 2001 From: Ryan Dale Date: Sun, 14 Mar 2021 16:13:45 -0400 Subject: [PATCH] GitHub actions (#339) * set up github actions testing * rm 2.7 from travis-ci --- .github/workflows/main.yml | 113 ++++++++++++++++++++++++++++++++++++- .travis.yml | 1 - condatest.sh | 1 + 3 files changed, 111 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83a63669..42e992ad 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,11 +2,15 @@ name: main on: [push] jobs: - conda-env: + build-and-test: + strategy: + matrix: + python-version: [3.6, 3.7, 3.8] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - name: git setup # Set up git and export env vars to be used in later steps. # Note the unconventional mechanism for exporting envs by appending to @@ -18,7 +22,110 @@ jobs: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV echo "WORKDIR=$(pwd)" >> $GITHUB_ENV - - name: build + + + - name: cythonize and pip + # Convert .pyx files to .cpp and package into sdist tarball. + # + # This only requires Cython, no other dependencies. + run: | + eval "$(conda shell.bash hook)" + conda create -p ./cython-env -y cython + conda activate ./cython-env + python setup.py clean cythonize sdist + (cd dist && pip install pybedtools-*.tar.gz && cd $TMPDIR && python -c 'import pybedtools; print(pybedtools.__file__)') + conda deactivate + + + - name: conda env and install locally + # Set up conda and install pybedtools into that env + # + # NOTE: Tests require *.so files that are created by installing the + # package, otherwise we get: + # + # ModuleNotFoundError: No module named 'pybedtools.cbedtools' + # + # We could install from the source repo dir. However this may inadvertently + # rely on files that are in the source repo but not in the actual sdist + # package. So we extract the sdist tarball to another location and install + # from there. + # + # Tests below will operate in this newly-installed directory. run: | eval "$(conda shell.bash hook)" - ./condatest.sh 3.8 + conda create -y -p ./test-env \ + --channel conda-forge \ + --channel bioconda python=${{ matrix.python-version }} \ + --file requirements.txt \ + --file test-requirements.txt \ + --file optional-requirements.txt + conda activate ./test-env + + mkdir -p /tmp/pybedtools-uncompressed + cd /tmp/pybedtools-uncompressed + tar -xf $WORKDIR/dist/pybedtools-*.tar.gz + cd pybedtools-* + pip install -e . + python -c 'import pybedtools; print(pybedtools.__file__)' + ls * + + + - name: tests + # Run pytest and sphinx doctests + run: | + eval "$(conda shell.bash hook)" + cd $WORKDIR + conda activate ./test-env + + # Move to extracted tarball dir, see above notes + cd /tmp/pybedtools-uncompressed/pybedtools-* + pytest -v --doctest-modules + pytest -v pybedtools/test/genomepy_integration.py + cp -r $WORKDIR/docs . + (cd docs && make clean doctest) + + + - name: build-docs + # Build docs and commit to gh-pages branch. Note that no push happens + # unless we're on the master branch + run: | + eval "$(conda shell.bash hook)" + conda activate ./test-env + + # Move to extracted tarball dir, see above notes + cd /tmp/pybedtools-uncompressed/pybedtools-* + (cd docs && make html) + + git clone \ + --single-branch \ + --branch gh-pages "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" \ + /tmp/docs + + rm -rf /tmp/docs/* + cp -r docs/build/html/* /tmp/docs + touch /tmp/docs/.nojekyll + cd /tmp/docs + git add . + if git diff --cached --quiet; then + echo "no changes, nothing to commit" + else + git commit -m 'update docs' + fi + cd $WORKDIR + + + - name: docs artifact + # Upload built docs as an artifact for inspection, even on PRs + uses: actions/upload-artifact@v2 + with: + name: docs + path: /tmp/docs + + + - name: push docs to gh-pages branch + # Push docs to gh-pages if this test is running on master branch + if: ${{ github.ref == 'refs/heads/master' }} + run: | + cd /tmp/docs + git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" gh-pages + cd $WORKDIR diff --git a/.travis.yml b/.travis.yml index 5f740386..5247e863 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ language: python # see https://github.com/travis-ci/travis-ci/issues/9815 for py3.7 support matrix: include: - - python: 2.7 - python: 3.6 - python: 3.7 - python: 3.8 diff --git a/condatest.sh b/condatest.sh index 3080ea7d..18b8ba80 100755 --- a/condatest.sh +++ b/condatest.sh @@ -15,6 +15,7 @@ log () { } +eval "$(conda shell.bash hook)" # ---------------------------------------------------------------------------- # sdist and pip install tests