-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from baobabsoluciones/development
Feature/package (#371)
- Loading branch information
Showing
50 changed files
with
1,169 additions
and
399 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,60 @@ | ||
name: Publish cornflow Python 🐍 distributions 📦 to PyPI | ||
|
||
on: | ||
push: | ||
tags: | ||
- "cornflow*" | ||
|
||
jobs: | ||
build-n-publish: | ||
name: Build and publish cornflow Python 🐍 distributions 📦 to PyPI | ||
defaults: | ||
run: | ||
working-directory: ./cornflow-server | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
- name: Install wheel | ||
run: >- | ||
python -m | ||
pip install | ||
wheel | ||
--user | ||
- name: Build a binary wheel and a source tarball | ||
run: python setup.py sdist bdist_wheel | ||
- name: Publish distribution 📦 to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
password: ${{ secrets.CORNFLOW_TEST_PYPI_TOKEN }} | ||
repository_url: https://test.pypi.org/legacy/ | ||
packages_dir: cornflow-server/dist/ | ||
- name: Publish distribution 📦 to PyPI | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
password: ${{ secrets.CORNFLOW_PYPI_TOKEN }} | ||
packages_dir: cornflow-server/dist/ | ||
- name: Get version number | ||
uses: jungwinter/split@v2 | ||
id: split | ||
with: | ||
msg : ${{ github.ref_name}} | ||
separator: "w" | ||
- name: Notify slack channel | ||
uses: slackapi/[email protected] | ||
with: | ||
slack-message: "A new version of cornflow (v${{ steps.split.outputs._1 }}) has been deployed" | ||
channel-id: ${{ secrets.SLACK_CHANNEL }} | ||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }} | ||
- name: Tag published version for docker hub trigger | ||
run: | | ||
git tag -a v${{ steps.split.outputs_1}} -m "Published cornflow version v${{ steps.split.outputs._1 }}" | ||
git push origin v${{ steps.split.outputs_1}} | ||
- name: Delete tag to launch release | ||
run: git push --delete origin ${{ github.ref_name }} | ||
|
||
|
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 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,6 @@ | ||
include LICENSE | ||
include MANIFEST.in | ||
include README.rst | ||
include setup.py | ||
include cornflow/migrations/* | ||
include cornflow/migrations/versions/* |
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 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 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,28 @@ | ||
""" | ||
init file to have this as a module | ||
""" | ||
|
||
import click | ||
from cornflow.cli.actions import actions | ||
from cornflow.cli.config import config | ||
from cornflow.cli.migrations import migrations | ||
from cornflow.cli.permissions import permissions | ||
from cornflow.cli.roles import roles | ||
from cornflow.cli.service import service | ||
from cornflow.cli.users import users | ||
from cornflow.cli.views import views | ||
|
||
|
||
@click.group(name="cornflow", help="Commands in the cornflow cli") | ||
def cli(): | ||
pass | ||
|
||
|
||
cli.add_command(actions) | ||
cli.add_command(config) | ||
cli.add_command(migrations) | ||
cli.add_command(permissions) | ||
cli.add_command(roles) | ||
cli.add_command(service) | ||
cli.add_command(users) | ||
cli.add_command(views) |
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,19 @@ | ||
import os | ||
|
||
import click | ||
from cornflow.cli.utils import get_app | ||
from cornflow.commands import register_actions_command | ||
from .arguments import verbose | ||
|
||
|
||
@click.group(name="actions", help="Commands to manage the actions") | ||
def actions(): | ||
pass | ||
|
||
|
||
@actions.command(name="init", help="Initialize the actions") | ||
@verbose | ||
def init(verbose): | ||
app = get_app() | ||
with app.app_context(): | ||
register_actions_command(verbose) |
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,24 @@ | ||
import click | ||
|
||
verbose = click.option("-v", "--verbose", is_flag=True, default=False) | ||
app_name = click.option( | ||
"-a", | ||
"--app_name", | ||
required=False, | ||
type=str, | ||
default="external_app", | ||
help="The name of the external app", | ||
) | ||
|
||
username = click.option( | ||
"-u", "--username", required=True, type=str, help="The username of the user" | ||
) | ||
password = click.option( | ||
"-p", "--password", required=True, type=str, help="The password of the user" | ||
) | ||
email = click.option( | ||
"-e", "--email", required=True, type=str, help="The email of the user" | ||
) | ||
path = click.option( | ||
"-p", "--path", type=str, help="The path to the file to save the file" | ||
) |
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,42 @@ | ||
import click | ||
|
||
from cornflow.cli.utils import get_app | ||
from flask import current_app | ||
from .arguments import path | ||
|
||
|
||
@click.group(name="config", help="Commands to manage the configuration variables") | ||
def config(): | ||
pass | ||
|
||
|
||
@config.command(name="list", help="List the configuration variables") | ||
def config_list(): | ||
app = get_app() | ||
with app.app_context(): | ||
for key, value in current_app.config.items(): | ||
click.echo(f"{key} = {value}") | ||
|
||
return 1 | ||
|
||
|
||
@config.command(name="save", help="Save the configuration variables to a file") | ||
@path | ||
def config_save(path): | ||
app = get_app() | ||
path = f"{path}config.cfg" | ||
with app.app_context(): | ||
with open(path, "w") as f: | ||
f.write("[configuration]\n\n") | ||
for key, value in current_app.config.items(): | ||
f.write(f"{key} = {value}\n") | ||
|
||
return 1 | ||
|
||
|
||
@config.command(name="get", help="Get the value of a configuration variable") | ||
@click.option("--key", "-k", type=str, help="The key of the configuration variable") | ||
def config_get(key): | ||
app = get_app() | ||
with app.app_context(): | ||
click.echo(f"{current_app.config.get(key, None)}") |
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,58 @@ | ||
import os.path | ||
|
||
|
||
import click | ||
from cornflow_core.shared import db | ||
from flask_migrate import Migrate, migrate, upgrade, init | ||
|
||
from .utils import get_app | ||
|
||
|
||
@click.group(name="migrations", help="Commands to manage the migrations") | ||
def migrations(): | ||
pass | ||
|
||
|
||
@migrations.command(name="migrate", help="Calculate the migrations") | ||
def migrate_migrations(): | ||
app = get_app() | ||
external = int(os.getenv("EXTERNAL_APP", 0)) | ||
if external == 0: | ||
path = "./cornflow/migrations" | ||
else: | ||
path = f"./{os.getenv('EXTERNAL_APP_MODULE', 'external_app')}/migrations" | ||
|
||
with app.app_context(): | ||
migration_client = Migrate(app=app, db=db, directory=path) | ||
migrate() | ||
|
||
|
||
@migrations.command(name="upgrade", help="Apply migrations") | ||
def upgrade_migrations(): | ||
app = get_app() | ||
external = int(os.getenv("EXTERNAL_APP", 0)) | ||
if external == 0: | ||
path = "./cornflow/migrations" | ||
else: | ||
path = f"./{os.getenv('EXTERNAL_APP_MODULE', 'external_app')}/migrations" | ||
|
||
with app.app_context(): | ||
migration_client = Migrate(app=app, db=db, directory=path) | ||
upgrade() | ||
|
||
|
||
@migrations.command( | ||
name="init", | ||
help="Initialize the migrations for an external app. Creates the folder and copies the migrations from cornflow", | ||
) | ||
def init_migrations(): | ||
app = get_app() | ||
external = int(os.getenv("EXTERNAL_APP", 0)) | ||
if external == 0: | ||
path = "./cornflow/migrations" | ||
else: | ||
path = f"./{os.getenv('EXTERNAL_APP_MODULE', 'external_app')}/migrations" | ||
|
||
with app.app_context(): | ||
migration_client = Migrate(app=app, db=db, directory=path) | ||
init() |
Oops, something went wrong.