Skip to content

Commit

Permalink
Added workflows for building, testing, releasing (#16)
Browse files Browse the repository at this point in the history
* added workflows

* settings fix

* skip integration tests in CI
  • Loading branch information
beforan authored Jan 10, 2025
1 parent 50cd478 commit 0a13396
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .env.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DATASOURCE_DB_USERNAME=postgres
DATASOURCE_DB_PASSWORD=postgres
DATASOURCE_DB_DATABASE=hutch-omop
DATASOURCE_DB_SCHEMA=public
DATASOURCE_DB_PORT=5432
DATASOURCE_DB_HOST=localhost
TASK_API_BASE_URL=https://brcdatarq.nottingham.ac.uk/link_connector_api
TASK_API_USERNAME=link-test
TASK_API_PASSWORD=zjC/FKL91V9QIwuRsfXtcGK9LfU=
COLLECTION_ID=RQ-CC-98ac1cb4-b34f-4131-a393-3936e7a946cf
TASK_API_TYPE=a
LOW_NUMBER_SUPPRESSION_THRESHOLD=
ROUNDING_TARGET=
POLLING_INTERVAL=5
25 changes: 25 additions & 0 deletions .github/workflows/check.container-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check Container Builds

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

- name: Build Docker image
uses: docker/[email protected]
with:
context: .
file: Dockerfile
push: false
platforms: linux/amd64,linux/arm64
30 changes: 30 additions & 0 deletions .github/workflows/check.run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Tests

on:
pull_request:

jobs:
run-tests:
name: Run Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.16"
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"

- name: uv sync
run: uv sync --frozen --dev

- name: Run tests
run: uv run pytest tests
65 changes: 65 additions & 0 deletions .github/workflows/release.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This workflow is used for any merge to main and results in a built container image being pushed and tagged as a dev release
# with commit hash and timestamp tags
#
# These are not stable or pre-release semver releases!
name: Publish a Dev Release

on:
push:
branches: [main]

env:
image-name: hutch/bunny
repo-owner: ${{ github.repository_owner }}
registry: ghcr.io

jobs:
publish-bunny:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

- name: Docker Login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.registry }}
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Set timestamp env var
run: echo "RUN_TIMESTAMP=$(TZ="Etc/UTC" date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV

- name: Docker Metadata action
id: meta
uses: docker/[email protected]
with:
images: ${{ env.registry }}/${{ env.repo-owner}}/${{ env.image-name}}
tags: |
${{ github.sha }}
${{ env.RUN_TIMESTAMP }}
dev-latest
labels: |
org.opencontainers.image.title=Hutch Bunny
org.opencontainers.image.vendor=University of Nottingham
org.opencontainers.image.version=0.0.1
# TODO: version label should reflect current source version?
# Could add more custom labels in the future here

- name: Build and push Docker images
uses: docker/[email protected]
with:
context: .
file: Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion src/hutch_bunny/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

POLLING_INTERVAL_DEFAULT = 5
### currently no guards to ensure that POLLING_INTERVAL and POLLING_TIMEOUT are >=0
POLLING_INTERVAL = int(environ.get("POLLING_INTERVAL")) or POLLING_INTERVAL_DEFAULT
POLLING_INTERVAL = int(environ.get("POLLING_INTERVAL", POLLING_INTERVAL_DEFAULT))

if POLLING_INTERVAL < 0:
print("POLLING_INTERVAL must be a positive integer. Setting to default 5s...")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_demographics_distribution_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

load_dotenv()

pytestmark = pytest.mark.skipif(
os.environ.get("CI") is not None, reason="Skip integration tests in CI"
)


@pytest.fixture
def db_manager():
Expand Down
4 changes: 4 additions & 0 deletions tests/test_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

load_dotenv()

pytestmark = pytest.mark.skipif(
os.environ.get("CI") is not None, reason="Skip integration tests in CI"
)


@pytest.fixture
def db_manager():
Expand Down

0 comments on commit 0a13396

Please sign in to comment.