-
Notifications
You must be signed in to change notification settings - Fork 40
213 lines (188 loc) · 8.45 KB
/
ci-python.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: CI Python
on:
workflow_call:
inputs:
style-only:
description: Only check the python code style (don't run test)
required: true
default: false
type: boolean
workflow_dispatch:
inputs:
style-only:
description: Only check the python code style (don't run test)
required: true
default: false
type: boolean
# We set `concurrency` to prevent having this workflow being run on code that is not up-to-date on a PR (a user make multiple push in a quick manner).
# But on the main branch, we don't want that behavior.
# Having the workflow run on each merge commit is something we would like, that could help us where a regression was made and missed by previous checks.
#
# For that we use `head_ref` that is only defined on `pull-request` and fallback to `run_id` (this is a counter, so it's value is unique between workflow call).
concurrency:
group: ci-python-${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
poetry-version: 1.5.1
pytest-base-args: >-
--log-level=DEBUG
--durations=10
--side-effects-timeout=10
-vv
-x
# TODO: We stick to PostgreSQL 12 for the moment given later versions are
# much slower (postgresql tests runs in ~9mn on 12 vs ~36mn on 14 !)
postgresql-version: 12
permissions:
contents: read
jobs:
test-python-server:
# Only the server is in Python, and it is only meant to be run on Linux
name: "(🐧 Linux only): 🐍 Python server tests"
# Just a fail-safe timeout, see the fine grain per-task timeout instead
timeout-minutes: 60
# All linux jobs must run the same ubuntu version to avoid Rust caching issues !
# 20.04 is required to install PostgreSQL 12
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # pin v4.0.0
timeout-minutes: 5
- name: Set apt mirror
if: !inputs.style-only
# GitHub Actions apt proxy is super unstable
# see https://github.com/actions/runner-images/issues/7048
run: |
set -e -o pipefail
(
# make sure there is a `\t` between URL and `priority:*` attributes
printf 'http://azure.archive.ubuntu.com/ubuntu priority:1\n';
curl http://mirrors.ubuntu.com/mirrors.txt | grep https
) | sudo tee /etc/apt/mirrors.txt
sudo sed -i 's/http:\/\/azure.archive.ubuntu.com\/ubuntu\//mirror+file:\/etc\/apt\/mirrors.txt/' /etc/apt/sources.list
- name: Configure PostgreSQL APT repository
if: !inputs.style-only
env:
POSTGRES_APT_KEY_SHA_512: df557805862cd279f40819834af14e1723b18044df9dc22bea710b6980c98cc8ed39e75ed5c9adaa1932992710f1180f0491dc9437bfd485b4aa2b75776407d4 /usr/share/keyrings/postgresql-keyring.gpg
run: |
set -x -o pipefail
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc \
| sudo gpg --dearmor --output /usr/share/keyrings/postgresql-keyring.gpg
printenv POSTGRES_APT_KEY_SHA_512 | sha512sum --strict -c -
echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
| sudo tee /etc/apt/sources.list.d/postgresql.list
sudo apt-get update
timeout-minutes: 5
# TODO: Postgresql implementation is currently broken
# - name: Install PostgreSQL-${{ env.postgresql-version }}
# run: |
# # Retry the command until it succeed.
# # We retry because sometime the APT repo configured
# # by the runner seems drop the connection causing the command to fail.
# until sudo apt-get -y install ${{ env.PACKAGE_TO_INSTALL }}; do
# echo "Fail to install APT package retrying ...";
# done
# env:
# PACKAGE_TO_INSTALL: >-
# postgresql-${{ env.postgresql-version }}
# timeout-minutes: 5
- uses: ./.github/actions/setup-python-poetry
id: setup-python
with:
poetry-version: ${{ env.poetry-version }}
project-path: ./server
timeout-minutes: 10
# libparsec is slow to compile, so we save it in cache and skip the
# compilation entirely if the Rust code hasn't changed !
# Key cache contains a hash of all the files that are used to produce _parsec.so
# Hence if we have a cache hit we know that there is no need for a rebuild !
- name: Setup cache-key
id: cache-key
run: echo "key=ubuntu-20.04-${{ hashFiles('server/src/**', 'server/Cargo.toml', 'libparsec/**', 'rust-toolchain.toml', 'Cargo.toml', 'Cargo.lock') }}-libparsec-python-${{ env.python-version }}" >> $GITHUB_OUTPUT
shell: bash
- name: Restore libparsec if Rust hasn't been modified
if: !inputs.style-only
id: cache-libparsec
uses: actions/cache/restore@704facf57e6136b1bc63b828d79edcd491f0ee84 # pin v3.3.2
with:
key: ${{ steps.cache-key.outputs.key }}
path: |
server/parsec/_parsec.*.pyd
server/parsec/_parsec.*.so
timeout-minutes: 2
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@f3c84ee10bf5a86e7a5d607d487bf17d57670965 # pin v1.5.0
if: !inputs.style-only && steps.cache-libparsec.outputs.cache-hit != 'true'
with:
# We setup the cache by hand, see below
cache: false
timeout-minutes: 5
- name: Retrieve Rust cache
uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # pin v2.6.2
if: !inputs.style-only && steps.cache-libparsec.outputs.cache-hit != 'true'
with:
# Cache is limited to 10Go (and cache is ~700mo per platform !). On top of that.
# cache is only shared between master and the PRs (and not across PRs).
# So we only save the cache on master build given it's the ones that are the
# most likely to be reused.
save-if: ${{ github.ref == 'refs/heads/master' }}
timeout-minutes: 5
- name: Install python deps
shell: bash
run: |
set -ex
poetry --directory ./server env info
if ${{ steps.cache-libparsec.outputs.cache-hit == 'true' }}; then export POETRY_LIBPARSEC_BUILD_STRATEGY=no_build; fi
python make.py python-ci-install
timeout-minutes: 20
- name: Install pre-commit
id: pre-commit
uses: ./.github/actions/use-pre-commit
with:
install-only: true
- name: Check python code style
run: |
set -eux
for step in mypy black ruff; do
python \
${{ steps.pre-commit.outputs.install-path }} \
run \
$step \
--show-diff-on-failure \
--verbose \
--color=always \
${{ steps.pre-commit.outputs.suggested-args }}
done
timeout-minutes: 10
# We only save the libparsec lib when:
# - We are not in a github queue branch (they're a one time use so caching won't help)
# - We haven't already cached it.
- name: Save cached libparsec to be reused on later call
if: >-
!inputs.style-only
&& steps.cache-libparsec.outputs.cache-hit != 'true'
&& !contains(github.ref, 'gh-readonly-queue')
uses: actions/cache/save@704facf57e6136b1bc63b828d79edcd491f0ee84 # pin v3.3.2
with:
key: ${{ steps.cache-key.outputs.key }}
path: |
server/parsec/_parsec.*.pyd
server/parsec/_parsec.*.so
timeout-minutes: 2
- name: Basic tests
if: !inputs.style-only
run: poetry run pytest ${{ env.pytest-base-args }} tests -n auto
timeout-minutes: 10
working-directory: server
# TODO: Postgresql implementation is currently broken
# - name: PostgreSQL tests
# if: !inputs.style-only
# env:
# PGINSTALLATION: /usr/lib/postgresql/${{ env.postgresql-version }}/bin
# run: poetry run pytest ${{ env.pytest-base-args }} tests/backend tests/test_cli.py -k 'not test_shuffle_roles' --postgresql --runslow
# timeout-minutes: 20
# working-directory: server
- name: Hypothesis tests
if: !inputs.style-only
run: poetry run pytest ${{ env.pytest-base-args }} tests --runslow -m slow --numprocesses auto
timeout-minutes: 50
working-directory: server