Skip to content

Commit

Permalink
reuse github actions from superdesk repo (#158)
Browse files Browse the repository at this point in the history
- use black for formatting
- fix mypy errors
  • Loading branch information
petrjasek authored Jan 2, 2025
1 parent e8b9b1a commit fbb1f67
Show file tree
Hide file tree
Showing 20 changed files with 812 additions and 580 deletions.
95 changes: 24 additions & 71 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,32 @@
name: "CI"

on:
[push, pull_request]
on: [push, pull_request]

jobs:

server:
runs-on: ubuntu-latest

services:
redis:
image: redis:alpine
ports:
- "6379:6379"

mongo:
image: mongo:4
ports:
- "27017:27017"

elastic:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.23
ports:
- "9200:9200"
env:
discovery.type: single-node

defaults:
run:
working-directory: server

steps:
- uses: actions/checkout@v4

- name: setup python
uses: actions/setup-python@v4
with:
python-version: '3.8'

- name: apt-get
run: |
sudo apt-get update
sudo apt-get -y install libxml2-dev libxmlsec1-dev libxmlsec1-openssl libexempi-dev
- name: pip install
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install -r dev-requirements.txt
- run: flake8

- run: pytest tests

- run: behave --format progress2 --logging-level=ERROR

- run: python manage.py app:initialize_data
strategy:
matrix:
python-version: ['3.10']
uses: superdesk/superdesk/.github/workflows/server.yml@develop
with:
python-version: ${{ matrix.python-version }}

pytest:
strategy:
matrix:
python-version: ['3.10']
uses: superdesk/superdesk/.github/workflows/pytest.yml@develop
with:
python-version: ${{ matrix.python-version }}

behave:
strategy:
matrix:
python-version: ['3.10']
uses: superdesk/superdesk/.github/workflows/behave.yml@develop
with:
python-version: ${{ matrix.python-version }}

client:
runs-on: ubuntu-latest

defaults:
run:
working-directory: client

steps:
- uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version: 14.x

- run: git config --global url."https://git@".insteadOf git://
- name: npm ci
run: npm install --no-audit

- name: grunt build
run: npm run build
uses: superdesk/superdesk/.github/workflows/client.yml@develop
15 changes: 9 additions & 6 deletions server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
from superdesk.factory import get_app as superdesk_app


if os.environ.get('NEW_RELIC_LICENSE_KEY'):
if os.environ.get("NEW_RELIC_LICENSE_KEY"):
try:
import newrelic.agent
newrelic.agent.initialize(os.path.abspath(os.path.join(os.path.dirname(__file__), 'newrelic.ini')))

newrelic.agent.initialize(
os.path.abspath(os.path.join(os.path.dirname(__file__), "newrelic.ini"))
)
except ImportError:
pass

Expand All @@ -32,7 +35,7 @@ def get_app(config=None):
if config is None:
config = {}

config['APP_ABSPATH'] = os.path.abspath(os.path.dirname(__file__))
config["APP_ABSPATH"] = os.path.abspath(os.path.dirname(__file__))

for key in dir(settings):
if key.isupper():
Expand All @@ -42,9 +45,9 @@ def get_app(config=None):
return app


if __name__ == '__main__':
if __name__ == "__main__":
debug = True
host = '0.0.0.0'
port = int(os.environ.get('PORT', '5000'))
host = "0.0.0.0"
port = int(os.environ.get("PORT", "5000"))
app = get_app()
app.run(host=host, port=port, debug=debug, use_reloader=debug)
22 changes: 0 additions & 22 deletions server/data_updates/00002_20160803-171643_validators.py

This file was deleted.

24 changes: 0 additions & 24 deletions server/data_updates/00003_20160829-094134_validators.py

This file was deleted.

16 changes: 10 additions & 6 deletions server/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
-r requirements.txt

flake8
pep8
httmock
wooper
pytest
responses
black==24.10.0
mypy==1.14.1
flake8==7.1.1
pep8==1.7.1
httmock==1.4.0
wooper==0.4.4
pytest==8.3.4
responses==0.25.3

types-pytz
30 changes: 20 additions & 10 deletions server/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from os import path

from superdesk import get_resource_service, etree
from superdesk.tests.environment import before_feature, before_step, after_scenario # noqa
from superdesk.tests.environment import ( # noqa: F401
before_feature,
before_step,
after_scenario,
)
from superdesk.tests.environment import setup_before_all, setup_before_scenario
from superdesk.io.commands.update_ingest import ingest_items
from superdesk.io.feeding_services.file_service import FileFeedingService
Expand All @@ -24,31 +28,35 @@

def before_all(context):
config = {
'INSTALLED_APPS': INSTALLED_APPS,
'ELASTICSEARCH_FORCE_REFRESH': True,
"INSTALLED_APPS": INSTALLED_APPS,
"ELASTICSEARCH_FORCE_REFRESH": True,
}
setup_before_all(context, config, app_factory=get_app)


def before_scenario(context, scenario):
config = {
'INSTALLED_APPS': INSTALLED_APPS,
'ELASTICSEARCH_FORCE_REFRESH': True,
"INSTALLED_APPS": INSTALLED_APPS,
"ELASTICSEARCH_FORCE_REFRESH": True,
}
setup_before_scenario(context, scenario, config, app_factory=get_app)

if 'stt_providers' in scenario.tags:
if "stt_providers" in scenario.tags:
setup_stt_providers(context)

if 'stt_cvs' in scenario.tags:
if "stt_cvs" in scenario.tags:
with context.app.app_context():
cmd = AppPopulateCommand()
filename = path.join(path.abspath(path.dirname("data/")), "vocabularies.json")
filename = path.join(
path.abspath(path.dirname("data/")), "vocabularies.json"
)
cmd.run(filename)


def _construct_file_ingest_provider(name: str, parser: str) -> Dict[str, Any]:
path_to_fixtures = path.join(path.abspath(path.dirname(__file__)), "../tests/fixtures")
path_to_fixtures = path.join(
path.abspath(path.dirname(__file__)), "../tests/fixtures"
)

return {
"name": name,
Expand All @@ -62,7 +70,9 @@ def _construct_file_ingest_provider(name: str, parser: str) -> Dict[str, Any]:


def mock_fetch_ingest(self: FileFeedingService, guid: str):
path_to_fixtures = path.join(path.abspath(path.dirname(__file__)), "../tests/fixtures")
path_to_fixtures = path.join(
path.abspath(path.dirname(__file__)), "../tests/fixtures"
)
file_path = path.join(path_to_fixtures, guid)
feeding_parser = self.get_feed_parser(self.provider)

Expand Down
13 changes: 6 additions & 7 deletions server/gunicorn_config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@

import os
import multiprocessing

bind = '0.0.0.0:%s' % os.environ.get('PORT', '5000')
workers = int(os.environ.get('WEB_CONCURRENCY', multiprocessing.cpu_count() + 1))
bind = "0.0.0.0:%s" % os.environ.get("PORT", "5000")
workers = int(os.environ.get("WEB_CONCURRENCY", multiprocessing.cpu_count() + 1))

accesslog = '-'
access_log_format = '%(m)s %(U)s status=%(s)s time=%(T)ss size=%(B)sb'
accesslog = "-"
access_log_format = "%(m)s %(U)s status=%(s)s time=%(T)ss size=%(B)sb"

reload = 'SUPERDESK_RELOAD' in os.environ
reload = "SUPERDESK_RELOAD" in os.environ

timeout = int(os.environ.get('WEB_TIMEOUT', 30))
timeout = int(os.environ.get("WEB_TIMEOUT", 30))
2 changes: 1 addition & 1 deletion server/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
app = get_app()
manager = Manager(app)

if __name__ == '__main__':
if __name__ == "__main__":
manager.run(superdesk.COMMANDS)
Loading

0 comments on commit fbb1f67

Please sign in to comment.