Skip to content

Commit

Permalink
Merge pull request #525 from populationgenomics/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
vivbak authored Jul 20, 2023
2 parents 942e53b + acf88b6 commit f77c075
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 6.1.0
current_version = 6.2.0
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>[A-z0-9-]+)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
SM_API_DOCKER: australia-southeast1-docker.pkg.dev/cpg-common/images/sm-api
defaults:
run:
shell: bash -l {0}
shell: bash -eo pipefail -l {0}
steps:
- uses: actions/checkout@main

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
shell: bash -eo pipefail -l {0}

steps:
- uses: actions/checkout@v2
Expand All @@ -19,7 +19,6 @@ jobs:
- name: Install packages
run: |
pip install -r requirements-dev.txt
pip install -r requirements-server.txt
pip install .
- name: pre-commit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
SM_DOCKER: samplemetadata:dev
defaults:
run:
shell: bash -l {0}
shell: bash -eo pipefail -l {0}
steps:
- uses: actions/checkout@main

Expand Down
6 changes: 6 additions & 0 deletions api/routes/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def _create_route(e: Type[EnumTable]):
async def get(connection=get_projectless_db_connection) -> list[str]:
return await e(connection).get()

@router.post('/' + hyphenated_name, operation_id='post' + camel_case_name + 's')
async def post(
new_type: str, connection=get_projectless_db_connection
) -> list[str]:
return await e(connection).insert(new_type)


for enum in enum_tables.__dict__.values():
if not isclass(enum):
Expand Down
2 changes: 1 addition & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from api.settings import PROFILE_REQUESTS, SKIP_DATABASE_CONNECTION

# This tag is automatically updated by bump2version
_VERSION = '6.1.0'
_VERSION = '6.2.0'

logger = get_logger()

Expand Down
1 change: 1 addition & 0 deletions db/python/enum_tables/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ async def insert(self, value: str):
await self.connection.execute(_query, {'name': value.lower()})
# clear the cache so results are up-to-date
self.get.cache_clear() # pylint: disable=no-member
return value
2 changes: 1 addition & 1 deletion deploy/python/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.0
6.2.0
58 changes: 48 additions & 10 deletions regenerate_api.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env python3
# pylint: disable=logging-not-lazy,subprocess-popen-preexec-fn,consider-using-with
import logging
import re
from typing import Optional, List

import os
import re
import shutil
import signal
import subprocess
import tempfile
import shutil
import time
import subprocess
from typing import List, Optional

import requests

Expand All @@ -35,6 +34,15 @@ def check_if_server_is_accessible() -> bool:
return False


def assert_server_is_accessible():
"""Assert that the server is accessible"""
if not check_if_server_is_accessible():
raise requests.ConnectionError(
f'Could not connect to server at {SCHEMA_URL}. '
'Please make sure the server is running and accessible.'
)


def start_server() -> Optional[subprocess.Popen]:
"""Start the API server, and return a process when it's started"""

Expand Down Expand Up @@ -124,7 +132,9 @@ def check_openapi_version():
logger.info(f'Got openapi version: {version}')


def generate_api_and_copy(output_type, output_copyer, extra_commands: List[str] = None):
def generate_api_and_copy(
output_type, output_copyer, extra_commands: List[str] | None = None
):
"""
Use OpenApiGenerator to generate the installable API
"""
Expand Down Expand Up @@ -161,15 +171,17 @@ def generate_api_and_copy(output_type, output_copyer, extra_commands: List[str]
time.sleep(2)

if not succeeded:
return
raise RuntimeError(
f'openapi generation failed after trying {n_attempts} time(s)'
)

output_copyer(tmpdir)
shutil.rmtree(tmpdir)


def generate_schema_file():
"""
Generate schema file and place int he metamist/graphql/ directory
Generate schema file and place in the metamist/graphql/ directory
"""
command = ['strawberry', 'export-schema', 'api.graphql.schema:schema']
schema = subprocess.check_output(command, stderr=subprocess.STDOUT).decode()
Expand Down Expand Up @@ -299,21 +311,47 @@ def main():
else:
process = start_server()

# Loop until Docker has initialised server and is ready to accept connections
startup_tries = 5
wait_time_in_seconds = 2
while (not check_if_server_is_accessible()) and startup_tries > 0:
startup_tries -= 1
logger.info(
f'Dockerised API server is not ready yet. '
+ f'Retrying in {wait_time_in_seconds} seconds. '
+ f'Remaining tries: {startup_tries}'
)
time.sleep(wait_time_in_seconds)

try:
assert_server_is_accessible()
check_openapi_version()

# Generate the installable Python API
generate_api_and_copy(
'python',
copy_python_files_from,
['--template-dir', 'openapi-templates'],
)
generate_api_and_copy('typescript-axios', copy_typescript_files_from)

# Generate the Typescript API for React application
generate_api_and_copy(
'typescript-axios',
copy_typescript_files_from,
)

# Generate the GraphQL schema
generate_schema_file()

# Copy resources and README
shutil.copy(
'./resources/muck-the-duck.svg',
os.path.join('web/src', 'muck-the-duck.svg'),
)
shutil.copy('README.md', os.path.join(OUTPUT_DOCS_DIR, 'index.md'))
shutil.copy(
'README.md',
os.path.join(OUTPUT_DOCS_DIR, 'index.md'),
)

# pylint: disable=broad-except
except BaseException as e:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
setup(
name=PKG,
# This tag is automatically updated by bump2version
version='6.1.0',
version='6.2.0',
description='Python API for interacting with the Sample API system',
long_description=readme,
long_description_content_type='text/markdown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const PAGE_SIZES = [20, 40, 100, 1000]
const GET_ANALYSIS_RUNNER_LOGS = gql(`
query AnalysisRunnerLogs($project_name: String!) {
project(name: $project_name) {
analyses(type: { eq: "analysis-runner" }) {
analyses(type: { eq: "analysis-runner" }, status: {eq: UNKNOWN}) {
author
id
meta
Expand Down

0 comments on commit f77c075

Please sign in to comment.