Skip to content

Commit bfdbc1a

Browse files
committed
MNT run tests with github actions
1 parent bae92ec commit bfdbc1a

3 files changed

Lines changed: 95 additions & 1 deletion

File tree

.github/workflows/deploy_pypi.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Deploy to PyPI
2+
# Deploy to PyPI if the __version__ variable in voxelwise_tutorials/__init__.py
3+
# is larger than the latest version on PyPI.
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
paths:
10+
# trigger workflow only on commits that change __init__.py
11+
- 'voxelwise_tutorials/__init__.py'
12+
13+
jobs:
14+
deploy-pypi:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- uses: actions/setup-python@v2
19+
20+
- name: Get versions
21+
# Compare the latest verion on PyPI, and the current version
22+
run: |
23+
python -m pip install --upgrade -q pip
24+
pip index versions voxelwise_tutorials
25+
LATEST=$(pip index versions voxelwise_tutorials | grep 'voxelwise_tutorials' |awk '{print $2}' | tr -d '(' | tr -d ')')
26+
CURRENT=$(cat voxelwise_tutorials/__init__.py | grep "__version__" | awk '{print $3}' | tr -d "'" | tr -d '"')
27+
EQUAL=$([ "$CURRENT" = "$LATEST" ] && echo 1 || echo 0)
28+
echo "LATEST=$LATEST" >> $GITHUB_ENV
29+
echo "CURRENT=$CURRENT" >> $GITHUB_ENV
30+
echo "EQUAL=$EQUAL" >> $GITHUB_ENV
31+
32+
- name: Print versions
33+
run: |
34+
echo ${{ env.LATEST }}
35+
echo ${{ env.CURRENT }}
36+
echo ${{ env.EQUAL }}
37+
38+
- name: Build and publish
39+
if: ${{ env.EQUAL == 0 }}
40+
env:
41+
TWINE_USERNAME: __token__
42+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
43+
run: |
44+
python -m pip install --upgrade pip
45+
python -m pip install setuptools wheel twine
46+
python setup.py sdist bdist_wheel
47+
python -m twine upload dist/*

.github/workflows/run_tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
run-tests:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: [3.7, 3.8, 3.9]
11+
max-parallel: 5
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
20+
- uses: actions/cache@v2
21+
with:
22+
path: ~/.cache/pip
23+
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }}
24+
restore-keys: |
25+
${{ runner.os }}-pip-
26+
27+
- name: Install dependencies
28+
run: |
29+
pip install -e ."[github]"
30+
31+
- name: Lint with flake8
32+
run: |
33+
pip install -q flake8
34+
# stop the build if there are Python syntax errors or undefined names
35+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37+
flake8 . --count --exit-zero --ignore=E402,C901 --max-line-length=127 --statistics
38+
39+
- name: Test with pytest
40+
run: |
41+
pip install -q pytest pytest-cov codecov
42+
pytest --cov=./ --reruns 2
43+
44+
- name: Run codecov
45+
run: |
46+
codecov

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
]
3131

3232
extras_require = {
33-
"docs": ["sphinx", "sphinx_gallery", "numpydoc"]
33+
"docs": ["sphinx", "sphinx_gallery", "numpydoc"],
34+
"github": ["pytest", "pytest-rerunfailures"],
3435
}
3536

3637

0 commit comments

Comments
 (0)