forked from ckan/ckanext-validation
-
Notifications
You must be signed in to change notification settings - Fork 3
215 lines (187 loc) · 8.1 KB
/
test-direct.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Tests (direct)
on:
push:
pull_request:
branches:
- master
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install requirements
run: pip install flake8 pycodestyle
- name: Check syntax
run: flake8
test:
needs: lint
strategy:
matrix:
include: #ckan-image see https://github.com/ckan/ckan-docker-base, ckan-version controls other image tags
- ckan-version: "2.11"
ckan-image: "2.11-py3.10"
ckan-solr: "2.11-solr9"
experimental: true
- ckan-version: "2.10"
ckan-image: "2.10-py3.10"
ckan-solr: "2.10-solr9"
experimental: true
- ckan-version: "2.9"
ckan-image: "2.9-py3.9"
ckan-solr: "2.9-solr8"
experimental: true
- ckan-version: "master"
ckan-image: "master"
ckan-solr: "master-solr9"
experimental: true # master is unstable, good to know if we are compatible or not
fail-fast: false
name: ${{ matrix.experimental && '**Fail_Ignored** ' || '' }}CKAN ${{ matrix.ckan-version }}
runs-on: ubuntu-latest
container:
image: ckan/ckan-dev:${{ matrix.ckan-image }}
# --hostname ckan allows chrome container to access this container for bdd testing
options: --user root --hostname ckan
services:
solr:
image: ckan/ckan-solr:${{ matrix.ckan-solr }}
postgres:
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
# ports:
# - 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
redis:
image: redis:3
chrome:
image: selenium/standalone-chrome:131.0-chromedriver-131.0-grid-4.27.0-20241225
options: --shm-size=1gb
env:
CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test
CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test
CKAN_DATASTORE_READ_URL: postgresql://datastore_read:pass@postgres/datastore_test
CKAN_SOLR_URL: http://solr:8983/solr/ckan
CKAN_REDIS_URL: redis://redis:6379/1
CKAN_SITE_URL: http://ckan:5000
CKAN__PLUGINS: "datastore envvars validation scheming_datasets test_validation_plugin"
steps:
- uses: actions/checkout@v4
continue-on-error: ${{ matrix.experimental }}
- name: Pin setuptools for ckan 2.9 only
if: ${{ matrix.ckan-version == 2.9 }}
run: pip install "setuptools>=44.1.0,<71"
continue-on-error: ${{ matrix.experimental }}
- name: Install requirements
continue-on-error: ${{ matrix.experimental }}
run: |
pip install -r dev-requirements.txt
pip install -r requirements.txt
pip install -e .
# Replace default path to CKAN core config file with the one on the container
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini
- name: Pin jinja2 for ckan 2.9 only (last jinja version that had escape class)
if: ${{ matrix.ckan-version == 2.9 }}
run: pip install "jinja2<3.1"
continue-on-error: ${{ matrix.experimental }}
- name: Setup extension
continue-on-error: ${{ matrix.experimental }}
run: |
ckan -c test.ini db init
ckan -c test.ini validation init-db
- name: Run tests
continue-on-error: ${{ matrix.experimental }}
run: pytest --ckan-ini=test.ini --cov=ckanext.validation --cov-report=xml:coverage.xml --cov-append --disable-warnings ckanext/validation/tests -vv --junit-xml=TESTS-results.xml
- name: Config for BDD testing
run: |
echo "::group::ckan config"
## Since we are using the ckan-dev as the running container, we need to manually setup the system
## https://github.com/ckan/ckan-docker-base/blob/main/ckan-2.11/setup/start_ckan_development.sh
export CKAN_INI=/srv/app/ckan.ini
echo "Setting beaker.session.secret in ini file"
ckan config-tool $CKAN_INI "beaker.session.secret=$(python3 -c 'import secrets; print(secrets.token_urlsafe())')"
ckan config-tool $CKAN_INI "SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_urlsafe())')"
ckan config-tool $CKAN_INI "WTF_CSRF_SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_urlsafe())')"
JWT_SECRET=$(python3 -c 'import secrets; print("string:" + secrets.token_urlsafe())')
ckan config-tool $CKAN_INI "api_token.jwt.encode.secret=${JWT_SECRET}"
ckan config-tool $CKAN_INI "api_token.jwt.decode.secret=${JWT_SECRET}"
ckan config-tool $CKAN_INI "ckan.plugins = datastore envvars validation scheming_datasets test_validation_plugin"
ckan config-tool $CKAN_INI "ckan.site_url = http://ckan:5000/"
ckan config-tool $CKAN_INI -s server:main "host = 0.0.0.0"
ckan config-tool $CKAN_INI -s server:main "port = 5000"
echo "::endgroup::"
echo "::group::ckan debug output"
echo "cat /srv/app/ckan.ini"
cat /srv/app/ckan.ini
echo "/etc/hosts"
# if ! grep -q "127.0.0.1 ckan" /etc/hosts; then
# echo "" >> /etc/hosts
# echo "127.0.0.1 ckan" >> /etc/hosts
# fi
cat /etc/hosts
echo "::endgroup::"
echo "::group::Install curl, procps"
if [ -f /etc/alpine-release ]; then
apk add --no-cache procps curl
elif [ -f /etc/debian_version ]; then
apt-get update
apt-get install -y --no-install-recommends build-essential curl procps
fi
echo "::endgroup::"
pip install -r test/dev-requirements.txt
- name: Pin urllib3 for ckan 2.9 only (last urllib3 version that requests is happy with)
if: ${{ matrix.ckan-version == 2.9 }}
run: pip install "urllib3<1.27"
continue-on-error: ${{ matrix.experimental }}
- name: Run BDD tests
continue-on-error: ${{ matrix.experimental }}
run: |
rm -rf test/screenshots/*
mkdir -p test/screenshots
export CKAN_INI=/srv/app/ckan.ini
export CKAN_SITE_URL=http://ckan:5000/
ckan -c $CKAN_INI run -H 0.0.0.0 > test/screenshots/ckan.log 2>&1 &
ckan -c $CKAN_INI jobs worker > test/screenshots/ckan-worker.log 2>&1 &
sleep 5
echo "::group::ckan clean db and init"
ckan db clean --yes
ckan db init
echo "validation init-db"
ckan validation init-db
echo "::endgroup::"
echo "::group::create test data"
chmod +x ./bin/*
echo "create test data"
./bin/create-test-data.sh
echo "::endgroup::"
# curl -v http://ckan:5000
# echo "login"
# curl -v http://ckan:5000/user/login
echo "::group::BDD Tests"
behave --junit --junit-directory . --summary -k ${*:-test/features} $EXTRA_TAGS --tags=${BEHAVE_TAG:--format_autocomplete}
echo "::endgroup::"
- name: Upload BDD outputs
if: always()
uses: actions/upload-artifact@v4
with:
name: CKAN ${{ matrix.ckan-version }} BDD outputs
path: test/screenshots
timeout-minutes: 1
continue-on-error: ${{ matrix.experimental }}
- name: Test Summary
uses: test-summary/action@v2
continue-on-error: ${{ matrix.experimental }}
with:
paths: "./TEST*.xml"
if: always()
- name: "Upload coverage report to codecov flag: ${{ matrix.ckan-version }}"
uses: codecov/codecov-action@v5
continue-on-error: ${{ matrix.experimental }}
with:
file: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
flags: "${{ matrix.ckan-version }}"