|
| 1 | +# SPDX-FileCopyrightText: Copyright (C) 2025 Opal Health Informatics Group at the Research Institute of the McGill University Health Centre <john.kildea@mcgill.ca> |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +name: ci |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + pull_request: |
| 11 | + workflow_dispatch: |
| 12 | + merge_group: |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 16 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +jobs: |
| 22 | + lint: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + env: |
| 25 | + RUFF_OUTPUT_FORMAT: github |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4.2.2 |
| 28 | + with: |
| 29 | + persist-credentials: false |
| 30 | + - uses: astral-sh/setup-uv@v5.3.1 |
| 31 | + id: setup-uv |
| 32 | + with: |
| 33 | + # renovate: datasource=pypi dependency=uv |
| 34 | + version: "0.6.6" |
| 35 | + - name: Install dependencies |
| 36 | + run: uv sync |
| 37 | + - name: Run ruff check |
| 38 | + if: '!cancelled()' |
| 39 | + uses: astral-sh/ruff-action@v3.2.1 |
| 40 | + - name: Run ruff format |
| 41 | + if: '!cancelled()' |
| 42 | + uses: astral-sh/ruff-action@v3.2.1 |
| 43 | + with: |
| 44 | + args: "format --check" |
| 45 | + - uses: mschoettle/pre-commit-action@v4.2.1 |
| 46 | + if: '!cancelled()' |
| 47 | + env: |
| 48 | + SKIP: ruff,ruff-format,markdownlint-cli2 |
| 49 | + - name: Fail if any previous steps failed |
| 50 | + if: failure() |
| 51 | + run: exit 1 |
| 52 | + |
| 53 | + test: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + env: |
| 56 | + DB_ROOT_PASSWORD: "root-password" |
| 57 | + DB_PASSWORD: "user-password" |
| 58 | + DB_USER: citest |
| 59 | + container: python:3.12.8-alpine3.20 |
| 60 | + services: |
| 61 | + db: |
| 62 | + image: mariadb:10.11.10-jammy |
| 63 | + env: |
| 64 | + MARIADB_ROOT_PASSWORD: ${{ env.DB_ROOT_PASSWORD }} |
| 65 | + # ensure that user has permissions for test DB to be used by pytest |
| 66 | + MARIADB_DATABASE: OpalDB |
| 67 | + MARIADB_USER: ${{ env.DB_USER }} |
| 68 | + MARIADB_PASSWORD: ${{ env.DB_PASSWORD }} |
| 69 | + |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4.2.2 |
| 72 | + with: |
| 73 | + persist-credentials: false |
| 74 | + - name: Install dependencies |
| 75 | + run: | |
| 76 | + pip install uv |
| 77 | + echo "Installed uv version is $(uv --version)" |
| 78 | + # install dependencies for mysqlclient, bash for running SQL scripts later |
| 79 | + apk add --no-cache build-base mariadb-dev mariadb-client bash |
| 80 | + uv sync |
| 81 | + - name: Prepare environment |
| 82 | + # set up env file for DB service |
| 83 | + # use sample env file |
| 84 | + # create additional DBs for legacy DB tests (OpalDB & QuestionnaireDB) |
| 85 | + run: | |
| 86 | + cp .env.sample .env |
| 87 | + sed -i "s/^DATABASE_ROOT_PASSWORD=.*/DATABASE_ROOT_PASSWORD=$DB_ROOT_PASSWORD/" .env |
| 88 | + sed -i "s/^DATABASE_USER=.*/DATABASE_USER=$DB_USER/" .env |
| 89 | + sed -i "s/^DATABASE_PASSWORD=.*/DATABASE_PASSWORD=$DB_PASSWORD/" .env |
| 90 | + sed -i "s/^DATABASE_HOST=.*/DATABASE_HOST=db/" .env |
| 91 | + MYSQL_PWD=$DB_ROOT_PASSWORD mariadb -u root -h db -e "CREATE DATABASE IF NOT EXISTS \`QuestionnaireDB\` /*!40100 DEFAULT CHARACTER SET utf8 */; GRANT ALL PRIVILEGES ON \`QuestionnaireDB\`.* TO \`$DB_USER\`@\`%\`;" |
| 92 | + MYSQL_PWD=$DB_ROOT_PASSWORD mariadb -u root -h db -e "CREATE DATABASE IF NOT EXISTS \`OrmsDatabase\` /*!40100 DEFAULT CHARACTER SET latin1 */; GRANT ALL PRIVILEGES ON \`OrmsDatabase\`.* TO \`$DB_USER\`@\`%\`;" |
| 93 | + MYSQL_PWD=$DB_ROOT_PASSWORD mariadb -u root -h db -e "CREATE DATABASE IF NOT EXISTS \`OrmsLog\` /*!40100 DEFAULT CHARACTER SET latin1 */; GRANT ALL PRIVILEGES ON \`OrmsLog\`.* TO \`$DB_USER\`@\`%\`;" |
| 94 | + - name: Run pytest |
| 95 | + run: | |
| 96 | + uv run pytest --version |
| 97 | + uv run pytest -v --junitxml=test-report.xml --tb=auto |
| 98 | + # see: https://github.com/dorny/test-reporter/issues/244 |
| 99 | + # - name: Publish Test Results |
| 100 | + # uses: dorny/test-reporter@v1.9.1 |
| 101 | + # if: '!cancelled()' |
| 102 | + # with: |
| 103 | + # name: Tests |
| 104 | + # path: ./test-report.xml |
| 105 | + # reporter: java-junit |
| 106 | + - name: Run SQL scripts |
| 107 | + run: | |
| 108 | + source .venv/bin/activate |
| 109 | + # migrate databases first |
| 110 | + ./docker/alembic-upgrade.sh |
| 111 | + # Full refresh for both OMI and OHIGPH datasets to ensure no broken data links/inconsistencies |
| 112 | + db_management/reset_data.sh OMI |
| 113 | + db_management/reset_data.sh OHIGPH |
| 114 | +
|
| 115 | +
|
| 116 | + markdownlint: |
| 117 | + permissions: |
| 118 | + contents: read |
| 119 | + # required for upload-sarif action |
| 120 | + # https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github#example-workflow-for-sarif-files-generated-outside-of-a-repository |
| 121 | + security-events: write |
| 122 | + uses: opalmedapps/.github/.github/workflows/markdownlint.yaml@main |
0 commit comments