Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,43 @@ name: build

on:
push:
pull_request:

env:
PROJECT_NAME: genesis-notification
REPO_ENDPOINT_PUT: http://10.20.0.1:8082

jobs:
Build:
runs-on: self-hosted
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Build Genesis Core
run: |
set -eux

genesis build $(pwd)

# Temporary upload step is done in the build script
VERSION="$(genesis get-version .)"
ELEMENT_PATH="/var/lib/repository/genesis_notification"

# Prepare `raw` and `raw.gz` images
cd output
qemu-img convert -f qcow2 genesis-notification.qcow2 -O raw genesis-notification.raw
gzip -5 -k < genesis-notification.raw > genesis-notification.raw.gz

# Upload the VM images
curl -X PUT --upload-file genesis-notification.qcow2 \
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/genesis-notification.qcow2
curl -X PUT --upload-file genesis-notification.raw.gz \
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/genesis-notification.raw.gz
curl -X PUT --upload-file genesis-notification.raw \
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/genesis-notification.raw

sha256sum genesis-notification.qcow2 >> SHA256SUMS
sha256sum genesis-notification.raw.gz >> SHA256SUMS
sha256sum genesis-notification.raw >> SHA256SUMS

rm -fr "${ELEMENT_PATH}/${VERSION}"
mkdir -p "${ELEMENT_PATH}/${VERSION}"
mv output/genesis-notification.qcow2 "${ELEMENT_PATH}/${VERSION}/"
cd ${ELEMENT_PATH}/${VERSION}/ && \
sha256sum genesis-notification.qcow2 >> ${ELEMENT_PATH}/${VERSION}/SHA256SUMS
curl -X PUT --upload-file SHA256SUMS \
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/SHA256SUMS
cd -
8 changes: 4 additions & 4 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Python
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: python-package-distributions
path: dist/
Expand All @@ -46,7 +46,7 @@ jobs:

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
uses: actions/download-artifact@v5
with:
name: python-package-distributions
path: dist/
Expand All @@ -67,7 +67,7 @@ jobs:

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
uses: actions/download-artifact@v5
with:
name: python-package-distributions
path: dist/
Expand Down
45 changes: 32 additions & 13 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ name: tests

on:
push:
paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
- '.markdownlint.yaml'
pull_request:

paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
- '.markdownlint.yaml'
jobs:
Lint:
runs-on: ubuntu-24.04
Expand All @@ -12,22 +19,26 @@ jobs:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install requirements
run: sudo apt update && sudo apt install --yes tox libev-dev libvirt-dev
- name: Black
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install tox-uv
run: uv tool install tox --with tox-uv
- name: ruff
run: |
tox -e black-check
tox -e ruff-check
Tests:
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.10", "3.12", "3.13"]
python-version: ["3.8", "3.10", "3.11", "3.12", "3.13", "3.14"]
services:
postgresql:
image: postgres:latest
Expand All @@ -43,13 +54,17 @@ jobs:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: sudo apt update && sudo apt install --yes tox libev-dev libvirt-dev
- name: Install requirements
run: sudo apt update && sudo apt install --yes libev-dev libvirt-dev
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install tox-uv
run: uv tool install tox --with tox-uv
- name: Unit tests
run: |
tox -e ${{ matrix.python-version }}
Expand All @@ -65,13 +80,17 @@ jobs:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: sudo apt update && sudo apt install --yes tox libev-dev libvirt-dev
- name: Install requirements
run: sudo apt update && sudo apt install --yes libev-dev
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install tox-uv
run: uv tool install tox --with tox-uv
- name: Coverage
run: |
tox -e begin,${{ matrix.python-version }},end
11 changes: 4 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ __pycache__/

# IDE
.idea/
.vscode
.vscode/

# Distribution / packaging
.Python
build/
output/
develop-eggs/
dist/
deps/
docker/common/bin
downloads/
eggs/
Expand All @@ -37,7 +35,6 @@ MANIFEST
AUTHORS
ChangeLog
cover/
version.txt

# OS
.DS_Store
Expand Down Expand Up @@ -108,6 +105,7 @@ venv/
ENV/
env.bak/
venv.bak/
*.conf

# Spyder project settings
.spyderproject
Expand All @@ -129,6 +127,5 @@ docs/source/*.png
# Vagrant
.vagrant/

# Configs
etc/genesis_notification/genesis_notification.d/*.conf

# GC build
output/
10 changes: 4 additions & 6 deletions genesis/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set -o pipefail
GC_PATH="/opt/genesis_notification"
GC_CFG_DIR=/etc/genesis_notification
VENV_PATH="$GC_PATH/.venv"
BOOTSTRAP_PATH="/var/lib/genesis/bootstrap/scripts"

GC_PG_USER="genesis_notification"
GC_PG_PASS="pass"
Expand All @@ -38,6 +37,8 @@ sudo apt dist-upgrade -y
sudo apt install -y \
postgresql \
libev-dev
curl -LsSf https://releases.astral.sh/github/uv/releases/download/0.10.12/uv-installer.sh | sh
source "$HOME"/.local/bin/env

# Default creds for genesis notification services
sudo -u postgres psql -c "CREATE ROLE $GC_PG_USER WITH LOGIN PASSWORD '$GC_PG_PASS';"
Expand All @@ -48,12 +49,9 @@ sudo mkdir -p $GC_CFG_DIR
sudo cp "$GC_PATH/etc/genesis_notification/genesis_notification.conf" $GC_CFG_DIR/
sudo cp "$GC_PATH/etc/genesis_notification/logging.yaml" $GC_CFG_DIR/

mkdir -p "$VENV_PATH"
python3 -m venv "$VENV_PATH"
cd "$GC_PATH"
uv sync
source "$GC_PATH"/.venv/bin/activate
pip install pip --upgrade
pip install -r "$GC_PATH"/requirements.txt
pip install -e "$GC_PATH"

# Apply migrations
ra-apply-migration --config-dir "$GC_PATH/etc/genesis_notification/" --path "$GC_PATH/migrations"
Expand Down
1 change: 0 additions & 1 deletion genesis_notification/clients/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


class IAMClient(common.RESTClientMixIn):

USER_PATH = "iam/users"

def __init__(self, endpoint, token, timeout=5):
Expand Down
4 changes: 1 addition & 3 deletions genesis_notification/cmd/user_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def main():
)

service.add_setup(
lambda: engines.engine_factory.configure_postgresql_factory(
conf=CONF
)
lambda: engines.engine_factory.configure_postgresql_factory(conf=CONF)
)

service_hub.add_service(service)
Expand Down
19 changes: 4 additions & 15 deletions genesis_notification/dm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def calulator():


class ModelWithAlwaysActiveStatus(models.Model):

STATUS = c.AlwaysActiveStatus

status = properties.property(
Expand Down Expand Up @@ -195,7 +194,6 @@ class EventType(


class AbstractContent(types_dynamic.AbstractKindModel):

def get_id(self):
return "%s" % self.__class__.__name__.lower()

Expand All @@ -219,9 +217,7 @@ class EmailContent(RenderedEmailContent):
def render(self, params):
return RenderedEmailContent(
title=jinja2.Template(self.title).render(**params),
bodies=[
jinja2.Template(body).render(**params) for body in self.bodies
],
bodies=[jinja2.Template(body).render(**params) for body in self.bodies],
)


Expand Down Expand Up @@ -270,9 +266,7 @@ class RenderedDirectMessageContent(AbstractContent):
KIND = "rendered_zulip_direct_message"

to = properties.property(
types.TypedList(
nested_type=types.String(min_length=1, max_length=256)
),
types.TypedList(nested_type=types.String(min_length=1, max_length=256)),
required=True,
)
content = properties.property(
Expand All @@ -297,9 +291,7 @@ def render(self, params):
return RenderedDirectMessageContent(
to=[
user.strip()
for user in jinja2.Template(self.to)
.render(**params)
.split(",")
for user in jinja2.Template(self.to).render(**params).split(",")
],
content=jinja2.Template(self.content).render(**params),
)
Expand Down Expand Up @@ -404,7 +396,6 @@ class Binding(


class StatusMixin(models.Model):

next_retry_delta = 60 # 60 sec
last_retry_delta = 1 * 24 * 60 * 60 # 1 day

Expand Down Expand Up @@ -433,9 +424,7 @@ class StatusMixin(models.Model):

def reset_next_retry(self):
now = datetime.datetime.now(datetime.timezone.utc)
self.next_retry_at = now + datetime.timedelta(
seconds=self.next_retry_delta
)
self.next_retry_at = now + datetime.timedelta(seconds=self.next_retry_delta)

def set_error_status(self, error_message):
self.status_description = str(error_message)
Expand Down
1 change: 0 additions & 1 deletion genesis_notification/services/builders/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


class EventBuilderAgent(basic.BasicService):

def __init__(self, iam_client, butch_size=100, **kwargs):
self._iam_client = iam_client
self._butch_size = butch_size
Expand Down
1 change: 0 additions & 1 deletion genesis_notification/services/providers/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


class SMTPAgent(basic.BasicService):

def __init__(self, butch_size=100, iter_min_period=5, **kwargs):
self._butch_size = butch_size
super().__init__(iter_min_period=iter_min_period, **kwargs)
Expand Down
6 changes: 2 additions & 4 deletions genesis_notification/user_api/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ def get_openapi_engine():
openapi_engine = openapi_engines.OpenApiEngine(
info=openapi_structures.OpenApiInfo(
title=f"Genesis Notification {versions.API_VERSION_1_0} User API",
version=app_version.version_info.release_string(),
description=(
f"OpenAPI - Genesis Notification {versions.API_VERSION_1_0}"
),
version=app_version.version_info,
description=(f"OpenAPI - Genesis Notification {versions.API_VERSION_1_0}"),
),
paths=openapi_structures.OpenApiPaths(),
components=openapi_structures.OpenApiComponents(),
Expand Down
4 changes: 1 addition & 3 deletions genesis_notification/user_api/api/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,4 @@ class EventTypeController(ra_controllers.BaseResourceController):


class EventController(ra_controllers.BaseResourceController):
__resource__ = resources.ResourceByRAModel(
models.Event, convert_underscore=False
)
__resource__ = resources.ResourceByRAModel(models.Event, convert_underscore=False)
Loading
Loading