-
Notifications
You must be signed in to change notification settings - Fork 3
143 lines (136 loc) · 4.76 KB
/
python-tests.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
name: CI
on:
push:
branches:
- "**"
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
linters:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: create requirements.txt so that pip cache with setup-python works
run: echo "pre-commit" > requirements_precommit.txt
- uses: actions/setup-python@v4
with:
python-version: 3.8
cache: pip
cache-dependency-path: requirements_precommit.txt
- name: install pre-commit
run: python -m pip install pre-commit
- name: get cached pre-commit hooks
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: pre-commit checks
run: pre-commit run --all-files --show-diff-on-failure --color=always
type-checking:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.9
cache: pip
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox setuptools
- name: Restore cached .tox
id: cache-tox
uses: actions/cache@v3
with:
path: .tox
key:
tox-${{ matrix.python-version }}-${{ matrix.os }}-${{ hashFiles('pyproject.toml') }}
restore-keys:
tox-${{ matrix.python-version }}-${{ matrix.os }}
- name: Run mypy via tox
run: python -m tox -e type
tests:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.11"]
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
backend: ["tf", "torch"]
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox setuptools
- name: Restore cached .tox
id: cache-tox
uses: actions/cache@v3
with:
path: .tox
key:
tox-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.backend }}-${{ hashFiles('pyproject.toml') }}
restore-keys:
tox-${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.backend }}
tox-${{ matrix.python-version }}-${{ matrix.os }}
- name: Pick proper tox env
shell: python
run: |
import os; import platform; import sys; from pathlib import Path
platform_mapping = {
"Linux": "linux",
"Darwin": "macos",
"Windows": "win",
}
pythonversion = f'py{"" if platform.python_implementation() == "CPython" else "py"}3{sys.version_info.minor}'
platformversion=platform_mapping[platform.system()]
toxenv = f"{pythonversion}-{platformversion}"
toxenv += "-${{ matrix.backend }}"
set_toxenv_cmd = f"TOXENV={toxenv}"
print(f"Picked: {toxenv}")
with Path(os.environ["GITHUB_ENV"]).open("ta") as file_handler:
file_handler.write(set_toxenv_cmd)
- name: Run tox target env for ${{ env.TOXENV }}
run: |
python -m tox -e convert-doc-to-test # extract code blocks from doc to test them
python -m tox # launch environment set by TOXENV at previous step
- name: Check if coverage report exists
id: check-coverage-report
run: |
if [ -f coverage.xml ]; then
coverage_exists=true
else
coverage_exists=false
fi
echo ${coverage_exists}
echo "coverage_exists=${coverage_exists}" >> $GITHUB_OUTPUT
- name: Export coverage report (if existing)
if: steps.check-coverage-report.outputs.coverage_exists == 'true'
uses: actions/upload-artifact@v3
with:
name: coverage
path: |
coverage.xml
coverage_html
build-doc:
uses: ./.github/workflows/build-doc.yml
deploy-doc:
# for default branch (main)
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
needs: [build-doc, tests, linters]
uses: ./.github/workflows/deploy-doc.yml
with:
doc-version: ${{ needs.build-doc.outputs.doc-version }}
binder-env-fullref: ${{ github.repository }}/${{ github.ref_name}}