-
Notifications
You must be signed in to change notification settings - Fork 37
158 lines (134 loc) · 4.49 KB
/
run-unit-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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Copyright 2020-2024 The MathWorks, Inc.
name: Unit Testing MATLAB Integration for Jupyter
on:
# Reusable workflow
# Trigger on workflow call
workflow_call:
workflow_dispatch:
jobs:
matlab_unit_tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
matlab-release: [R2021b, latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up virtual display on Ubuntu
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y xvfb
# Function to check if a display port is free
is_display_free() {
xvfb-run --auto-servernum --server-num=$1 true 2>/dev/null
}
# Find the first free display port
DISPLAY_PORT=""
for num in $(seq 99 -1 0); do
if is_display_free $num; then
DISPLAY_PORT=$num
break
fi
done
# Start Xvfb with the free port
Xvfb :$DISPLAY_PORT -ac &
# Set the DISPLAY environment variable
echo "DISPLAY=:$DISPLAY_PORT" >> $GITHUB_ENV
# Print the chosen display port for debugging
echo "Using display port :$DISPLAY_PORT"
- name: Set up MATLAB ${{ matrix.matlab-release }}
# Use MATLAB Actions to get running MATLAB in GitHub Actions
uses: matlab-actions/setup-matlab@v2
with:
release: ${{ matrix.matlab-release }}
products: >
Symbolic_Math_Toolbox
- name: Run tests
uses: matlab-actions/run-tests@v2
with:
select-by-folder: tests/matlab-tests
python_unit_tests:
env:
code-cov-py: "3.11"
code-cov-os: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.11"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
# Installing wheel package will slightly speed-up installing dependencies.
# Installing the package with "[dev]" flag will install test dependecies as well,
# enabling us to run pytest.
run: |
python3 -m pip install --upgrade pip
python3 -m pip install wheel pytest
python3 -m pip install .[dev]
- name: Lint with black
run: black --check .
- name: Test with pytest
if: ${{ matrix.python-version != env.code-cov-py }}
run: python3 -m pytest tests/unit
- name: Test with pytest and get code coverage for Python ${{env.code-cov-py}}
if: ${{matrix.python-version == env.code-cov-py }}
run: python3 -m pytest --cov --cov-report=xml tests/unit
- name: Persist coverage data to be uploaded if all jobs are successful.
if: ${{matrix.python-version == env.code-cov-py && matrix.os == env.code-cov-os}}
uses: actions/upload-artifact@v4
with:
name: coverage_file
path: ./coverage.xml
retention-days: 5
lezer_unit_tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: src/jupyter_matlab_labextension/src/lezer-matlab/test/
env:
NODE_VERSION: 18
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install node dependencies and build parser
run: npm install
- name: Run Lezer tests
run: npm test
upload_code_coverage:
name: "Upload Code Coverage using codecov"
needs: [python_unit_tests]
if: success()
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get coverage files from previous job
uses: actions/download-artifact@v4
with:
name: coverage_file
- name: Upload python coverage report to Codecov
uses: codecov/codecov-action@v4
with:
directory: ./
name: Python-codecov
files: ./coverage.xml
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}