-
Notifications
You must be signed in to change notification settings - Fork 1
103 lines (96 loc) · 3.23 KB
/
cicd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Based on the following resources:
# https://github.com/actions/starter-workflows/blob/main/ci/python-package.yml
# https://www.marwandebbiche.com/posts/python-package-tooling/
# https://github.com/marketplace/actions/install-poetry-action
name: Continuous Integration and Deployment # Pipeline name in GitHub Actions
on: # events that trigger this workflow
push:
branches:
- master
pull_request:
branches:
- master
release:
types: [created]
workflow_dispatch: # manual trigger
jobs:
# Testing
test:
# Matrix testng allows us to test multiple Python versions
# We will also fail-fast - fail the job if it fails for any context
strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
defaults:
run:
shell: bash
runs-on: ${{ matrix.os }}
steps:
# Checkout the repo so the workflow can access it
- name: Checkout
uses: actions/checkout@v3
# Install the specified version of poetry
- name: Get poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
# Load cached poetry env if it exists
- name: Load cached venv
id: cached-pip-wheels
uses: actions/cache@v3
with:
path: ~/.cache
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Install poetry env with dev group
- name: Install poetry env with dev group
run: poetry install --with=dev
# Run tests
- name: Run tests
run: |
source $VENV
poetry run pytest
# Code coverage to codecov.io
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: tests/coverage.xml
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
# Publishes to PyPi if tests are passed and release is created
publish:
if: github.event_name == 'release' && github.event.action == 'created'
needs: test
runs-on: ubuntu-latest
steps:
# Checkout the repo so the workflow can access it
- name: Checkout
uses: actions/checkout@v3
# Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
# Install the specified version of poetry
- name: Get poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-create: true
virtualenvs-in-project: true
# Load cached poetry env if it exists
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Build and publish to PyPI
- name: Build and publish to pypi
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}