|
| 1 | +# Contains tasks to be repeated when testing for the different Python versions listed |
| 2 | +# in the "Run unit tests" stage in .github/workflows/test-and-publish.yml |
| 3 | +name: Run tests |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + secrets: |
| 8 | + CODECOV_TOKEN: |
| 9 | + required: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + name: Run tests |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + python-version: ["3.9", "3.10", "3.11"] |
| 18 | + services: |
| 19 | + mariadb: |
| 20 | + image: mariadb:11.3.2 # released 2024-05-06 |
| 21 | + # Pulls image from DockerHub |
| 22 | + # Docker images: https://hub.docker.com/_/mariadb |
| 23 | + # Previous version(s): |
| 24 | + # 10.8 # released 2023-06-02 |
| 25 | + env: |
| 26 | + MARIADB_DATABASE: ispybtest |
| 27 | + MARIADB_ROOT_PASSWORD: mariadb_root_pwd |
| 28 | + ports: |
| 29 | + - 3306:3306 |
| 30 | + options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3 |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + - name: Use Python ${{ matrix.python-version }} |
| 35 | + uses: actions/setup-python@v5 |
| 36 | + with: |
| 37 | + python-version: ${{ matrix.python-version }} |
| 38 | + |
| 39 | + - name: Start RabbitMQ container |
| 40 | + run: | |
| 41 | + set -eux |
| 42 | + mkdir rabbitmq-docker && cd rabbitmq-docker |
| 43 | +
|
| 44 | + cat <<EOF >rabbitmq.conf |
| 45 | + # Allowing remote connections for default user is highly discouraged |
| 46 | + # as it dramatically decreases the security of the system. Delete the user |
| 47 | + # instead and create a new one with generated secure credentials. |
| 48 | + loopback_users = none |
| 49 | + EOF |
| 50 | +
|
| 51 | + cat <<EOF >Dockerfile |
| 52 | + FROM rabbitmq:3.13-management |
| 53 | + COPY rabbitmq.conf /etc/rabbitmq/rabbitmq.conf |
| 54 | + EOF |
| 55 | +
|
| 56 | + docker build -t test-rabbitmq . |
| 57 | + docker run --detach --name rabbitmq -p 127.0.0.1:5672:5672 -p 127.0.0.1:15672:15672 test-rabbitmq |
| 58 | + docker container list -a |
| 59 | +
|
| 60 | + - name: Get database |
| 61 | + uses: actions/download-artifact@v4 |
| 62 | + with: |
| 63 | + name: database |
| 64 | + path: database/ |
| 65 | + |
| 66 | + - name: Install package |
| 67 | + run: | |
| 68 | + set -eux |
| 69 | + pip install --disable-pip-version-check -e "."[cicd,client,server,developer] |
| 70 | +
|
| 71 | + - uses: shogo82148/actions-setup-mysql@v1 |
| 72 | + with: |
| 73 | + distribution: "mariadb" |
| 74 | + mysql-version: "11.3" |
| 75 | + auto-start: false |
| 76 | + |
| 77 | + - name: Set up test database |
| 78 | + run: | |
| 79 | + set -eu |
| 80 | + cp ".github/workflows/config/my.cnf" .my.cnf |
| 81 | + tar xfz "database/ispyb-database.tar.gz" |
| 82 | +
|
| 83 | + printf 'Waiting for MySQL database to accept connections' |
| 84 | + until mariadb --defaults-file=.my.cnf -e "SHOW DATABASES" >/dev/null; do printf '.'; sleep 10; done |
| 85 | + printf '\n' |
| 86 | +
|
| 87 | + mariadb --defaults-file=.my.cnf -e "SET GLOBAL log_bin_trust_function_creators = 1;" |
| 88 | + for f in schemas/ispyb/tables.sql \ |
| 89 | + schemas/ispyb/lookups.sql \ |
| 90 | + schemas/ispyb/data.sql \ |
| 91 | + schemas/ispyb/routines.sql \ |
| 92 | + grants/ispyb_processing.sql \ |
| 93 | + grants/ispyb_import.sql; do |
| 94 | + echo Importing ${f}... |
| 95 | + mariadb --defaults-file=.my.cnf < $f |
| 96 | + done |
| 97 | + 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@'%';" |
| 98 | + mariadb --defaults-file=.my.cnf -e "CREATE USER ispyb_api_future@'%' IDENTIFIED BY 'password_4321'; GRANT SELECT ON ispybtest.* to ispyb_api_future@'%';" |
| 99 | + 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@'%';" |
| 100 | + rm .my.cnf |
| 101 | +
|
| 102 | + - name: Check RabbitMQ is alive |
| 103 | + run: wget -t 10 -w 1 http://127.0.0.1:15672 -O - |
| 104 | + |
| 105 | + - name: Run tests |
| 106 | + run: | |
| 107 | + export ISPYB_CREDENTIALS=".github/workflows/config/ispyb.cfg" |
| 108 | + PYTHONDEVMODE=1 pytest -v -ra --cov=murfey --cov-report=xml --cov-branch |
| 109 | +
|
| 110 | + - name: Upload to Codecov |
| 111 | + uses: codecov/codecov-action@v4 |
| 112 | + with: |
| 113 | + name: ${{ matrix.python-version }} |
| 114 | + files: coverage.xml |
| 115 | + env: |
| 116 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 117 | + continue-on-error: true |
| 118 | + timeout-minutes: 2 |
| 119 | + |
| 120 | + - name: Show RabbitMQ logs |
| 121 | + if: always() |
| 122 | + run: | |
| 123 | + docker logs rabbitmq |
| 124 | + docker stop rabbitmq |
0 commit comments