Skip to content

Commit 5199176

Browse files
committed
Add extra section on CI/CD with github actions
1 parent 1e005ab commit 5199176

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

.github/workflows/tests.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches: [ master, develop ]
6+
pull_request:
7+
branches: [ develop ]
8+
9+
jobs:
10+
testing:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.8', '3.9']
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install Project
24+
run: |
25+
python -m pip install --upgrade pip setuptools wheel pytest hypothesis
26+
python -m pip install pipenv
27+
pipenv install --deploy --system
28+
29+
- name: Run Tests
30+
run: |
31+
pytest -v

docs/source/tutorial/testing.rst

+65
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,68 @@ hard coding them.
460460
assert cumulative_product(array) == [0] * len(array)
461461
462462
|
463+
464+
CI / CD
465+
^^^^^^^
466+
467+
The term CI/CD stands for "continuous integration / continuous deployment". The idea
468+
integrates `development` with software `operations` and can be a non-trivial topic
469+
to cover, let alone implement.
470+
This concept is equally applicable to the previous section on :ref:`packaging <packaging>`
471+
as well as the next section on :ref:`documentation <documentation>`. We'll include it here
472+
because it's a great idea to implement for automated testing.
473+
474+
What would be great is if we could automate running our tests on all changes to the code.
475+
Not just locally, but using our version control system, so that contributions made to
476+
the code are automatically tested without us needing to pull down that branch and running
477+
the tests manually to see if everything is okay. We want a nice "green light" to give us
478+
the `all-clear` -- always.
479+
480+
There are several services out there that will integrate with your version control hosting
481+
platform and automatically run a customizable workflow when events happen
482+
(e.g., on a `pull request` or a new `push` to the repository). If you're hosting your
483+
project on GitHub though, using the freely available
484+
`Github Actions <https://github.com/features/actions>`_ is a super simple way to provide this
485+
functionality for your Python project.
486+
487+
We basically just need to include a configuration file in our project in a special location
488+
and GitHub will automatically understand what to do. Here is a really basic example to get
489+
started that will run ``pytest`` for us everytime we have new commits or PRs to the `develop`
490+
branch of our project using multiple versions of Python.
491+
492+
.. code-block:: yaml
493+
:caption: .github/workflows/tests.yml
494+
495+
name: tests
496+
497+
on:
498+
push:
499+
branches: [ master, develop ]
500+
pull_request:
501+
branches: [ develop ]
502+
503+
jobs:
504+
testing:
505+
runs-on: ubuntu-latest
506+
strategy:
507+
matrix:
508+
python-version: ['3.8', '3.9']
509+
510+
steps:
511+
- uses: actions/checkout@v2
512+
- name: Set up Python ${{ matrix.python-version }}
513+
uses: actions/setup-python@v2
514+
with:
515+
python-version: ${{ matrix.python-version }}
516+
517+
- name: Install Project
518+
run: |
519+
python -m pip install --upgrade pip setuptools wheel pytest hypothesis
520+
python -m pip install pipenv
521+
pipenv install --deploy --system
522+
523+
- name: Run Tests
524+
run: |
525+
pytest -v
526+
527+
|

0 commit comments

Comments
 (0)