Skip to content

Commit

Permalink
rename api for consistency and add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
vggonzal authored and vggonzal committed Oct 18, 2023
1 parent 01905e7 commit e766a89
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 9 deletions.
26 changes: 26 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Github Issue: #NUM _(replace NUM with Github issue number)_

### Description

_Summarize the ticket here_

### Overview of work done

_Summarize the work you did_

### Overview of verification done

_Summarize the testing and verification you've done. This includes unit tests or testing with specific data_

### Overview of integration done

_Explain how this change was integration tested. Provide screenshots or logs if appropriate. An example of this would be a local Harmony deployment._

## PR checklist:

* [ ] Linted
* [ ] Updated unit tests
* [ ] Updated changelog
* [ ] Integration testing

_See [Pull Request Review Checklist](../CONTRIBUTING.md#reviewing) for pointers on reviewing this pull request_
163 changes: 163 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# This is the main build pipeline that verifies and publishes the software
name: Build
# Controls when the workflow will run
on:
# Triggers the workflow on push events
push:
branches: [ develop, release/**, main, feature/**, issue/**, dependabot/** ]
tags-ignore:
- '*'
paths-ignore:
- 'pyproject.toml'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
POETRY_VERSION: "1.3.1"
PYTHON_VERSION: "3.10"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
# First job in the workflow installs and verifies the software
build:
name: Build, Test, Verify, Publish
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
- uses: getsentry/action-github-app-token@v2
name: podaac cicd token
id: podaac-cicd
with:
app_id: ${{ secrets.CICD_APP_ID }}
private_key: ${{ secrets.CICD_APP_PRIVATE_KEY }}
- uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
token: ${{ steps.podaac-cicd.outputs.token }}
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}


- name: Install bumpver & poetry
run: pip3 install bumpver poetry poetry-plugin-bundle
- name: Install dependencies
run: poetry install

- name: Get version
id: get-version
run: |
echo "current_version=$(poetry version | awk '{print $2}')" >> $GITHUB_OUTPUT
echo "pyproject_name=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV
- name: Bump pre-alpha version
# If triggered by push to a feature branch
if: |
startsWith(github.ref, 'refs/heads/feature') ||
startsWith(github.ref, 'refs/heads/issue') ||
startsWith(github.ref, 'refs/heads/dependabot')
run: |
new_ver="${{ steps.get-version.outputs.current_version }}+$(git rev-parse --short ${GITHUB_SHA})"
poetry version $new_ver
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
- name: Bump alpha version
# If triggered by push to the develop branch
if: ${{ github.ref == 'refs/heads/develop' }}
run: |
poetry version prerelease
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
echo "venue=sit" >> $GITHUB_ENV
- name: Bump rc version
# If triggered by push to a release branch
if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
env:
# True if the version already has a 'rc' pre-release identifier
BUMP_RC: ${{ contains(steps.get-version.outputs.current_version, 'rc') }}
run: |
if [ "$BUMP_RC" = true ]; then
poetry version prerelease
else
poetry version ${GITHUB_REF#refs/heads/release/}-rc.1
fi
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
echo "venue=uat" >> $GITHUB_ENV
- name: Release version
# If triggered by push to the main branch
if: ${{ startsWith(github.ref, 'refs/heads/main') }}
env:
CURRENT_VERSION: ${{ steps.get-version.outputs.current_version }}
# Remove -rc.* from end of version string
# The ${string%%substring} syntax below deletes the longest match of $substring from back of $string.
run: |
poetry version ${CURRENT_VERSION%%-rc.*}
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
echo "venue=ops" >> $GITHUB_ENV
- name: Install hydrocron
run: poetry install
- name: Lint
run: |
poetry run pylint hydrocronapi
poetry run flake8 hydrocronapi
## Set environment variables
- name: Configure Initial YAML file and environment variables
run: |
echo "THE_VERSION=${{ env.software_version }}" >> $GITHUB_ENV;
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV;
GITHUB_REF_READABLE="${GITHUB_REF//\//-}"
echo "GITHUB_REF_READABLE=${GITHUB_REF_READABLE}" >> $GITHUB_ENV
echo "THE_ENV=sit" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV
- name: Run Snyk as a blocking step
uses: snyk/actions/python-3.9@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: test
args: >
--org=${{ secrets.SNYK_ORG_ID }}
--project-name=${{ github.repository }}
--severity-threshold=high
--fail-on=all
- name: Run Snyk on Python
uses: snyk/actions/python-3.9@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
args: >
--org=${{ secrets.SNYK_ORG_ID }}
--project-name=${{ github.repository }}
- name: Commit Version Bump
# If building develop, a release branch, or main then we commit the version bump back to the repo
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release')
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git commit -am "/version ${{ env.software_version }}"
git push
- name: Push Tag
if: |
github.ref == 'refs/heads/develop' ||
github.ref == 'refs/heads/main' ||
startsWith(github.ref, 'refs/heads/release')
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag -a "${{ env.software_version }}" -m "Version ${{ env.software_version }}"
git push origin "${{ env.software_version }}"
- name: Build Python Artifact
run: |
poetry build
- name: Test with pytest
run: |
poetry run pytest tests/test_api.py -k 'test_gettimeseries_get'
poetry run pytest tests/test_api.py -k 'test_hydrocron_database'
poetry run pytest tests/test_api.py -k 'test_io_swot_reach_node_shp'
File renamed without changes.
2 changes: 1 addition & 1 deletion hydrocronapi/__main__.py → hydrocron_api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def main():
"""
Main function to run flask app in port 8080
"""
from hydrocronapi import hydrocron # noqa: E501 # pylint: disable=import-outside-toplevel
from hydrocron_api import hydrocron # noqa: E501 # pylint: disable=import-outside-toplevel
hydrocron.flask_app.run(port=8080)


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datetime import datetime
from typing import Generator
from shapely import Polygon, Point
from hydrocronapi import hydrocron
from hydrocron_api import hydrocron


logger = logging.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import time
from datetime import datetime
from typing import Generator
from hydrocronapi import hydrocron
from hydrocron_api import hydrocron

logger = logging.getLogger()

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion hydrocronapi/hydrocron.py → hydrocron_api/hydrocron.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import boto3
import connexion

from hydrocronapi.data_access.db import DynamoDataRepository
from hydrocron_api.data_access.db import DynamoDataRepository


class Context(ModuleType):
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
import os

from flask_testing import TestCase
from hydrocronapi.data_access.db import DynamoDataRepository
from hydrocron_api.data_access.db import DynamoDataRepository


class BaseTestCase(TestCase):

def create_app(self):
os.environ['HYDROCRON_ENV'] = 'test'
import hydrocronapi.hydrocron # noqa: E501 # pylint: disable=import-outside-toplevel
hydrocronapi.hydrocron.flask_app.config.update({
import hydrocron_api.hydrocron # noqa: E501 # pylint: disable=import-outside-toplevel
hydrocron_api.hydrocron.flask_app.config.update({
"TESTING": True,
})
logging.getLogger('connexion.operation').setLevel('DEBUG')

hydrocronapi.hydrocron.construct_repository = lambda: DynamoDataRepository(self.dynamo_db)
return hydrocronapi.hydrocron.flask_app
hydrocron_api.hydrocron.construct_repository = lambda: DynamoDataRepository(self.dynamo_db)
return hydrocron_api.hydrocron.flask_app

0 comments on commit e766a89

Please sign in to comment.