Skip to content

Commit d556317

Browse files
authored
Add workflows for codeql and component testing (#350)
* add workflows for codeql and component testing * remove codeql workflow * disable live tests during workflow * run action when pr is updated * remove duplicate key * remove type restriction * add cleanup to tests and improve logging * fix handling of pytest exit code * add manual installation of pytest if required * use unified env for python tests * update transformer version * try caching of virtual environments * disable client logging for tests * add exclusion checks for submodules * add KGQAnWrapper submodule * exit if external environment dir not possible
1 parent a22412f commit d556317

File tree

13 files changed

+177
-9
lines changed

13 files changed

+177
-9
lines changed

.github/workflows/run-tests.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Qanary component test pipeline
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
test-java:
9+
runs-on: ubuntu-latest
10+
env:
11+
BABELFY_API_KEY : someapikey
12+
CHATGPT_API_KEY : someapikey
13+
DANDELION_API_KEY : someapikey
14+
MEANINGCLOUD_API_KEY : someapikey
15+
TAGME_API_KEY : someapikey
16+
TEXTRAZOR_API_KEY : someapikey
17+
OPENAI_API_KEY : someapikey
18+
BABELFY_API_LIVE_TEST_ACTIVE : false
19+
PLATYPUS_API_LIVE_TEST_ACTIVE : false
20+
TEXTRAZOR_API_LIVE_TEST_ACTIVE : false
21+
CHATGPT_API_LIVE_TEST_ACTIVE : false
22+
DANDELION_API_LIVE_TEST_ACTIVE : false
23+
MEANINGCLOUD_API_LIVE_TEST_ACTIVE : false
24+
AGDISTIS_API_LIVE_TEST_ACTIVE : false
25+
OPENAI_API_LIVE_TEST_ACTIVE : false
26+
TAGME_API_LIVE_TEST_ACTIVE : false
27+
steps:
28+
- name: Configure java
29+
uses: actions/setup-java@v4
30+
with:
31+
distribution: 'corretto'
32+
java-version: '17'
33+
- uses: actions/checkout@v4
34+
- name: Test Java components
35+
run: bash -c ./service_config/test_java_components.sh
36+
test-python:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Configure Python
40+
uses: actions/setup-python@v4
41+
id: setup_python
42+
with:
43+
python-version: '3.12'
44+
- uses: actions/checkout@v4
45+
- name: Cache virtual environments
46+
uses: actions/cache@v4
47+
with:
48+
key: environments-${{ runner.os }}-${{ steps.setup_python.outputs.python-version}}-${{ hashFiles('**/requirements.txt') }}
49+
path: environments
50+
- name: Test Python components
51+
run: bash -c ./service_config/test_python_components.sh

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "Qanary-component-QB-Python-KGQAnWrapper"]
2+
path = Qanary-component-QB-Python-KGQAnWrapper
3+
url = https://github.com/WSE-research/Qanary-component-QB-Python-KGQAnWrapper.git

qanary-component-MT-Python-HelsinkiNLP/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
log_cli = 1
2+
log_cli = 0
33
log_cli_level = INFO
44
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
55
log_cli_date_format=%Y-%m-%d %H:%M:%S

qanary-component-MT-Python-LibreTranslate/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
log_cli = 1
2+
log_cli = 0
33
log_cli_level = INFO
44
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
55
log_cli_date_format=%Y-%m-%d %H:%M:%S

qanary-component-MT-Python-MBart/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
log_cli = 1
2+
log_cli = 0
33
log_cli_level = INFO
44
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
55
log_cli_date_format=%Y-%m-%d %H:%M:%S

qanary-component-MT-Python-MBart/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ langid==1.1.6
44
mock==3.0.5
55
python-dotenv==0.21.1
66
qanary_helpers==0.2.2
7-
transformers==4.25.1
7+
transformers==4.41.0
88
sentencepiece==0.1.97
9-
torch==1.13.1
9+
torch==2.3.0
1010
gunicorn==20.1.0
1111
protobuf==3.20.*
1212
pytest

qanary-component-MT-Python-NLLB/pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
log_cli = 1
2+
log_cli = 0
33
log_cli_level = INFO
44
log_cli_format = %(asctime)s [%(levelname)8s] [%(filename)s:%(lineno)s] %(message)s
55
log_cli_date_format=%Y-%m-%d %H:%M:%S

qanary-component-MT-Python-NLLB/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ langdetect==1.0.9
33
mock==3.0.5
44
python-dotenv==0.21.1
55
qanary_helpers==0.2.2
6-
transformers==4.25.1
6+
transformers==4.41.0
77
sentencepiece==0.1.97
8-
torch==1.13.1
8+
torch==2.3.0
99
gunicorn==20.1.0
1010
protobuf==3.20.*
1111
pytest

service_config/build_images.sh

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#!/bin/bash
22

3+
# ensure that submodules are not in maven reactor
4+
submodules=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
5+
for submodule in $submodules;
6+
do
7+
if grep -qi $submodule "pom.xml"; then
8+
echo "Submodules should be tested and built externally. Please remove \"${submodule}\" from the maven reactor list."
9+
exit 4
10+
fi
11+
done
12+
313
# replace secrets
414
if [ -z "$BABELFY_API_KEY" ]
515
then

service_config/build_python_images.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22

3-
images=$(ls | grep -P "qanary-component.*Python-[a-zA-Z]+$")
3+
# get a list of all Python component directories
4+
# exclude submodules (external component repositories)
5+
images=$(comm -3 <(ls | grep -P "[qQ]anary-component.*Python-[a-zA-Z]+$") <(git config --file .gitmodules --get-regexp path | awk '{ print $2 }'))
46

57
for dir in $images
68
do
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# ensure that submodules are not in maven reactor
4+
submodules=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
5+
for submodule in $submodules;
6+
do
7+
if grep -qi $submodule "pom.xml"; then
8+
echo "Submodules should be tested and built externally. Please remove \"${submodule}\" from the maven reactor list."
9+
exit 4
10+
fi
11+
done
12+
13+
# test components
14+
if ! mvn --batch-mode --no-transfer-progress test;
15+
then
16+
echo "Maven test failed"
17+
exit 4 # stop if test fails
18+
fi
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
declare -A summary
4+
failures=false
5+
# get a list of all Python component directories
6+
# exclude submodules (external component repositories)
7+
components=$(comm -3 <(ls | grep -P "[qQ]anary-component.*Python-[a-zA-Z]+$") <(git config --file .gitmodules --get-regexp path | awk '{ print $2 }'))
8+
9+
# create a super directory to hold virtual environments (for caching)
10+
11+
if [ -d environments ]; then
12+
echo "External evironment directory exists"
13+
else
14+
if mkdir environments; then
15+
echo "External environment directory created"
16+
else
17+
echo "External environment directory could not be created"
18+
exit 4
19+
fi
20+
fi
21+
22+
printf "Found Python components:\n\n${components}\n\n"
23+
24+
25+
# iterate over components
26+
for dir in $components
27+
do
28+
# iterate over Python components
29+
name=$(echo ${dir} | tr "[:upper:]" "[:lower:]")
30+
printf "\n\n===== ${name} =====\n\n"
31+
32+
cd $dir
33+
# setup virtual environment in external super directory
34+
envname=../environments/${name}
35+
python -m venv ${envname}
36+
if source ${envname}/bin/activate; then
37+
pip install -r requirements.txt
38+
else
39+
echo "Something went wrong trying to install requirements! Exiting ..."
40+
exit 4
41+
fi
42+
43+
# install pytest manually if not included in requirements
44+
if ! pip show pytest; then
45+
echo "Installing pytest manually..."
46+
pip install pytest
47+
fi
48+
if ! pip show pytest-env; then
49+
echo "Installing pytest-env manually..."
50+
pip install pytest-env
51+
fi
52+
53+
# run tests
54+
pytest
55+
test_status=$?
56+
# check exit codes
57+
if [ $test_status -eq 0 ]; then # all tests successful
58+
summary[${name}]="passed"
59+
elif [ $test_status -eq 5 ]; then # no tests found
60+
summary[${name}]="no tests"
61+
else # tests failed or something else went wrong
62+
summary[${name}]="failed"
63+
failures=true
64+
fi
65+
66+
#pip freeze | xargs pip uninstall -y TODO: disabled because that would mess with caching
67+
deactivate
68+
rm -r ${envname}
69+
70+
cd ..
71+
72+
done
73+
74+
75+
# print a summary
76+
printf "\n\n===== SUMMARY =====\n\n"
77+
for x in "${!summary[@]}"; do printf "%s\t:\t[%s]\n" "$x" "${summary[$x]}"; done | column -s$'\t' -t
78+
if $failures; then
79+
printf "\nSome tests failed!\n"
80+
exit 4
81+
else
82+
printf "\nTests succeeded\n"
83+
fi

0 commit comments

Comments
 (0)