-
Notifications
You must be signed in to change notification settings - Fork 1
145 lines (123 loc) · 5.06 KB
/
ci.yml
File metadata and controls
145 lines (123 loc) · 5.06 KB
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
# Contains tasks to be repeated when testing for the different Python versions listed
# in the "Run unit tests" stage in .github/workflows/test.yml
name: Run tests
on:
workflow_call:
secrets:
CODECOV_TOKEN:
required: true
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
services:
mariadb:
image: mariadb:12.2.2 # released 2024-05-06
# Pulls image from DockerHub
# Docker images: https://hub.docker.com/_/mariadb
# Previous version(s):
# 10.8 # released 2023-06-02
env:
MARIADB_DATABASE: ispybtest
MARIADB_ROOT_PASSWORD: mariadb_root_pwd
ports:
- 3306:3306
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres:latest
env:
POSTGRES_DB: murfey_test_db
POSTGRES_PASSWORD: psql_pwd
POSTGRES_USER: psql_user
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v6
- name: Use Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Start RabbitMQ container
run: |
set -eux
mkdir rabbitmq-docker && cd rabbitmq-docker
cat <<EOF >rabbitmq.conf
# Allowing remote connections for default user is highly discouraged
# as it dramatically decreases the security of the system. Delete the user
# instead and create a new one with generated secure credentials.
loopback_users = none
EOF
cat <<EOF >Dockerfile
FROM rabbitmq:3.13-management
COPY rabbitmq.conf /etc/rabbitmq/rabbitmq.conf
EOF
docker build -t test-rabbitmq .
docker run --detach --name rabbitmq -p 127.0.0.1:5672:5672 -p 127.0.0.1:15672:15672 test-rabbitmq
docker container list -a
- name: Get ISPyB database
uses: actions/download-artifact@v8
with:
name: database
path: database/
- name: Install Murfey
run: |
set -eux
pip install --disable-pip-version-check -e "."[cicd,server,developer,sxt]
- uses: shogo82148/actions-setup-mysql@v1
with:
distribution: "mariadb"
mysql-version: "11.3"
auto-start: false
- name: Set up test ISPyB database
run: |
set -eu
cp ".github/workflows/config/my.cnf" .my.cnf
tar xfz "database/ispyb-database.tar.gz"
printf 'Waiting for MySQL database to accept connections'
until mariadb --defaults-file=.my.cnf -e "SHOW DATABASES" >/dev/null; do printf '.'; sleep 10; done
printf '\n'
mariadb --defaults-file=.my.cnf -e "SET GLOBAL log_bin_trust_function_creators = 1;"
for f in schemas/ispyb/tables.sql \
schemas/ispyb/lookups.sql \
schemas/ispyb/data.sql \
schemas/ispyb/routines.sql \
grants/ispyb_processing.sql \
grants/ispyb_import.sql; do
echo "Patching ${f} in SQL files to fix CLI escape issues..."
sed -i 's/\\-/-/g' "$f"
echo "Importing ${f}..."
mariadb --defaults-file=.my.cnf < $f
done
mariadb --defaults-file=.my.cnf -e "CREATE USER ispyb_api@'%' IDENTIFIED BY 'password_1234'; GRANT ispyb_processing to ispyb_api@'%'; GRANT ispyb_import to ispyb_api@'%'; SET DEFAULT ROLE ispyb_processing FOR ispyb_api@'%';"
mariadb --defaults-file=.my.cnf -e "CREATE USER ispyb_api_future@'%' IDENTIFIED BY 'password_4321'; GRANT SELECT ON ispybtest.* to ispyb_api_future@'%';"
mariadb --defaults-file=.my.cnf -e "CREATE USER ispyb_api_sqlalchemy@'%' IDENTIFIED BY 'password_5678'; GRANT SELECT ON ispybtest.* to ispyb_api_sqlalchemy@'%'; GRANT INSERT ON ispybtest.* to ispyb_api_sqlalchemy@'%'; GRANT UPDATE ON ispybtest.* to ispyb_api_sqlalchemy@'%';"
rm .my.cnf
- name: Check RabbitMQ is alive
run: wget -t 10 -w 1 http://127.0.0.1:15672 -O -
- name: Run Murfey tests
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: murfey_test_db
POSTGRES_PASSWORD: psql_pwd
POSTGRES_USER: psql_user
run: |
PYTHONDEVMODE=1 pytest -v -ra --cov=murfey --cov-report=xml --cov-branch
- name: Upload test results to Codecov
uses: codecov/codecov-action@v5
with:
name: ${{ matrix.python-version }}
files: coverage.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true
timeout-minutes: 2
- name: Show RabbitMQ logs
if: always()
run: |
docker logs rabbitmq
docker stop rabbitmq