-
Notifications
You must be signed in to change notification settings - Fork 7
176 lines (167 loc) · 5.27 KB
/
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
# Workflows which need Python cache
name: Python CI
on:
push:
paths:
- '**/*.py'
- '**/*.rs'
- 'pytest.ini'
merge_group:
pull_request:
types: [opened, synchronize, reopened]
schedule:
- cron: 0 5 * * 1 # Every Monday at 5:00 UTC
permissions:
contents: read
jobs:
# Build cache for pip package dependencies (low frequency)
dependencies:
name: Pip dependencies cache
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
# Build a virtualenv cache
- name: Get venv cache
uses: actions/cache/restore@v4
id: sedpack_venv_dependencies
with:
# The cache key depends on requirements.txt
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('**/requirements*.txt') }}
path: .venv
# Build a virtualenv, but only if it doesn't already exist
- name: Populate pip cache
run: |
python -m venv .venv
source .venv/bin/activate
python -m pip install --require-hashes --no-deps -r requirements.txt
if: steps.sedpack_venv_dependencies.outputs.cache-hit != 'true'
- name: Save cache
uses: actions/cache/save@v4
with:
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('**/requirements*.txt') }}
path: .venv
if: steps.sedpack_venv_dependencies.outputs.cache-hit != 'true'
# Build cache for current code (every commit)
local:
name: Local install
needs: [dependencies]
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
cache: 'pip'
- name: Use cached venv with dependencies
uses: actions/cache/restore@v4
id: sedpack_venv_cache
with:
# The cache key depends on requirements.txt
key: ${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('**/requirements*.txt') }}
path: .venv
fail-on-cache-miss: true
- name: Source venv
run: source .venv/bin/activate
- name: Install local
run: python -m pip install --editable .
- name: Build local package
uses: PyO3/maturin-action@v1
with:
command: develop
args: --release
sccache: 'true'
- name: Try import
run: python -c "from sedpack import _sedpack_rs"
- name: Save cache
uses: actions/cache/save@v4
with:
# The cache key is the current commit sha
key: sedpackvenv-$${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-{{ github.event.pull_request.head.sha }}
path: .venv
pytest:
name: Pytest
needs: [local]
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
steps:
# Restore venv
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
cache: 'pip'
- name: Use cached venv with installed sedpack
uses: actions/cache/restore@v4
with:
# The cache key is the current commit sha
key: sedpackvenv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ github.event.pull_request.head.sha }}
path: .venv
fail-on-cache-miss: true
# Pytest
- name: Run Pytest
shell: bash
run: |
source .venv/bin/activate
pip install -r test_requirements.txt
python -m pip install --editable .
pytest
coverage:
name: Coverage
needs: [local]
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
steps:
# Restore venv
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
cache: 'pip'
- name: Use cached venv with installed sedpack
uses: actions/cache/restore@v4
with:
# The cache key is the current commit sha
key: sedpackvenv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ github.event.pull_request.head.sha }}
path: .venv
fail-on-cache-miss: true
# Coverage
- name: Source
shell: bash
run: |
source .venv/bin/activate
pip install -r test_requirements.txt
python -m pip install --editable .
- name: Install workflow dependencies
run: pip install --upgrade pytest coverage
- name: Running unit tests with coverage
env:
DISABLE_AUTOGRAPH: 1
# TODO remove the -i (ignore errors)
run: |
coverage run -m pytest
coverage xml -i
- name: Upload results
uses: coverallsapp/github-action@v2
with:
file: coverage.xml