Skip to content

Commit

Permalink
Merge pull request #1 from TheJacksonLaboratory/G3-58-set-up-cicd-for…
Browse files Browse the repository at this point in the history
…-geneweaver-api

G3 58 set up cicd for geneweaver api
  • Loading branch information
bergsalex authored Dec 5, 2023
2 parents adbc0c1 + 90a56bd commit 925d4dc
Show file tree
Hide file tree
Showing 52 changed files with 713 additions and 278 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/_check-coverage-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: 'Test Coverage Definition'
on:
workflow_call:
inputs:
coverage-module:
description: "Module to test coverage for"
type: string
required: true
python-version:
description: Python version to set up'
default: '3.11'
type: string
runner-os:
description: 'Runner OS'
default: 'ubuntu-latest'
type: string
upload-coverage:
description: 'Upload coverage results'
default: true
type: boolean
required-coverage:
description: 'Required coverage percentage'
default: 100
type: string
show-test-traceback:
description: "Show traceback for failed tests"
type: string
default: "no"
jobs:
run-tests:
runs-on: ${{ inputs.runner-os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "/Users/runner/.local/bin:$PATH" >> $GITHUB_PATH
fi
- name: Configure Poetry
run: poetry config virtualenvs.create false
- name: Install dependencies with Poetry
run: poetry install
- name: Test with pytest
run: |
poetry run pytest tests \
--tb=${{ inputs.show-test-traceback }} \
--cov=${{ inputs.coverage-module }} \
--cov-report=term \
--cov-report=html \
--cov-fail-under=${{ inputs.required-coverage }} > coverage_report.txt
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage_report.txt
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report-html
path: htmlcov
24 changes: 24 additions & 0 deletions .github/workflows/_format-lint-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Lint Code Definition'
on:
workflow_call:
inputs:
python-version:
description: 'Python version to set up'
required: true
default: '3.9'
type: string
jobs:
format-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install Black and Ruff
run: pip install black ruff
- name: Run Ruff Linter
run: ruff src/ tests/
- name: Run Black Formatter
run: black src/ tests/
44 changes: 44 additions & 0 deletions .github/workflows/_run-tests-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'Python Tests Definition'
on:
workflow_call:
inputs:
python-version:
description: Python version to set up'
required: true
default: '3.9'
type: string
runner-os:
description: 'Runner OS'
required: true
default: 'ubuntu-latest'
type: string
upload-coverage:
description: 'Upload coverage results'
default: true
type: boolean
required-coverage:
description: 'Required coverage percentage'
default: 75
type: string
jobs:
run-tests:
runs-on: ${{ inputs.runner-os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "/Users/runner/.local/bin:$PATH" >> $GITHUB_PATH
fi
- name: Configure Poetry
run: poetry config virtualenvs.create false
- name: Install dependencies with Poetry
run: poetry install
- name: Test with pytest
run: |
poetry run pytest tests
49 changes: 49 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Coverage
on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
jobs:
check-coverage:
uses: ./.github/workflows/_check-coverage-action.yml
with:
required-coverage: ${{ vars.REQUIRED_COVERAGE }}
coverage-module: "geneweaver.api"
comment-coverage-report:
needs: [ check-coverage ]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
pull-requests: write
steps:
- name: Download coverage report artifact
uses: actions/download-artifact@v3
with:
name: coverage-report
- name: Read coverage report
id: read-coverage
run: |
echo "COVERAGE_REPORT<<EOF" >> $GITHUB_ENV
cat coverage_report.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '### Test Coverage Report'
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
### Test Coverage Report
```
${{ env.COVERAGE_REPORT }}
```
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 to PyPI

on:
push:
branches:
- 'main'
paths:
- 'pyproject.toml'

permissions:
contents: write

jobs:
format-lint:
uses: ./.github/workflows/_format-lint-action.yml
with:
python-version: '3.9'
test:
needs: format-lint
uses: ./.github/workflows/_run-tests-action.yml
with:
python-version: '3.9'
runner-os: 'ubuntu-latest'
upload-coverage: false
required-coverage: ${{ vars.REQUIRED_COVERAGE }}
release:
needs: test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'z

- name: Install dependencies
run: |
pip install toml
- name: Check for version change
id: version_check
run: |
# Extract version from pyproject.toml
version=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
echo "Version=$version"
echo "version=$version" >> $GITHUB_OUTPUT
# Check if this version tag already exists
if git rev-parse "v$version" >/dev/null 2>&1; then
echo "Version already released"
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "New version detected"
echo "should_release=false" >> $GITHUB_OUTPUT
fi
- name: Determine Release Type
id: release_type
run: |
version=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
if [[ $version =~ [a-zA-Z] ]]; then
echo "Pre-release version detected"
echo "prerelease=true" >> $GITHUB_OUTPUT
else
echo "Full release version detected"
echo "prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Install Poetry
if: ${{ steps.version_check.outputs.should_release }} == 'true'
run: |
curl -sSL https://install.python-poetry.org | python3 -
# TODO: Add deploy to kubernetes step
13 changes: 13 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Style
on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
jobs:
format-lint:
uses: ./.github/workflows/_format-lint-action.yml
with:
python-version: '3.9'
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Tests
on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.9', '3.10', '3.11']
uses: ./.github/workflows/_run-tests-action.yml
with:
runner-os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
required-coverage: ${{ vars.REQUIRED_COVERAGE }}
27 changes: 23 additions & 4 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
## Project Name: geneweaver-api
# Geneweaver 3 API

Description: description
Description: The API for the Geneweaver v3 application ecosystem.

App: geneweaver_api
## Setup

To run the app execute `uvicorn geneweaver_api.main:app --reload`
### Local

#### Requirements

- Python Poetry
- Python 3.9 or higher
- A connection to a copy of the Geneweaver Database

#### Setup

1. Clone the repository
2. Run `poetry install` in project root to install dependencies
3. Configure environment settings with environment variables or a `.env` file.
4. Run the application

To run the app execute either `uvicorn geneweaver.api.main:app --reload` with the poetry
virtualenv activated, or just run `poetry run uvicorn geneweaver.api.main:app --reload`.

This will host the application on `http://127.0.0.1:8000/` which means the swagger docs
page is available at `http://127.0.0.1:8000/docs`.
Loading

0 comments on commit 925d4dc

Please sign in to comment.