31 Case Study: pypkgs-cookiecutter
’s ci.yml
workflow
Let’s break down our pypkgs-cookiecutter
’s ci.yml
workflow file to start to better understand a real use case of GitHub Actions.
name: ci
on: [push, pull_request]
jobs:
ci:
# Set up operating system
runs-on: ubuntu-latest
# Define job steps
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "{{ cookiecutter.python_version }}"
- name: Check-out repository
uses: actions/checkout@v3
- name: Install poetry
uses: snok/install-poetry@v1
- name: Install package
run: poetry install
- name: Test with pytest
run: poetry run pytest tests/ --cov={{ cookiecutter.__package_slug }} --cov-report=xml
- name: Use Codecov to track coverage
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml # coverage report
- name: Build documentation
run: poetry run make html --directory docs/
Orientating ourselves with the ci.yml
workflow
Let’s answer the following questions to start better understanding the build.yml
workflow.
How many jobs are there?
How many steps are there?
What which steps are actions and which are commands
What is the type of runner
What events trigger this workflow?
What secrets need to be setup?
Adding the ci.yml
workflow to your pypkgs*
repository
Let’s add the ci.yml
workflow to our pycounts*
repository from week 1!
Setup any needed secrets for the workflow.
Go to the actions tab for your GitHub repository
Click on “set up a workflow yourself”
Delete the template action provided to you, and paste the
ci.yml
file above into the text editor. Rename the fileci.yml
.Click “Start commit”, enter a commit message and then click “Commit”.