Skip to content

Commit

Permalink
Merge pull request #8 from freezingsaddles/add-ci
Browse files Browse the repository at this point in the history
Add GitHub Actions CI
  • Loading branch information
obscurerichard authored Nov 20, 2024
2 parents 217bd04 + e039c4f commit b3c9d61
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 43 deletions.
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
# Thanks https://www.reddit.com/r/learnpython/comments/rr6y69/comment/hqeqt68/?utm_source=share&utm_medium=web2x&context=3
ignore = E203, W503, E501

max-line-length = 88
max-complexity = 39
extend-ignore = E203
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: 2
updates:
- package-ecosystem: "pip"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
38 changes: 38 additions & 0 deletions .github/workflows/build-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Build and Deploy Latest

on:
push:
branches:
- 'master'

jobs:

build:
uses: freezingsaddles/freezing-web/.github/workflows/[email protected]
concurrency: build-deploy-and-test
with:
tag: latest
repo: freezing-nq
secrets: inherit

deploy:
concurrency: build-deploy-and-test
needs: build
runs-on: ubuntu-latest
timeout-minutes: 5
steps:

- name: install
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
passphrase: ${{ secrets.PASSPHRASE }}
script: |
set -euo pipefail
cd /opt/compose
docker-compose pull freezing-nq
docker-compose up -d freezing-nq
15 changes: 15 additions & 0 deletions .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Build Tag

on:
push:
tags:
- '*'

jobs:
build:
uses: freezingsaddles/freezing-web/.github/workflows/[email protected]
with:
tag: ${{ github.ref_name }}
repo: freezing-nq
secrets: inherit
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Build

on: pull_request

jobs:
build:
uses: freezingsaddles/freezing-web/.github/workflows/[email protected]
with:
tag: latest-actions-build
repo: freezing-nq
secrets: inherit
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Lint

on: pull_request

jobs:

# Thanks https://black.readthedocs.io/en/stable/integrations/github_actions.html
lint:
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v4
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: black Lint
uses: psf/[email protected]
- name: isort Lint
uses: isort/isort-action@v1
with:
requirements-files: "requirements.txt requirements-test.txt"
- name: flake8 Lint
uses: py-actions/flake8@v2
# There are too many errors to start with to fail on this
continue-on-error: true
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.*
*.pyc
*.egg-info
/env
Expand Down
18 changes: 9 additions & 9 deletions freezing/nq/api/webhook.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import json
import falcon

from freezing.nq.autolog import log
from freezing.nq.config import config
from freezing.nq.publish import ActivityPublisher

import falcon
from freezing.model.msg.mq import ActivityUpdate, ActivityUpdateSchema, DefinedTubes
from freezing.model.msg.strava import (
ObjectType,
SubscriptionCallback,
SubscriptionCallbackSchema,
SubscriptionUpdate,
SubscriptionUpdateSchema,
SubscriptionCallbackSchema,
SubscriptionCallback,
ObjectType,
)
from freezing.model.msg.mq import DefinedTubes, ActivityUpdate, ActivityUpdateSchema

from freezing.nq.autolog import log
from freezing.nq.config import config
from freezing.nq.publish import ActivityPublisher


class WebhookResource:
Expand Down
2 changes: 1 addition & 1 deletion freezing/nq/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from freezing.nq.api.health import HealthResource
from freezing.nq.api.webhook import WebhookResource
from freezing.nq.publish import configured_publisher, ActivityPublisher
from freezing.nq.publish import ActivityPublisher, configured_publisher


class RequireJSON:
Expand Down
16 changes: 4 additions & 12 deletions freezing/nq/autolog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import
import sys
import logging

import inspect
import logging


class EagerFormattingAdapter(logging.LoggerAdapter):
Expand Down Expand Up @@ -64,16 +64,8 @@ def _getUnterpolatedMessage(self, msg, args):
# by casting the left side (the "msg" variable) in this context
# to unicode. So we'll do that here

if sys.version_info >= (
3,
0,
):
# this is most likely unnecessary on python 3, but it's here
# for completeness, in the case of someone manually creating
# a bytestring
unicode_type = str
else:
unicode_type = unicode
# This used to check for Python 2 vs 3, but Python 2 is dead, so:
unicode_type = str

# handle the attempt to print utf-8 encoded data, similar to
# %-interpolation's handling of unicode formatting non-ascii
Expand Down
3 changes: 2 additions & 1 deletion freezing/nq/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
import os

from envparse import env

envfile = os.environ.get("APP_SETTINGS", os.path.join(os.getcwd(), ".env"))
Expand Down
6 changes: 3 additions & 3 deletions freezing/nq/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import greenstalk
from freezing.model.msg.mq import DefinedTubes

from freezing.nq.config import config
from freezing.nq.autolog import log
from freezing.nq.config import config


class ActivityPublisher:
Expand Down Expand Up @@ -34,8 +34,8 @@ def publish_message(self, message: Any, dest: DefinedTubes):
queue = greenstalk.Client(host=self.host, port=self.port, use=dest.value)
try:
queue.put(self.serialize_message(message))
except:
log.exception("Error publishing message.")
except Exception as ex:
log.exception(f"Error publishing message: {ex}")
finally:
queue.close()

Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.isort]
profile = "black"
7 changes: 4 additions & 3 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
black==19.10b0
flake8==3.7.9
pur==5.3.0
black==24.3.0
flake8==7.0.0
isort==5.13.2
pur==7.3.1
pytest==3.3.2
pytest-mock==1.6.3
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ envparse==0.2.0
falcon==2.0.0
freezing-model @ https://github.com/freezingsaddles/freezing-model/archive/0.7.20.tar.gz
greenstalk==1.0.1
gunicorn==20.0.4
gunicorn==22.0.0
python-mimeparse==1.6.0
six==1.14.0
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"""

install_reqs = [
"envparse==0.2.0",
"falcon==2.0.0",
"greenstalk==1.0.1",
"gunicorn==20.0.4",
"python-mimeparse==1.6.0",
"six==1.14.0",
"envparse",
"falcon",
"greenstalk",
"gunicorn",
"python-mimeparse",
"six",
"freezing-model",
"arrow==0.15.5",
"arrow",
]

setup(
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json

from falcon import testing
import pytest
import pytest_mock
from falcon import testing

from freezing.nq.app import make_app
from freezing.nq.config import config
Expand Down
7 changes: 3 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import json
import copy
import json

import pytest
import arrow

import pytest
from freezing.model.msg.mq import ActivityUpdate, DefinedTubes
from freezing.model.msg.strava import AspectType

from freezing.nq.config import config
from freezing.nq.publish import ActivityPublisher
from freezing.model.msg.mq import DefinedTubes, ActivityUpdate


def test_get_webhook(client):
Expand Down

0 comments on commit b3c9d61

Please sign in to comment.