Using GitHub Actions for your Python projects

Harsh Mishra

This talk on Github: HarshCasper/Pyjamas-2021

$whoami

  • Software Developer at Quansight Labs
  • Google Summer of Code '21 Student at MetaCall
  • Google Season of Docs '21 Writer & Outreachy Mentor at moja global
  • Find me on: harshcasper.com

Agenda

  • Understanding CI/CD
  • Introduction to GitHub Actions
  • Writing a simple workflow
  • Running GitHub Actions locally
  • Self hosted runners and marketplace
  • Q&A

What is CI/CD?

CI/CD is an acronym for continuous integration/continuous deployment.

Through CI/CD you automate your:

  • Build process
  • Test process
  • Deployment process

Why is CI/CD important?

  • Mitigates staging and production errors.
  • Improves team productivity, code reviews and feedback loop.
  • Deploy your code continuously and make immediate rollbacks.
  • Plugin various CI toolings for code quality checks and more.

Popular CI/CD tools

  • GitHub Actions
  • Travis CI
  • Circle CI
  • AppVeyor
  • Gitlab CI

In this talk, we will cover GitHub Actions.

Introduction to GitHub Actions

  • Event-driven automation framework to trigger workflows
  • Native CI/CD offered by GitHub for building, testing and deployment.
  • Offers free usage for open-source projects with a generous pricing for private projects.
  • Brings forward a marketplace of custom actions to run on your CI/CD pipeline.

Example workflow

name: Python CI Workflow

on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.9
      - name: Upgrade pip version
      - run: |
          python3 -m pip install --upgrade pip
      - name: Installs all the Dependencies
        run: |
          python3 setup.py install
      - name: Checks the Application Build
        run: |
          pip3 install wheel
          python3 setup.py sdist bdist_wheel
      - name: Tests the Application
        run: |
          pip3 install -r tests/test-requirements.txt
          nosetests --with-coverage --cover-package=webedge tests.unit

Why use GitHub Actions?

  • Capitalize on a wide number of operating systems and architecture.
  • Plugin-based architecture to utilize wide number of third-party actions.
  • Ease of development and customizable development and deployment.
  • Create your own action for specific use-cases, local emulation or host your own runners!

Writing a simple workflow

We will write a simple workflow to install, run and test a Flask application on GitHub Actions. Through GitHub Actions, we will:

  • Setup Python on a GitHub runner.
  • Install the project along with all the dependenices.
  • Run the tests.
  • Lint the code using Flake8.
  • Build the Docs.

Running GitHub Actions locally

You can run GitHub Actions locally using the act, a tool by Nektos to emulate local runs using Docker.

Building SciPy on GitHub Actions using act

Self hosted runners

  • Self hosted runners offer more control of hardware, operating system, and software tools
  • Self hosted runners can be integrated with toolings already offered by your cloud providers.
  • Self hosted runners are free to use with GitHub Actions with only payable cost against the server use.
  • Example of a managed self-hosted runner for GitHub Actions: cirun.io

GitHub Actions Marketplace

Marketplace today hosts over 10,000+ GitHub Actions.

Q&A

Any questions?

Thanks!

Harsh Bardhan Mishra

This talk on Github: HarshCasper/Pyjamas-2021