-
Notifications
You must be signed in to change notification settings - Fork 1
143 lines (117 loc) · 3.62 KB
/
ci_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
name: CI - Tests
on:
pull_request:
push:
branches:
- 'main'
- 'push-action/**' # Allow pushing to protected branches (using CasperWA/push-protected)
jobs:
basic-tests:
name: External
uses: SINTEF/ci-cd/.github/workflows/[email protected]
with:
# General setup
install_extras: "[dev]"
# pre-commit
python_version_pre-commit: "3.10"
# pylint & safety
python_version_pylint_safety: "3.10"
run_pylint: false
# Build dist
python_version_package: "3.10"
build_libs: flit
build_cmd: flit build
# Build documentation
run_build_docs: false
docker:
name: Docker
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
docker_target: ["development", "production"]
services:
mongo:
image: mongo:6
ports:
- "27017:27017"
env:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
env:
ENTITY_SERVICE_MONGO_URI: mongodb://localhost:27017
ENTITY_SERVICE_MONGO_USER: root
ENTITY_SERVICE_MONGO_PASSWORD: root
DOCKER_TEST_PORT: 8000
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Build Docker image
run: docker build --pull -t entity-service --target ${{ matrix.docker_target }} .
- name: Run Docker container
run: |
docker run --rm -d \
--env ENTITY_SERVICE_MONGO_URI \
--env ENTITY_SERVICE_MONGO_USER \
--env ENTITY_SERVICE_MONGO_PASSWORD \
--env PORT=${DOCKER_TEST_PORT} \
--name "entity-service" \
--network "host" \
--volume "${PWD}:/app" \
entity-service
sleep 5
- name: Install test dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel flit
pip install -U -r .github/utils/requirements_docker_test.txt
pip install -U -e .
- name: Fill MongoDB with test data
run: ./.github/utils/docker_test.py add-testdata
- name: Run tests
env:
DOCKER_TEST_HOST: localhost
run: |
{
./.github/utils/docker_test.py run-tests &&
cat logs/dlite_entities_service.log
} || {
echo "Failed! Here's the Docker logs for the service:" &&
docker logs entity-service &&
echo -e "\nAnd the service log:" &&
cat logs/dlite_entities_service.log &&
exit 1
}
pytest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python_version: ["3.10", "3.11", "3.12"]
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python_version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: Install test dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel flit
pip install -U -e .[testing]
- name: Run pytest
run: pytest -vv --cov-report=xml
- name: Upload coverage
if: github.repository_owner == 'SINTEF' && matrix.python_version == '3.10'
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
env_vars: OS,PYTHON
env:
OS: ubuntu-latest
PYTHON: ${{ matrix.python_version }}