-
Notifications
You must be signed in to change notification settings - Fork 7
180 lines (154 loc) · 6.27 KB
/
on-pull-request.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
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
176
177
178
179
180
name: On Pull Request
on:
pull_request:
branches: [main]
jobs:
test:
strategy:
matrix:
# TODO: one of the examples dependencies does not support 3.11
os: [ubuntu-24.04]
python-version: ["3.9", "3.10", "3.11"]
new-python-protobuf: ["true"]
include:
# 3.7 and 3.8 are no longer available on ubuntu-24.04
# We run on 20.04 which was the last version where this worked.
# If support for 20.04 becomes an issue, we can install 3.7 and 3.8
# with pyenv or manually.
- python-version: "3.7"
new-python-protobuf: "true"
os: ubuntu-20.04
- python-version: "3.7"
new-python-protobuf: "false"
os: ubuntu-20.04
- python-version: "3.8"
new-python-protobuf: "true"
os: ubuntu-20.04
runs-on: ${{ matrix.os }}
env:
TEST_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
TEST_CACHE_NAME: python-integration-test-${{ matrix.python-version }}-${{ matrix.new-python-protobuf }}-${{ github.sha }}
steps:
- uses: actions/checkout@v3
- name: Commitlint and Other Shared Build Steps
uses: momentohq/standards-and-practices/github-actions/shared-build@gh-actions-v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.3.1
virtualenvs-in-project: true
- name: Install dependencies
run: poetry install
- name: Install Old Protobuf
# Exercises the wire types generated against the old protobuf library
if: matrix.new-python-protobuf == 'false'
run: poetry add "protobuf<3.20"
- name: Run mypy
# mypy has inconsistencies between 3.7 and the rest; default to lowest common denominator
if: matrix.python-version == '3.7'
run: poetry run mypy src tests
- name: Run ruff analyzer
run: poetry run ruff check --no-fix src tests
- name: Run ruff formatter
run: poetry run ruff format --check --diff src tests
- name: Run tests
run: poetry run pytest -p no:sugar -q
test-examples:
runs-on: ubuntu-24.04
strategy:
matrix:
# TODO: one of the examples dependencies does not support 3.11
include:
- python-version: "3.9"
package: prepy310
- python-version: "3.10"
package: py310
- python-version: "3.11"
package: py310
# For simplicity, the examples use a cache called "test-cache"
# Therefore we cannot run them in parallel or else we could prematurely delete
# the cache for one job in another job.
max-parallel: 1
env:
# TODO: remove token stored as secret in favor of using a
# momento-local instance that can be spun up for testing
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.3.1
virtualenvs-in-project: true
- name: Python SDK sample
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: poetry
- name: Verify README generation
uses: momentohq/standards-and-practices/github-actions/oss-readme-template@gh-actions-v2
if: ${{ matrix.python-version }} == '3.10'
with:
project_status: official
project_stability: stable
project_type: sdk
sdk_language: Python
dev_docs_slug: python
template_file: ./README.template.md
output_file: ./README.md
- name: Install dependencies
working-directory: ./examples
run: poetry install
- name: Run mypy
id: mypy
continue-on-error: true
working-directory: ./examples
run: poetry run mypy ${{ matrix.package }}
- name: Run ruff analyzer
id: ruff
continue-on-error: true
working-directory: ./examples
run: poetry run ruff check --no-fix ${{ matrix.package }}
- name: Run ruff formatter
id: format
continue-on-error: true
working-directory: ./examples
run: poetry run ruff format --diff ${{ matrix.package }}
- name: Run samples for python ${{ matrix.python-version }}
id: validation
continue-on-error: true
working-directory: ./examples
run: |
poetry run python -m ${{ matrix.package }}.quickstart
poetry run python -m ${{ matrix.package }}.example
poetry run python -m ${{ matrix.package }}.example_async
- name: Run docs samples for python >= 3.10
id: docs-ex-validation
continue-on-error: true
working-directory: ./examples
if: ${{ matrix.package == 'py310' }}
run: poetry run python ${{ matrix.package }}/doc-examples-python-apis.py
- name: Send CI failure mail
if: ${{ steps.outputs.mypy == 'failure' || steps.outputs.ruff == 'failure' || steps.outputs.format == 'failure' || steps.validation.outcome == 'failure' || steps.docs-ex-validation.outcome == 'failure' }}
uses: momentohq/standards-and-practices/github-actions/error-email-action@gh-actions-v1
with:
username: ${{secrets.MOMENTO_ROBOT_GMAIL_USERNAME}}
password: ${{secrets.MOMENTO_ROBOT_GMAIL_PASSWORD}}
- name: Flag Job Failure
if: ${{ steps.outputs.mypy == 'failure' || steps.outputs.ruff == 'failure' || steps.outputs.format == 'failure' || steps.validation.outcome == 'failure' || steps.docs-ex-validation.outcome == 'failure' }}
run: |
echo "Job statuses"
echo "============"
echo "sample scripts: ${{ steps.validation.outcome }}"
echo "mypy: ${{ steps.outputs.mypy }}"
echo "flake8: ${{ steps.outputs.flake8 }}"
echo "black: ${{ steps.outputs.black }}"
echo "isort: ${{ steps.outputs.isort }}"
echo "doc examples: ${{ steps.outputs.docs-ex-validation }}"
exit 1