Skip to content

Commit

Permalink
Switch from Travis to GitHub Actions (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksanders authored Sep 13, 2024
1 parent 190f856 commit 191adf3
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 275 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
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
76 changes: 76 additions & 0 deletions .github/workflows/release.yml
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/
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
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 \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Aardvark
Aardvark - Multi-Account AWS IAM Access Advisor API
========
[![NetflixOSS Lifecycle](https://img.shields.io/osslifecycle/Netflix/osstracker.svg)]()
[![Discord chat](https://img.shields.io/discord/754080763070382130?logo=discord)](https://discord.gg/9kwMWa6)
Expand Down
16 changes: 0 additions & 16 deletions aardvark/__about__.py

This file was deleted.

84 changes: 0 additions & 84 deletions aardvark/__init__.py
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)
81 changes: 81 additions & 0 deletions aardvark/app.py
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)
Loading

0 comments on commit 191adf3

Please sign in to comment.