Skip to content

Commit 8b92e52

Browse files
committed
Add test-coverage.yml
1 parent 7551efc commit 8b92e52

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Run tests and upload coverage
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- develop
7+
- master
8+
pull_request:
9+
branches-ignore:
10+
- develop
11+
- master
12+
13+
jobs:
14+
test:
15+
name: Run tests and collect coverage
16+
runs-on: ubuntu-22.04
17+
environment: test-coverage
18+
19+
services:
20+
mssql:
21+
image: mcr.microsoft.com/mssql/server:2019-latest
22+
ports:
23+
- 1433:1433
24+
env:
25+
ACCEPT_EULA: Y
26+
SA_PASSWORD: "TestP@ssw0rd123!"
27+
MSSQL_PID: Developer
28+
MSSQL_MEMORY_LIMIT_MB: 4096
29+
options: >-
30+
--health-cmd "/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P '${SA_PASSWORD}' -Q 'SELECT 1' || exit 1"
31+
--health-interval 10s
32+
--health-timeout 300s
33+
--health-retries 5
34+
35+
postgres:
36+
image: postgres:latest
37+
ports:
38+
- 5432:5432
39+
env:
40+
POSTGRES_DB: testdb
41+
POSTGRES_USER: postgres
42+
POSTGRES_PASSWORD: 123
43+
options: >-
44+
--health-cmd "pg_isready -U postgres -d testdb"
45+
--health-interval 10s
46+
--health-timeout 5s
47+
--health-retries 5
48+
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
55+
- name: Fix MSSQL data directory permissions
56+
run: |
57+
docker exec mssql chown -R mssql:mssql /var/opt/mssql/data
58+
docker exec mssql chmod -R 777 /var/opt/mssql/data
59+
if: always()
60+
61+
- name: Start MSSQL container
62+
run: |
63+
for i in {1..30}; do
64+
nc -zv localhost 1433 && echo "PostgreSQL is up" && break
65+
echo "Waiting for MSSQL to start..."
66+
sleep 5
67+
done
68+
shell: bash
69+
70+
- name: Start PostgreSQL container
71+
run: |
72+
for i in {1..30}; do
73+
nc -zv localhost 5432 && echo "PostgreSQL is up" && break
74+
sleep 5
75+
done
76+
shell: bash
77+
78+
- name: Set up Conda
79+
uses: conda-incubator/setup-miniconda@v3
80+
with:
81+
activate-environment: pyhelpers-test-env
82+
python-version: "3.10"
83+
auto-update-conda: true
84+
85+
- name: Install application dependencies (7-Zip, Pandoc, Inkscape, wkhtmltopdf, Wine)
86+
shell: bash -l {0} # Ensures Conda environment is active
87+
run: |
88+
sudo apt update
89+
sudo apt install -y p7zip-full pandoc inkscape wkhtmltopdf netcat
90+
91+
sudo dpkg --add-architecture i386
92+
sudo apt update
93+
sudo apt install -y software-properties-common wget
94+
sudo mkdir -pm755 /etc/apt/keyrings
95+
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
96+
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
97+
sudo apt update
98+
sudo apt install -y --install-recommends winehq-stable wine32
99+
100+
- name: Install Xvfb for Wine (Headless Mode)
101+
run: |
102+
sudo apt install -y xvfb
103+
104+
- name: Set up virtual display with Xvfb
105+
run: |
106+
echo "Starting virtual display"
107+
export DISPLAY=:99
108+
Xvfb :99 &
109+
echo "DISPLAY=:99" >> $GITHUB_ENV # Persist for subsequent steps
110+
111+
- name: Initialise Wine
112+
run: |
113+
export DISPLAY=:99
114+
WINEARCH=win32 WINEPREFIX=~/.wine wineboot -u
115+
winecfg >/dev/null 2>&1 # Ensure Wine is fully initialized
116+
fc-cache -fv
117+
118+
- name: Install required Wine libraries
119+
run: |
120+
sudo apt install -y winetricks
121+
WINEARCH=win32 WINEPREFIX=~/.wine winetricks --unattended vcrun2010 corefonts
122+
123+
- name: Verify the installation of application dependencies
124+
run: |
125+
WINEARCH=win32 WINEPREFIX=~/.wine wine cmd /c echo 'Wine is working!'
126+
wine --version
127+
7z --help
128+
pandoc --version
129+
inkscape --version
130+
wkhtmltopdf --version
131+
132+
- name: Install GDAL and PyHelpers' essential dependencies
133+
shell: bash -l {0}
134+
run: |
135+
conda activate pyhelpers-test-env
136+
conda install -y -c conda-forge gdal
137+
python -c "from osgeo import gdal; print(gdal.__version__)"
138+
python -m pip install --upgrade pip
139+
sed '/gdal/d' requirements.txt | pip install -r /dev/stdin
140+
python -m nltk.downloader popular
141+
142+
- name: Cache NLTK data
143+
uses: actions/cache@v4
144+
with:
145+
path: ~/.nltk_data
146+
key: ${{ runner.os }}-nltk-data-${{ hashFiles('**/*.py') }}
147+
restore-keys: |
148+
${{ runner.os }}-nltk-data-
149+
150+
- name: Run tests
151+
shell: bash -l {0}
152+
env:
153+
MSSQL_SERVER: localhost
154+
MSSQL_PORT: 1433
155+
MSSQL_USER: sa
156+
MSSQL_PASSWORD: "TestP@ssw0rd123!"
157+
MSSQL_DB: testdb
158+
159+
POSTGRES_SERVER: localhost
160+
POSTGRES_PORT: 5432
161+
POSTGRES_USER: postgres
162+
POSTGRES_PASSWORD: 123
163+
POSTGRES_DB: testdb
164+
run: |
165+
python -m pytest -v --cov=pyhelpers --cov-branch \
166+
--cov-report=term --cov-report=xml:coverage.xml tests/
167+
168+
- name: Debug coverage file
169+
shell: bash -l {0}
170+
run: ls -lah

0 commit comments

Comments
 (0)