{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Continuous Integration\n", "\n", "\n", "Continuous Integration is everything you need to do as a serious software developer.\n", "Namely,\n", "\n", "- have your code on GitHub (or other code hosting services), shared with your collaborators and managed through pull requests and branches\n", "- tests suite that you run automatically on your code changes\n", "- documentation on ReadTheDocs automatically generated from your code, and automatically updated\n", "- pypi package automatically updated with your new code, including version number, and pre-compiled binaries (wheels)\n", "- Slack or Discord servers for communication with your collaborators and community\n", "\n", "\n", "These practices are sometimes referred to as being parts of **DevOps** or **Continuous Delivery** practices. We do not make the distinction here.\n", "\n", "\n", "## Webhooks\n", "\n", "Webhooks allow you to trigger actions on remote services when certain events happen on your repository.\n", "\n", "This allows you to automate updates:\n", "- on Slack or Discord servers\n", "- automatically update your ReadTheDocs pages\n", "\n", "\n", "## GitHub Actions\n", "\n", "GitHub Actions allow you (amongst many other things) to automate your test suite and PyPI package updates.\n", "GitHub actions are defined via yaml files in your repository.\n", "\n", "See an example [here](https://github.com/CLASS-SZ/classy_szfast/blob/main/.github/workflows/python-publish.yml) for the PyPI part. You can follow the actions\n", "on the GitHub website (see, [here](https://github.com/CLASS-SZ/classy_szfast/actions) for an example).\n", "\n", "\n", "Here’s a workflow file for running `pytest` tests on a package after it’s installed from PyPI, triggered manually:\n", "\n", "```yaml\n", "name: Test PyPi Package\n", "\n", "on:\n", " workflow_dispatch:\n", "\n", "jobs:\n", " test_package:\n", " runs-on: ubuntu-latest\n", "\n", " steps:\n", " - name: Set up Python\n", " uses: actions/setup-python@v5\n", " with:\n", " python-version: \"3.x\"\n", "\n", " - name: Install package from PyPI\n", " run: |\n", " pip install --upgrade pip\n", " pip install your-package-name # Replace with your actual package name\n", "\n", " - name: Run pytest\n", " run: |\n", " pytest tests/*\n", "```\n", "\n", "In this workflow:\n", "- The job is triggered manually with `workflow_dispatch`.\n", "- The package is installed directly from PyPI.\n", "- `pytest` is run on the tests located in the `tests` directory.\n", "\n", "\n", "For more CI/CD examples, on the test suite, you are encouraged to familiarise yourself with code coverage, for instance with [codecov](https://about.codecov.io/).\n", "\n" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 2 }