Skip to content

Commit 4489597

Browse files
authored
chore: add initial CI workflow (#473)
1 parent a81a140 commit 4489597

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

.github/workflows/ci.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,33 @@ repos:
6666
rev: v1.30.1
6767
hooks:
6868
- id: typos
69+
70+
# zizmor detects security vulnerabilities in GitHub Actions workflows.
71+
- repo: https://github.com/woodruffw/zizmor-pre-commit
72+
rev: v1.4.1
73+
hooks:
74+
- id: zizmor
75+
76+
- repo: https://github.com/python-jsonschema/check-jsonschema
77+
rev: 0.31.2
78+
hooks:
79+
- id: check-github-workflows
80+
args: ["--verbose"]
81+
- id: check-compose-spec
82+
args: ["--verbose"]
83+
- id: check-renovate
84+
args: ["--verbose"]
85+
additional_dependencies: ['json5']
86+
87+
# `actionlint` hook, for verifying correct syntax in GitHub Actions workflows.
88+
# Some additional configuration for `actionlint` can be found in `.github/actionlint.yaml`.
89+
- repo: https://github.com/rhysd/actionlint
90+
rev: v1.7.7
91+
hooks:
92+
- id: actionlint
93+
language: golang
94+
additional_dependencies:
95+
# actionlint has a shellcheck integration which extracts shell scripts in `run:` steps from GitHub Actions
96+
# and checks these with shellcheck.
97+
# see also: https://github.com/rhysd/actionlint/pull/482
98+
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.10.0"

renovate.json5

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// https://docs.renovatebot.com/presets-default/#enableprecommit
1414
":enablePreCommit",
1515
"github>mschoettle/renovate-presets//presets/docker-alpine.json5",
16+
"github>mschoettle/renovate-presets//presets/actions-dependency-version.json5",
1617
],
1718
"pip_requirements": {
1819
"fileMatch": ["^requirements/.*\\.txt$"]

0 commit comments

Comments
 (0)