-
Notifications
You must be signed in to change notification settings - Fork 5
115 lines (103 loc) · 3.42 KB
/
ci.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
name: native-app-examples
on:
pull_request:
types:
- opened
- edited
- labeled
- unlabeled
- synchronize
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- environment-file: shared_python_ci_env.yml
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Get changed files
id: changed-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
else
echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
fi
- name: Determine tests to run
uses: actions/github-script@v7
id: tests_to_run
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.changed_files }}
with:
script: |
const { CHANGED_FILES } = process.env;
const fs = require('fs');
const path = require('path');
function getPytestPaths(dir, callback)
{
const files = fs.readdirSync(dir, { withFileTypes: true });
for (const file of files)
{
if (file.isDirectory())
{
getPytestPaths(path.join(dir, file.name), callback);
}
else
{
extension = path.extname(file.name);
if (extension == '.py')
{
callback(dir);
}
}
}
}
const paths = new Set(CHANGED_FILES.split(" ")
.map(x => x.substring(0, x.indexOf("/") + 1))
.filter(x => x.length > 0 && !x.startsWith('.')));
const pytestPaths = new Set()
const pytestArgs = new Set()
for (const rootPath of paths)
{
let count = 0;
getPytestPaths(rootPath, x =>
{
pytestPaths.add(x);
count++
})
if (count > 0)
{
pytestArgs.add(rootPath)
}
}
core.setOutput('pytestPaths', [...pytestPaths].join(' '));
core.setOutput('pytestArgs', [...pytestArgs].join(' '));
- name: Setup test environment
uses: conda-incubator/setup-miniconda@v2
with:
environment-file: ${{ matrix.environment-file }}
- name: Install dependencies
run: |
printf "[pytest]\npythonpath=${{ steps.tests_to_run.outputs.pytestPaths }}" > pytest.ini
python -m pip install pytest
- name: Run tests
run: |
args=${{ steps.tests_to_run.outputs.pytestArgs }}
pythonpath=${{ steps.tests_to_run.outputs.pytestPaths }}
if [ -z "${args}" ] || [ -z "${pythonpath}" ]; then
echo “Nothing to test”
else
pytest $args
fi