-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from Travis to GitHub Actions (#153)
- Loading branch information
1 parent
190f856
commit 191adf3
Showing
16 changed files
with
239 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Run tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install \ | ||
-r requirements.txt \ | ||
flake8 \ | ||
pytest \ | ||
. | ||
- name: Lint | ||
run: | | ||
flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test | ||
run: | | ||
pytest --capture=sys --ignore=test/test_docker.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
push: | ||
branches: | ||
- main # publish pre-release packages on every push to main | ||
|
||
jobs: | ||
package: | ||
name: Build package | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
fetch-tags: true | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.9" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install -U pip build | ||
python -m pip install -r requirements.txt . | ||
- name: Build dist | ||
run: | | ||
python -m build | ||
- name: Store the distribution packages | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
|
||
pypi-publish: | ||
name: Upload release to PyPI | ||
runs-on: ubuntu-latest | ||
needs: | ||
- package | ||
environment: | ||
name: release | ||
url: https://pypi.org/p/aardvark | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Download all the dists | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
- name: Publish package distributions to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
|
||
pypi-test-publish: | ||
name: Upload release to TestPyPI | ||
runs-on: ubuntu-latest | ||
needs: | ||
- package | ||
environment: | ||
name: release | ||
url: https://test.pypi.org/p/aardvark | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Download all the dists | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: python-package-distributions | ||
path: dist/ | ||
- name: Publish package distributions to TestPyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
repository-url: https://test.pypi.org/legacy/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3.7 | ||
FROM python:3.8 | ||
|
||
RUN apt-get update -y \ | ||
&& apt-get upgrade -y \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +0,0 @@ | ||
#ensure absolute import for python3 | ||
from __future__ import absolute_import | ||
|
||
import os.path | ||
import logging | ||
from logging import DEBUG, Formatter, StreamHandler | ||
from logging.config import dictConfig | ||
import sys | ||
|
||
from flask_sqlalchemy import SQLAlchemy | ||
from flask import Flask | ||
from flasgger import Swagger | ||
|
||
db = SQLAlchemy() | ||
|
||
from aardvark.view import mod as advisor_bp # noqa | ||
|
||
BLUEPRINTS = [ | ||
advisor_bp | ||
] | ||
|
||
API_VERSION = '1' | ||
|
||
|
||
def create_app(): | ||
app = Flask(__name__, static_url_path='/static') | ||
Swagger(app) | ||
|
||
path = _find_config() | ||
if not path: | ||
print('No config') | ||
app.config.from_pyfile('_config.py') | ||
else: | ||
app.config.from_pyfile(path) | ||
|
||
# For ELB and/or Eureka | ||
@app.route('/healthcheck') | ||
def healthcheck(): | ||
"""Healthcheck | ||
Simple healthcheck that indicates the services is up | ||
--- | ||
responses: | ||
200: | ||
description: service is up | ||
""" | ||
return 'ok' | ||
|
||
# Blueprints | ||
for bp in BLUEPRINTS: | ||
app.register_blueprint(bp, url_prefix="/api/{0}".format(API_VERSION)) | ||
|
||
# Extensions: | ||
db.init_app(app) | ||
setup_logging(app) | ||
|
||
return app | ||
|
||
|
||
def _find_config(): | ||
"""Search for config.py in order of preference and return path if it exists, else None""" | ||
CONFIG_PATHS = [os.path.join(os.getcwd(), 'config.py'), | ||
'/etc/aardvark/config.py', | ||
'/apps/aardvark/config.py'] | ||
for path in CONFIG_PATHS: | ||
if os.path.exists(path): | ||
return path | ||
return None | ||
|
||
|
||
def setup_logging(app): | ||
if not app.debug: | ||
if app.config.get('LOG_CFG'): | ||
# initialize the Flask logger (removes all handlers) | ||
app.logger | ||
dictConfig(app.config.get('LOG_CFG')) | ||
app.logger = logging.getLogger(__name__) | ||
else: | ||
handler = StreamHandler(stream=sys.stderr) | ||
|
||
handler.setFormatter(Formatter( | ||
'%(asctime)s %(levelname)s: %(message)s ' | ||
'[in %(pathname)s:%(lineno)d]')) | ||
app.logger.setLevel(app.config.get('LOG_LEVEL', DEBUG)) | ||
app.logger.addHandler(handler) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os.path | ||
import logging | ||
from logging import DEBUG, Formatter, StreamHandler | ||
from logging.config import dictConfig | ||
import sys | ||
|
||
from flask_sqlalchemy import SQLAlchemy | ||
from flask import Flask | ||
from flasgger import Swagger | ||
|
||
db = SQLAlchemy() | ||
|
||
from aardvark.view import mod as advisor_bp # noqa | ||
|
||
BLUEPRINTS = [ | ||
advisor_bp | ||
] | ||
|
||
API_VERSION = '1' | ||
|
||
|
||
def create_app(): | ||
app = Flask(__name__, static_url_path='/static') | ||
Swagger(app) | ||
|
||
path = _find_config() | ||
if not path: | ||
print('No config') | ||
app.config.from_pyfile('_config.py') | ||
else: | ||
app.config.from_pyfile(path) | ||
|
||
# For ELB and/or Eureka | ||
@app.route('/healthcheck') | ||
def healthcheck(): | ||
"""Healthcheck | ||
Simple healthcheck that indicates the services is up | ||
--- | ||
responses: | ||
200: | ||
description: service is up | ||
""" | ||
return 'ok' | ||
|
||
# Blueprints | ||
for bp in BLUEPRINTS: | ||
app.register_blueprint(bp, url_prefix="/api/{0}".format(API_VERSION)) | ||
|
||
# Extensions: | ||
db.init_app(app) | ||
setup_logging(app) | ||
|
||
return app | ||
|
||
|
||
def _find_config(): | ||
"""Search for config.py in order of preference and return path if it exists, else None""" | ||
CONFIG_PATHS = [os.path.join(os.getcwd(), 'config.py'), | ||
'/etc/aardvark/config.py', | ||
'/apps/aardvark/config.py'] | ||
for path in CONFIG_PATHS: | ||
if os.path.exists(path): | ||
return path | ||
return None | ||
|
||
|
||
def setup_logging(app): | ||
if not app.debug: | ||
if app.config.get('LOG_CFG'): | ||
# initialize the Flask logger (removes all handlers) | ||
app.logger | ||
dictConfig(app.config.get('LOG_CFG')) | ||
app.logger = logging.getLogger(__name__) | ||
else: | ||
handler = StreamHandler(stream=sys.stderr) | ||
|
||
handler.setFormatter(Formatter( | ||
'%(asctime)s %(levelname)s: %(message)s ' | ||
'[in %(pathname)s:%(lineno)d]')) | ||
app.logger.setLevel(app.config.get('LOG_LEVEL', DEBUG)) | ||
app.logger.addHandler(handler) |
Oops, something went wrong.