CI for Template #405
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI for Template | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
schedule: | |
- cron: 45 6 * * * | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
tests: | |
name: ${{ matrix.copier_config.name }} - Python ${{ matrix.python-version }} | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
matrix: | |
python-version: ['3.8', '3.9', '3.10'] | |
copier_config: | |
- name: Base example | |
package_name: example_package # The default package_name | |
extra_flags: '' | |
foldername: base_example | |
- name: Black w/o example module | |
package_name: 'drewtonian' # Same module name provided in `extra_flags` on the next line. | |
extra_flags: >- | |
--data project_name=new_science | |
--data package_name=drewtonian | |
--data author_name=Drew | |
--data [email protected] | |
--data project_license=BSD | |
--data preferred_linter=black | |
--data use_isort=false | |
--data mypy_type_checking=basic | |
--data create_example_module=no | |
--data include_notebooks=no | |
--data use_gitlfs=disabled | |
foldername: 'black_w_o_example_module' | |
- name: Black w/ example | |
package_name: 'drewtonian' # Same module name provided in `extra_flags` on the next line. | |
extra_flags: >- | |
--data project_name=new_science | |
--data package_name=drewtonian | |
--data author_name=Drew | |
--data [email protected] | |
--data project_license=BSD | |
--data preferred_linter=black | |
--data use_isort=false | |
--data mypy_type_checking=basic | |
--data create_example_module=yes | |
--data include_notebooks=no | |
--data use_gitlfs=disabled | |
foldername: 'black_w_example_module' | |
- name: Pylint w/o example | |
package_name: 'drewtonian' # Same module name provided in `extra_flags` on the next line. | |
extra_flags: >- | |
--data project_name=new_science | |
--data package_name=drewtonian | |
--data author_name=Drew | |
--data [email protected] | |
--data project_license=BSD | |
--data preferred_linter=pylint | |
--data use_isort=false | |
--data mypy_type_checking=basic | |
--data create_example_module=no | |
--data include_notebooks=no | |
--data use_gitlfs=disabled | |
foldername: 'pylint_w_o_example_module' | |
- name: No sphinx docs | |
package_name: 'drewtonian' | |
extra_flags: >- | |
--data project_name=new_science | |
--data package_name=drewtonian | |
--data include_docs=no | |
--data include_notebooks=no | |
foldername: 'no_sphinx_docs' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Python dependencies | |
run: | | |
sudo apt-get update | |
python -m pip install --upgrade pip | |
python -m pip install copier mypy | |
- name: Generate package | |
run: | | |
copier copy --vcs-ref HEAD --defaults ${{ matrix.copier_config.extra_flags }} ./ ../test/${{ matrix.copier_config.foldername }} | |
cd ../test/${{ matrix.copier_config.foldername }} | |
cat .copier-answers.yml | |
- name: Build package | |
run: | | |
cd ../test/${{ matrix.copier_config.foldername }} | |
git config --global user.email "[email protected]" | |
git config --global user.name "Test Name" | |
git init --initial-branch=main | |
git add src | |
git commit -m initial | |
pip install . | |
pip install .[dev] | |
- name: pylint checks | |
if: ${{ contains (matrix.copier_config.name, 'Base') }} | |
run: | | |
cd ../test/${{ matrix.copier_config.foldername }} | |
python -m pylint --recursive=y ./src/ --rcfile=./src/.pylintrc | |
- name: black checks | |
if: ${{ contains(matrix.copier_config.extra_flags, 'preferred_linter=black') }} | |
uses: psf/black@stable | |
with: | |
src: "../test/${{ matrix.copier_config.foldername }}/src" | |
- name: mypy checks basic | |
if: ${{ contains(matrix.copier_config.extra_flags, 'mypy_type_checking=basic') && !contains(matrix.copier_config.extra_flags, 'create_example_module=no') }} | |
run: | | |
cd "../test/${{ matrix.copier_config.foldername }}" | |
mypy src tests | |
- name: mypy checks strict | |
if: ${{ contains(matrix.copier_config.extra_flags, 'mypy_type_checking=strict') && !contains(matrix.copier_config.extra_flags, 'create_example_module=no') }} | |
run: | | |
cd "../test/${{ matrix.copier_config.foldername }}" | |
mypy --strict src tests | |
- name: Install notebook requirements | |
if: ${{ !contains(matrix.copier_config.extra_flags, 'include_notebooks=no') }} | |
run: | | |
sudo apt-get install pandoc | |
pip install -r ../test/${{ matrix.copier_config.foldername }}/docs/requirements.txt | |
cat ../test/${{ matrix.copier_config.foldername }}/docs/requirements.txt | |
- name: Build docs | |
if: ${{ !contains(matrix.copier_config.extra_flags, 'include_docs=no') }} | |
run: | | |
cd ../test/${{ matrix.copier_config.foldername }} | |
sphinx-build -T -E -b html -d docs/build/doctrees ./docs docs/build/html | |
- name: Tests | |
if: ${{ !contains(matrix.copier_config.extra_flags, 'create_example_module=no') }} | |
run: | | |
cd ../test/${{ matrix.copier_config.foldername }} | |
python -m pytest tests --cov=${{ matrix.copier_config.package_name }} --cov-report=xml |