-
Notifications
You must be signed in to change notification settings - Fork 28
175 lines (153 loc) · 6.48 KB
/
ci-cd.yaml
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# GitHub Actions docs: https://docs.github.com/en/actions/learn-github-actions
# Reference syntax: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
# Env. variables: https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables
# Add'l variables: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions
# Requires encrypted secret (see https://docs.github.com/en/actions/reference/encrypted-secrets) secrets.pypi_password
# This file is automatically "updated" with PRs by the "pre-commit ci" app in GitHub https://pre-commit.ci; it is
# currently scheduled weekly at approximately 16:00 UTC Monday.
name: Test and deploy release
on: [push, pull_request, workflow_dispatch]
env:
FORCE_COLOR: 1
PYTHONUNBUFFERED: 1
PYTHONUTF8: 1
jobs:
# Set the job key. The key is displayed as the job name
# when a job name is not provided
# PRE-COMMIT IS ALREADY DONE BY GIT
# pre-commit:
# # Name the Job
# name: Quality assurance (pre-commit)
# # Set the type of machine to run on
# runs-on: ubuntu-latest
#
# steps:
# # Checks out a copy of the repository per https://github.com/actions/checkout
# - name: Check out repo
# uses: actions/checkout@main
#
# # Build Python and packages per https://github.com/actions/setup-python
# - name: Set up Python
# uses: actions/setup-python@main
# with:
# python-version: '3.11' # same as https://docs.readthedocs.io/en/stable/config-file/v2.html#build-tools-python
# cache: 'pip'
# cache-dependency-path: |
# requirements.txt
# tests/requirements_pre-commit.txt
#
# # Install dependencies needed by the repo: local in .pre-commit-config.yaml
# - name: Install dependencies
# run: |
# pip install -U pip wheel
# if [ -f tests/requirements_pre-commit.txt ]; then pip install -U -r tests/requirements_pre-commit.txt; fi
# if [ -f requirements.txt ]; then pip install -U -r requirements.txt; fi
#
# # The below has been replaced with the integration in GitHub of the "pre-commit ci" app https://pre-commit.ci
# # # Run pre-commit cache per https://github.com/pre-commit/action
# # - name: Run pre-commit
# # uses: pre-commit/action@v2.0.3
test:
name: "Test (${{ matrix.python-version }}, ${{ matrix.os }})"
# matrix.os is defined in strategy
runs-on: ${{ matrix.os }}
# Identifies any jobs that must complete successfully before this job will run
# needs: [pre-commit]
# A strategy creates a build matrix for your jobs. You can define different variations to run each job in
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.12', '3.11', '3.10', '3.9']
# for valid python-version see https://github.com/actions/python-versions/releases
env:
commitmsg: ${{ github.event.head_commit.message }} # only available at check-out; becomes env.commitmsg
steps:
# Checks out a copy of the repository per https://github.com/actions/checkout
- name: Check out repo
uses: actions/checkout@main
# Build Python and packages per https://github.com/actions/setup-python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@main
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
# pip -e installs a project in editable mode (i.e. setuptools “develop mode”) from a local project path
run: |
pip install -U pip setuptools wheel
pip install -U .
pip install -U coveralls -r tests/requirements_testing.txt
- name: Run tests (Linux/MacOS)
if: runner.os == 'Linux' || runner.os == 'macOS'
run:
python -m pytest tests/ -v --cov=./ --cov-report term --cov-report html --cov-report xml --cov-config=.coveragerc
env:
PYTHONUTF8: 1
- name: Run tests (Windows)
if: runner.os == 'Windows'
run:
# workaround for Windows fatal exception: access violation
python -m pytest tests/ -v --cov=./ --cov-report term --cov-report html --cov-report xml --cov-config=.coveragerc -p no:faulthandler
env:
PYTHONUTF8: 1
# # below not working as pytest-cov does not create the ./coverage/lcov.info file!
# - name: Upload LCOV coverage data to Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.github_token }}
# flag-name: tests-${{ matrix.python-version }}-${{ matrix.os }}
# parallel: true
- name: Upload coverage to Coveralls (parallel)
run: coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
COVERALLS_FLAG_NAME: tests-${{ matrix.python-version }}-${{ matrix.os }}
COVERALLS_PARALLEL: true
coveralls:
name: Indicate completion to coveralls.io
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Coveralls parallel finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
deploy:
name: Deploy release
runs-on: ubuntu-latest
# ref https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [test]
steps:
- name: Check out repo
uses: actions/checkout@main
- name: Set up Python
uses: actions/setup-python@main
with:
python-version: '3.12'
cache: 'pip'
# Install pip dependencies
- name: Install dependencies
run: |
pip install -U pip build
- name: Build dist
run: |
python -m build
# PyPI publish GitHub Action from https://github.com/pypa/gh-action-pypi-publish
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
- name: Create GitHub release
id: create_release
uses: actions/create-release@main
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body_path: RELEASE.rst
draft: false
prerelease: false