Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Github Actions support #44

Merged
merged 7 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Before you submit a pull request, check that it meets these guidelines:
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.

3. The pull request should work for Python 2.7, 3.4, 3.5 and 3.6, and for PyPy. Check
3. The pull request should work for Python 2.7, 3.5, 3.6 and 3.7, and for PyPy. Check
https://travis-ci.org/audreyr/cookiecutter-pypackage/pull_requests
and make sure that the tests pass for all supported Python versions.

Expand Down
18 changes: 10 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Features
--------

* Testing setup with ``unittest`` and ``pytest``
* Github-Actions_: Ready for Github Actions Continuous Integration testing
* Travis-CI_: Ready for Travis Continuous Integration testing
* Tox_ testing: Setup to easily test for Python 2.7, 3.4, 3.5, 3.6
* Tox_ testing: Setup to easily test for Python 2.7, 3.5, 3.6, 3.7, 3.8
* Sphinx_ docs: Documentation ready for generation, automatic building and deploying to gh-pages (strongly recommended)
* Bumpversion_: Pre-configured version bumping with a single command
* Auto-release to PyPI_ when you push a new tag to master (strongly recommended)
Expand Down Expand Up @@ -56,23 +57,23 @@ Then:
* Install tox (``pip install tox``)
* Run tox (``tox``)

4. Configure Travis to run tests and build documentation
4. Configure Travis to run tests and build documentation. If you're using Github Actions, you can skip this step.


* Create the repo on GitHub if it is not already there
* Add the repo to your Travis-CI_ account (https://travis-ci.org/ORG_NAME/PROJECT_NAME)
* Push a commit and monitor the build

5. Configure Travis to automatically deploy documentation to GitHub pages
5. Configure Travis to automatically deploy documentation to GitHub pages. If you're using Github Actions, you can skip this step.

* Configure a GitHub deployment token and add it to Travis. See the ``.travis.yml`` file of your project for details.
* Push a commit and watch your documentation being built.
* View the documentation at https://hdi-project.github.io/PROJECT_NAME

6. Configure Travis to automatically deploy to PyPI on new tags
6. Automatically deploy to PyPI on new tags.

* Register_ your project with PyPI, or use the DAI Lab account (`dai_lab_mit`, ask someone for the info)
* Use Travis to encrypt your PyPI password in Travis config and activate automated deployment on PyPI when you push a new tag to master branch. See the ``.travis.yml`` file of your project for details.
* Use Travis to encrypt your PyPI password in Travis config and activate automated deployment on PyPI when you push a new tag to master branch - see the ``.travis.yml`` file of your project for details. Alternatively, if using Github Actions, you can generate an API token on PyPI and add it to your Github Secrets with the name ``pypi_password`` - see the ``.github/workflows/deploy.yml`` file of your project for details.
* Test the release process

* Ensure you can create the dist using ``make dist``
Expand All @@ -82,7 +83,7 @@ Then:

* Tag a new release using ``bumpversion`` (TODO)
* Push the latest *commit* to master and ensure that tests pass (``git push origin master``)
* Push the latest *tag* to master and watch as Travis will automatically deploy your release to PyPI (``git push --tags origin master``)
* Push the latest *tag* to master and watch as Travis / Github Actions will automatically deploy your release to PyPI (``git push --tags origin master``)

7. Start developing!

Expand Down Expand Up @@ -198,8 +199,8 @@ things are files and folders and I'll give you a quick overview of what they
are/do.

* Tox_ (tox.ini): A system that can run all kinds of tests for you. For
instance, you can test your code on various versions (Python 2.7, 3.4, 3.5,
3.6) and test your code on linters as well.
instance, you can test your code on various versions (Python 2.7, 3.5,
3.6, 3.7, 3.8) and test your code on linters as well.

* Travis-CI_ (travis.yml): A continuous integration system. That means every
time you push a commit it will simulate downloading your project, installing
Expand Down Expand Up @@ -254,6 +255,7 @@ are/do.
.. _`cookiecutter-pypackage tutorial`: https://cookiecutter-pypackage.readthedocs.io/en/latest/tutorial.html
.. _Cookiecutter: https://github.com/DAI-Lab/cookiecutter
.. _Travis-CI: http://travis-ci.org/
.. _Github-Actions: https://github.com/features/actions
.. _Tox: http://testrun.org/tox/
.. _Sphinx: http://sphinx-doc.org/
.. _Bumpversion: https://github.com/peritus/bumpversion
Expand Down
11 changes: 6 additions & 5 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"full_name": "Your Name",
"email": "email@mit.edu",
"github_username": "username",
"github_owner": ["DAI-Lab", "HDI-Project", "D3-AI", "{{ cookiecutter.github_username }}"],
"github_owner": ["DAI-Lab", "HDI-Project", "D3-AI", "data-dev", "sdv-dev", "{{ cookiecutter.github_username }}"],
"project_name": "Python Boilerplate",
"package_name": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}",
"project_slug": "{{ cookiecutter.package_name.replace('-', '_') }}",
Expand All @@ -13,10 +13,11 @@
"pypi_username": "{{ 'mit_dai_lab' if cookiecutter.github_username != cookiecutter.github_owner else cookiecutter.github_username }}",
"version": "0.1.0.dev0",
"support_py2": "n",
"use_pypi_deployment_with_travis": "y",
"use_ghpages_deployment_with_travis": "y",
"use_codecov": "y",
"command_line_interface": ["Click", "No command-line interface"],
"ci_provider": ["Github Actions", "Travis CI", "No continuous integration"],
"use_pypi_with_ci": "n",
"use_ghpages_with_ci": "y",
"use_codecov_with_ci": "y",
"command_line_interface": ["No command-line interface", "Click"],
"create_author_file": "y",
"open_source_license": ["MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"]
}
4 changes: 2 additions & 2 deletions docs/prompts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Options

The following package configuration options set up different features for your project.

use_pypi_deployment_with_travis
Whether to use PyPI deployment with Travis.
use_pypi_with_ci
Whether to automatically deploy to PyPI on git tags

command_line_interface
Whether to create a console script using Click. Console script entry point will match the project_slug. Options: ['Click', "No command-line interface"]
9 changes: 9 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def main():
cli_file = os.path.join('{{ cookiecutter.project_slug }}', 'cli.py')
remove_file(cli_file)

if '{{ cookiecutter.use_pypi_with_ci }}' != 'y':
remove_file('.github/workflows/deploy.yml')

if '{{ cookiecutter.ci_provider }}' != 'Travis CI':
remove_file('.travis.yml')
if '{{ cookiecutter.ci_provider }}' != 'Github Actions':
remove_file('.github/workflows/docs.yml')
remove_file('.github/workflows/tests.yml')

if 'Not open source' == '{{ cookiecutter.open_source_license }}':
remove_file('LICENSE')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_bake_with_apostrophe_and_run_tests(cookies):


def test_bake_without_travis_pypi_setup(cookies):
with bake_in_temp_dir(cookies, extra_context={'use_pypi_deployment_with_travis': 'n'}) as result:
with bake_in_temp_dir(cookies, extra_context={'use_pypi_with_ci': 'n'}) as result:
result_travis_config = yaml.load(result.project.join(".travis.yml").open())
assert "deploy" not in result_travis_config
assert "python" == result_travis_config["language"]
Expand Down
37 changes: 37 additions & 0 deletions {{cookiecutter.repository_name}}/.github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: PyPI Deploy

on:
push:
tags:
- '*'

jobs:

# Automatically deploy releases to PyPI for each tagged commit. This
# uses the API Token feature (https://pypi.org/help/#apitoken). After
# obtaining an API token from PyPI, add it to your github secrets with
# the name `pypi_password`.
deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]

- name: Build distribution
run: make dist

- name: Publish package
if: startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: {{ '${{ secrets.pypi_password }}' }}
28 changes: 28 additions & 0 deletions {{cookiecutter.repository_name}}/.github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Generate Docs

on:
push:
branches: [ master ]

jobs:

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Python
uses: actions/setup-python@v1
with:
python-version: '3.7'

- name: Build
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
make docs
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: {{ '${{secrets.GITHUB_TOKEN}}' }}
publish_dir: docs/_build/html
38 changes: 38 additions & 0 deletions {{cookiecutter.repository_name}}/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Run Tests

on:
push:
branches: [ '*' ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: {{ '${{ matrix.os }}' }}
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8]
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v1
- name: Set up Python {{ '${{ matrix.python-version }}' }}
uses: actions/setup-python@v1
with:
python-version: {{ '${{ matrix.python-version }}' }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions

- name: Test with tox
run: tox

k15z marked this conversation as resolved.
Show resolved Hide resolved
{%- if cookiecutter.use_codecov_with_ci == 'y' %}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
{%- endif %}
15 changes: 8 additions & 7 deletions {{cookiecutter.repository_name}}/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
dist: trusty
language: python
python:
- 3.8
- 3.7
- 3.6
- 3.5
- 3.4
{%- if cookiecutter.support_py2 == 'y' %}
- 2.7
{%- endif %}
Expand All @@ -16,7 +17,7 @@ matrix:
sudo: required

# Command to install dependencies
{%- if cookiecutter.use_codecov == 'y' %}
{%- if cookiecutter.use_codecov_with_ci == 'y' %}
install: pip install -U tox-travis codecov

after_success: codecov
Expand All @@ -27,10 +28,10 @@ install: pip install -U tox-travis
# Command to run tests
script: tox

{% if cookiecutter.use_pypi_deployment_with_travis == 'y' or cookiecutter.use_ghpages_deployment_with_travis == 'y' -%}
{% if cookiecutter.use_pypi_with_ci == 'y' or cookiecutter.use_ghpages_with_ci == 'y' -%}
deploy:
{%- endif %}
{% if cookiecutter.use_pypi_deployment_with_travis == 'y' %}
{% if cookiecutter.use_pypi_with_ci == 'y' %}
# Automatically deploy releases to PyPI for each tagged commit
# Assuming you have installed the travis-ci CLI tool, after you
# create the Github repo and add it to Travis, run the
Expand All @@ -45,9 +46,9 @@ deploy:
on:
tags: true
repo: {{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}
python: 3.6
python: 3.7
{%- endif %}
{% if cookiecutter.use_ghpages_deployment_with_travis == 'y' %}
{% if cookiecutter.use_ghpages_with_ci == 'y' %}
# Automatically build and deploy documentation to GitHub Pages after every
# commit
# Follow the instructions at https://docs.travis-ci.com/user/deployment/pages/
Expand All @@ -61,5 +62,5 @@ deploy:
target-branch: gh-pages
on:
branch: master
python: 3.6
python: 3.7
{%- endif %}
9 changes: 7 additions & 2 deletions {{cookiecutter.repository_name}}/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Before you submit a pull request, check that it meets these guidelines:
4. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the documentation in an appropriate place.
5. The pull request should work for all the supported Python versions. Check the `Travis Build
5. The pull request should work for all the supported Python versions. Check the `Build
Status page`_ and make sure that all the checks pass.

Unit Testing Guidelines
Expand Down Expand Up @@ -233,5 +233,10 @@ or in command line::


.. _GitHub issues page: https://github.com/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}/issues
.. _Travis Build Status page: https://travis-ci.org/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}/pull_requests
{%- if cookiecutter.ci_provider == 'Github Actions' %}
.. _Build Status page: https://github.com/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}/actions
{%- endif %}
{%- if cookiecutter.ci_provider == 'Travis CI' %}
.. _Build Status page: https://travis-ci.org/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}/pull_requests
{%- endif %}
.. _Google docstrings style: https://google.github.io/styleguide/pyguide.html?showone=Comments#Comments
4 changes: 2 additions & 2 deletions {{cookiecutter.repository_name}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ install-test: clean-build clean-pyc ## install the package and test dependencies

.PHONY: test
test: ## run tests quickly with the default Python
python -m pytest --basetemp=${ENVTMPDIR} --cov={{ cookiecutter.project_slug }}
python -m pytest --basetemp=${ENVTMPDIR} --cov={{ cookiecutter.project_slug }} --cov-report xml

.PHONY: lint
lint: ## check style with flake8 and isort
Expand All @@ -52,7 +52,7 @@ install-develop: clean-build clean-pyc ## install the package in editable mode a

.PHONY: test-all
test-all: ## run tests on every Python version with tox
tox -r
tox -r -p auto
k15z marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: fix-lint
fix-lint: ## fix lint issues using autoflake, autopep8, and isort
Expand Down
11 changes: 9 additions & 2 deletions {{cookiecutter.repository_name}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
<!-- Uncomment these lines after releasing the package to PyPI for version and downloads badges -->
<!--[![PyPI Shield](https://img.shields.io/pypi/v/{{ cookiecutter.package_name }}.svg)](https://pypi.python.org/pypi/{{ cookiecutter.package_name }})-->
<!--[![Downloads](https://pepy.tech/badge/{{ cookiecutter.package_name }})](https://pepy.tech/project/{{ cookiecutter.package_name }})-->
{%- if cookiecutter.ci_provider == 'Travis CI' %}
[![Travis CI Shield](https://travis-ci.org/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}.svg?branch=master)](https://travis-ci.org/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }})
{%- if cookiecutter.use_codecov == 'y' %}
{%- endif %}
{%- if cookiecutter.ci_provider == 'Github Actions' %}
[![Github Actions Shield](https://img.shields.io/github/workflow/status/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}/Run%20Tests)](https://github.com/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}/actions)
{%- endif %}
{%- if cookiecutter.use_codecov_with_ci == 'y' %}
[![Coverage Status](https://codecov.io/gh/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }}/branch/master/graph/badge.svg)](https://codecov.io/gh/{{ cookiecutter.github_owner }}/{{ cookiecutter.repository_name }})
{%- endif %}



# {{ cookiecutter.project_name }}

{{ cookiecutter.project_short_description }}
Expand All @@ -29,7 +36,7 @@ TODO: Provide a short overview of the project here.

## Requirements

**{{ cookiecutter.project_name }}** has been developed and tested on [Python {%- if cookiecutter.support_py2 == 'y' %}2.7, {%- endif %}3.4, 3.5, 3.6 and 3.7](https://www.python.org/downloads/)
**{{ cookiecutter.project_name }}** has been developed and tested on [Python {% if cookiecutter.support_py2 == 'y' %}2.7, {% endif %}3.5, 3.6, 3.7 and 3.8](https://www.python.org/downloads/)

Also, although it is not strictly required, the usage of a [virtualenv](https://virtualenv.pypa.io/en/latest/)
is highly recommended in order to avoid interfering with other software installed in the system
Expand Down
Loading