Skip to content

Commit d3a2c29

Browse files
vojchrisbc
andauthored
merge Deploy test into main (#37)
* update black; * add about + versino resolvers; tweak flake8 settings * add GHA scripts; * setup poretry group `dev` & remove extras; * added model & node resolvers; * new SLT models * add tag attribute on SourceLogicTreeBranch; * add branch_set_short_name * add relay node resolvers for all model classes; * refactor slt schemas into module; more coverage for as_node tests; * add BranchInversionSource class * configure api and wsgi entry point * add inversion_id property * add lru_cache to improve API performance * add BranchDistributedSource; remove Node suppurt from source classes; no coverage on main aspi module; * added current_model_version resolver; get_model resolver support default to CURRENTA_MODEL as per underlying LIB; * reorg tests; kill commented code blocks; detox; * revert to secrets for GHA; * change temp api key name; * fix serverless deployment config; * use dockerizePip to ensure AWS linuxB compatability (ref GLIBC 2.28 not found error); * update from flask-graphql to graphql-server; version updates; * serverless version updates; * added fix/test for missing model title; * new gmm classes & tests; WIP util LIB is updated; * update nzshm-model; use branch_set short_name for GMM node identity resolvers;update tests; * fix branch_set_short_name attrinute and tests * [29] use reusable workflow for testing (#31) * [33] scheduled build (#35) * Bump version: 0.2.0 → 0.3.0 --------- Co-authored-by: Chris Chamberlain <[email protected]>
1 parent 2fcc08e commit d3a2c29

27 files changed

+3584
-728
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.2.0
2+
current_version = 0.3.0
33
commit = True
44
tag = False
55

.github/ISSUE_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
* kororaa-graphql-api version:
2+
* Python version:
3+
* Operating System:
4+
5+
### Description
6+
7+
Describe what you were trying to get done.
8+
Tell us what happened, what went wrong, and what you expected to happen.
9+
10+
### What I Did
11+
12+
```
13+
Paste the command(s) you ran and the output.
14+
If there was a crash, please include the traceback here.
15+
```

.github/workflows/deploy-to-aws.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: deploy-aws-lambda
2+
3+
on:
4+
push:
5+
branches:
6+
- deploy-test
7+
- main
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
call-test-workflow:
14+
uses: GNS-Science/nshm-github-actions/.github/workflows/python-run-tests.yml@main
15+
with:
16+
operating-systems: "['ubuntu-latest']"
17+
python-versions: "['3.10']"
18+
secrets: inherit
19+
20+
deploy:
21+
needs: call-test-workflow
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
node-version: [20]
26+
python-version: ['3.10']
27+
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: actions/setup-python@v4
31+
with:
32+
python-version: ${{ matrix.python-version }}
33+
34+
- name: Install and configure Poetry
35+
uses: GNS-Science/install-poetry@main
36+
with:
37+
virtualenvs-create: true
38+
virtualenvs-in-project: true
39+
installer-parallel: true
40+
41+
- name: Use Node.js ${{ matrix.node-version }}
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: ${{ matrix.node-version }}
45+
check-latest: true
46+
47+
- name: upgrade NPM
48+
run: npm install --location=global npm@latest
49+
50+
# - name: Verify NPM
51+
# run: npm doctor
52+
53+
- name: Install Dependencies
54+
run: npm install
55+
56+
- name: List packages
57+
run: npm ls
58+
59+
- name: Serverless Doctor
60+
run: npm run-script sls_doctor
61+
62+
- name: Configure AWS Credentials
63+
uses: aws-actions/configure-aws-credentials@v4
64+
with:
65+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
66+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
67+
aws-region: ap-southeast-2
68+
69+
- name: Serverless Deploy ....
70+
env:
71+
ENABLE_METRICS: 0
72+
run: |
73+
poetry self add poetry-plugin-export
74+
if [[ "${{github.base_ref}}" == "main" || "${{github.ref}}" == 'refs/heads/main' ]]; then
75+
STAGE=prod npm run-script deploy
76+
else
77+
STAGE=test npm run-script deploy
78+
fi
79+

.github/workflows/dev.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Dev workflow
2+
3+
on:
4+
schedule:
5+
- cron: '25 5 * * 0' # At 05:25 on Sunday
6+
pull_request:
7+
branches: [main, deploy-test]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
call-test-workflow:
14+
uses: GNS-Science/nshm-github-actions/.github/workflows/python-run-tests.yml@main
15+
with:
16+
operating-systems: "['ubuntu-latest']"
17+
python-versions: "['3.10']"
18+
delete-poetry-lock: ${{ github.event_name == 'schedule' }} # the scheduled build tests against newer dependencies
19+
secrets: inherit

.github/workflows/release.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Publish package on main branch if it's tagged with 'v*'
2+
3+
name: release & publish workflow
4+
5+
# Controls when the action will run.
6+
on:
7+
# Triggers the workflow on push events but only for the master branch
8+
push:
9+
tags:
10+
- 'v*'
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
16+
jobs:
17+
# This workflow contains a single job called "release"
18+
release:
19+
name: Create Release
20+
runs-on: ubuntu-20.04
21+
22+
strategy:
23+
matrix:
24+
python-versions: [3.8]
25+
26+
# Steps represent a sequence of tasks that will be executed as part of the job
27+
steps:
28+
- name: Get version from tag
29+
id: tag_name
30+
run: |
31+
echo ::set-output name=current_version::${GITHUB_REF#refs/tags/v}
32+
shell: bash
33+
34+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
35+
- uses: actions/checkout@v2
36+
37+
- name: Get Changelog Entry
38+
id: changelog_reader
39+
uses: mindsers/changelog-reader-action@v2
40+
with:
41+
validation_depth: 10
42+
version: ${{ steps.tag_name.outputs.current_version }}
43+
path: ./CHANGELOG.md
44+
45+
- uses: actions/setup-python@v2
46+
with:
47+
python-version: ${{ matrix.python-versions }}
48+
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
pip install poetry
53+
54+
- name: build documentation
55+
run: |
56+
poetry install -E doc
57+
poetry run mkdocs build
58+
59+
- name: publish documentation
60+
uses: peaceiris/actions-gh-pages@v3
61+
with:
62+
github_token: ${{ secrets.GITHUB_TOKEN }}
63+
publish_dir: ./site
64+
65+
# - name: Build wheels and source tarball
66+
# run: >-
67+
# poetry build
68+
69+
# - name: show temporary files
70+
# run: >-
71+
# ls -l
72+
73+
# - name: create github release
74+
# id: create_release
75+
# uses: softprops/action-gh-release@v1
76+
# env:
77+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
# with:
79+
# body: ${{ steps.changelog_reader.outputs.changes }}
80+
# files: dist/*.whl
81+
# draft: false
82+
# prerelease: false
83+
84+
# - name: publish to PyPI
85+
# uses: pypa/gh-action-pypi-publish@release/v1
86+
# with:
87+
# user: __token__
88+
# password: ${{ secrets.PYPI_API_TOKEN }}
89+
# skip_existing: true

CHANGELOG.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
# Changelog
22

3+
## [0.3.0] - 2025-07-29
34

4-
## [0.2.0] 2024-05-30
5+
### Changed
6+
- flake8 config
7+
- new about and version resolvers
8+
9+
### Added
10+
- Node resolver support for NshmModel
11+
- get_model resolver
12+
- get_models resolver
13+
- source logic tree models and resolvers
14+
- gmmm logic tree models and resolvers
15+
16+
## [0.2.0] - 2024-06-07
17+
### Changed
518
- Complete reset, no more django
619
- all previous code is mothballed
720

821
## [0.1.3] - 2023-09-04
9-
## Added
22+
### Added
1023
- new about and version resolvers
1124

1225
## [0.1.2] - 2023-09-04
13-
## Changed
26+
### Changed
1427
- configure static_url correctly for both local & AWS
1528

1629
## [0.1.1] - 2023-09-01

nshm_model_graphql_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """GNS Science"""
44
__email__ = "[email protected]"
5-
__version__ = "0.2.0"
5+
__version__ = "0.3.0"
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""Main module."""
2+
3+
import logging
4+
import logging.config
5+
import os
6+
7+
import yaml
8+
from flask import Flask
9+
from flask_cors import CORS
10+
from graphql_server.flask import GraphQLView
11+
12+
# from nshm_model_graphql_api.library_version_check import log_library_info
13+
from nshm_model_graphql_api.schema import schema_root
14+
15+
LOGGING_CFG = os.getenv("LOGGING_CFG", "nshm_model_graphql_api/logging_aws.yaml")
16+
logger = logging.getLogger(__name__)
17+
18+
# TESTING = os.getenv('TESTING', False)
19+
# if not TESTING:
20+
# # because in testing, this screws up moto mocking
21+
# log_library_info(['botocore', 'boto3', 'fiona'])
22+
23+
24+
def create_app():
25+
"""Function that creates our Flask application."""
26+
app = Flask(__name__)
27+
CORS(app)
28+
29+
# app.before_first_request(migrate)
30+
31+
app.add_url_rule(
32+
"/graphql",
33+
view_func=GraphQLView.as_view(
34+
"graphql",
35+
schema=schema_root,
36+
graphiql=True,
37+
),
38+
)
39+
40+
"""
41+
Setup logging configuration
42+
ref https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
43+
"""
44+
if os.path.exists(LOGGING_CFG):
45+
with open(LOGGING_CFG, "rt") as f:
46+
config = yaml.safe_load(f.read())
47+
logging.config.dictConfig(config)
48+
else:
49+
print("Warning, no logging config found, using basicConfig(INFO)")
50+
logging.basicConfig(level=logging.INFO)
51+
52+
logger.debug("DEBUG logging enabled")
53+
logger.info("INFO logging enabled")
54+
logger.warning("WARN logging enabled")
55+
logger.error("ERROR logging enabled")
56+
57+
return app
58+
59+
60+
# pragma: no cover
61+
app = create_app()
62+
63+
64+
if __name__ == "__main__":
65+
app.run()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""API schema package."""
2+
3+
from .schema_root import schema_root # noqa: F401

0 commit comments

Comments
 (0)