-
Notifications
You must be signed in to change notification settings - Fork 25
78 lines (66 loc) · 2.4 KB
/
test_homework2.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
name: Homework 2 Test
on:
pull_request:
paths:
- 'members/**'
permissions:
contents: read
pull-requests: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install global dependencies
run: |
pip install fastapi pytest uvicorn
- name: Get list of changed submodules
id: changed_submodules
uses: actions/github-script@v6
with:
script: |
const pull_number = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const { data: files } = await github.rest.pulls.listFiles({
owner,
repo,
pull_number,
});
const changedSubmodules = files
.map(file => file.filename)
.filter(filename => filename.startsWith('members/'))
.map(filename => filename.split('/')[1])
.filter((value, index, self) => self.indexOf(value) === index);
if (changedSubmodules.length > 1) {
core.setFailed(`More than one submodule changed: ${changedSubmodules.join(', ')}`);
} else if (changedSubmodules.length === 0) {
core.setFailed('No submodules were changed.');
} else {
core.setOutput('submodule', changedSubmodules[0]);
}
- name: Install dependencies
if: steps.changed_submodules.outputs.submodule != ''
run: |
submodule=${{ steps.changed_submodules.outputs.submodule }}
echo "Testing $submodule"
- name: Install dependencies
if: steps.changed_submodules.outputs.submodule != ''
run: |
submodule=${{ steps.changed_submodules.outputs.submodule }}
git submodule update --init --recursive members/$submodule
pip install -r members/$submodule/requirements.txt
- name: Test submodule
if: steps.changed_submodules.outputs.submodule != ''
run: |
submodule=${{ steps.changed_submodules.outputs.submodule }}
cd members/$submodule
cp ../../.github/scripts/test_homework2.py .
pytest test_homework2.py