Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement C# Dotnet Function App REST APIs #8

Merged
merged 37 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0a406d4
Add Makefile, cookiecutter template, and pre-generation validation fo…
colbytimm Nov 30, 2024
d769d96
Remove obsolete Makefile and .gitignore; add GitHub Actions workflow …
colbytimm Nov 30, 2024
1bb5da8
Add initial Dotnet API project structure with configuration, models, …
colbytimm Nov 30, 2024
7512d2f
Add install target to Makefile and update VSCode settings for Python …
colbytimm Nov 30, 2024
e763478
Refactor project structure: rename project and update entity definiti…
colbytimm Nov 30, 2024
69445d2
Add GitHub Actions workflow for Dotnet API build with multi-platform …
colbytimm Nov 30, 2024
48de727
Add _copy_without_render entry for build-pipeline.yml in cookiecutter…
colbytimm Nov 30, 2024
20ad8ed
Remove cloud service entry from GitHub Actions build pipeline configu…
colbytimm Nov 30, 2024
7f45117
Rename API project and test project entries in solution file for cons…
colbytimm Nov 30, 2024
edf1ebf
Rename csproj files
colbytimm Nov 30, 2024
aa47539
Refactor action.yaml for setup-cookiecutter-template: update name and…
colbytimm Nov 30, 2024
63c2fdd
Rename pipeline extension to yaml
colbytimm Nov 30, 2024
79ed14d
Update project names in action.yaml for setup-cookiecutter-template
colbytimm Nov 30, 2024
5052a6c
Rename working directory references from Kitten-Claws to KittenClaws …
colbytimm Nov 30, 2024
253432d
Enhance README.md: center title and add build status badges
colbytimm Dec 1, 2024
abe2dc7
Update README.md: adjust table column widths for better alignment
colbytimm Dec 1, 2024
f05beaa
Update README.md: standardize table attributes for consistency
colbytimm Dec 1, 2024
0961fba
Update README.md: adjust table column widths for improved layout
colbytimm Dec 1, 2024
1e06fb3
Fix README.md: update image tag to use height attribute for Python icon
colbytimm Dec 1, 2024
50667cc
Enhance README.md: add Cookiecutter badge to project headers for visi…
colbytimm Dec 1, 2024
2fa6013
Add VSCode extensions recommendations and update .gitignore for Azurite
colbytimm Dec 4, 2024
c1a0a0b
Add mock HttpRequestData utility for unit tests
colbytimm Dec 4, 2024
01d533d
Refactor project structure: update namespaces, remove unused files, a…
colbytimm Dec 4, 2024
6affe0f
Refactor namespaces and update method signatures for consistency in A…
colbytimm Dec 4, 2024
67ea6c1
Add local settings configuration for Azure Functions with Cosmos DB c…
colbytimm Dec 4, 2024
59ff533
Update local settings JSON to escape placeholders for Cosmos DB confi…
colbytimm Dec 4, 2024
32ca952
Update CI workflows to use matrix for OS selection instead of hardcod…
colbytimm Dec 4, 2024
d76f758
Remove .NET 9.x from the CI workflow to streamline build process
colbytimm Dec 4, 2024
401d983
Enhance GitHub Actions workflow to conditionally add Poetry to PATH f…
colbytimm Dec 4, 2024
251097d
Refactor CI workflows to use Makefile commands for dependency install…
colbytimm Dec 4, 2024
8210a97
Refactor GitHub Actions workflow to use Makefile for dependency insta…
colbytimm Dec 4, 2024
cfcde46
Refactor build pipeline to change working directory before running Ma…
colbytimm Dec 4, 2024
3bb5e7a
Remove unnecessary Poetry shell command from Makefile install target
colbytimm Dec 4, 2024
88e2347
Replace Makefile install command with Poetry install in build pipeline
colbytimm Dec 4, 2024
7ee381f
Enhance repository methods and update VSCode settings for improved fo…
colbytimm Dec 4, 2024
e9f5b01
Update GitHub Actions workflow to run unit tests with Poetry and pytest
colbytimm Dec 4, 2024
6492e10
Add Dotnet Function App example to README
colbytimm Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/actions/setup-cookiecutter-template/action.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: "setup-cookiecutter-template"
description: "Composite action to setup the Cookiecutter template."
name: Setup Cookiecutter Template
description: Composite action to setup the Cookiecutter template.

inputs:
template-language:
required: true
description: "Template language"
description: Template language
template-cloud-service:
required: true
description: "Template cloud service"
description: Template cloud service

runs:
using: "composite"
Expand All @@ -29,12 +29,12 @@ runs:
- name: Create Cookiecutter Template
run: |
cookiecutter ./${{ inputs.template-language }} --no-input \
project_name="Kitten-Claws" \
project_name="KittenClaws" \
project_description="Kitties got claws...beware" \
project_slug="kitty_cats" \
project_endpoint="kitties" \
project_lower_camel_name="kittyCat" \
project_class_name="KittyCat" \
project_lower_camel_name="kittenClaws" \
project_class_name="KittenClaws" \
author="Sir Meowsalots" \
cloud_service="${{ inputs.template-cloud-service }}" \
open_source_license="MIT license"
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/build-dotnet-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Dotnet Cookiecutter API Build

on:
push:
paths:
- dotnet/**
branches:
- main
pull_request:
paths:
- dotnet/**
branches:
- main

jobs:
build-dotnet:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
template-type:
- dotnet
cloud-service:
- "Azure Function App"
dotnet-version:
- "8.x"
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v4

- name: Setup Cookiecutter Template
uses: ./.github/actions/setup-cookiecutter-template
with:
template-language: ${{ matrix.template-type }}
template-cloud-service: ${{ matrix.cloud-service }}

- name: Setup dotnet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}

- name: Install dependencies
run: make install
working-directory: KittenClaws

- name: Build
run: make build
working-directory: KittenClaws

- name: Test with the dotnet CLI
run: make test-unit
working-directory: KittenClaws
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
build-python:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
Expand Down Expand Up @@ -50,10 +50,16 @@ jobs:
run: curl -sSL https://install.python-poetry.org | python - -y
shell: bash

- name: Add Poetry to Path
- name: Add Poetry to Path (Linux and macOS)
if: runner.os != 'Windows'
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
shell: bash

- name: Add Poetry to Path (Windows)
if: runner.os == 'Windows'
run: echo "$HOME\\AppData\\Roaming\\Python\\Scripts" >> $GITHUB_PATH
shell: bash

- name: Configure Poetry virtual environment in project
run: poetry config virtualenvs.in-project true
shell: bash
Expand All @@ -68,6 +74,12 @@ jobs:
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
cd "Kitten-Claws"
cd "KittenClaws"
poetry install --no-interaction
shell: bash

- name: Run unit tests
run: |
cd "KittenClaws"
poetry run pytest --cov
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:

jobs:
build-typescript:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
Expand Down Expand Up @@ -51,16 +51,16 @@ jobs:
uses: borales/actions-yarn@v4
with:
cmd: install
dir: Kitten-Claws
dir: KittenClaws

- name: Run build
uses: borales/actions-yarn@v4
with:
cmd: build
dir: Kitten-Claws
dir: KittenClaws

- name: Unit tests
uses: borales/actions-yarn@v4
with:
cmd: test:unit
dir: Kitten-Claws
dir: KittenClaws
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"editor.formatOnSave": false
"editor.formatOnSave": false,
"editor.formatOnPaste": false
}
73 changes: 45 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<img src="./.docs/imgs/cookiecutter_api_header.jpg">

# <img src="./.docs/imgs/stars.gif" width="32"> Cookiecutter API <img src="./.docs/imgs/stars.gif" width="32">
<div align="center">
<h1>
<img src="./.docs/imgs/stars.gif" width="32"> Cookiecutter API <img src="./.docs/imgs/stars.gif" width="32">
</h1>
</div>

![](https://img.shields.io/github/actions/workflow/status/Code-and-Sorts/cookiecutter-api/build-python-pipeline.yaml?branch=main&label=Python-Build&style=for-the-badge)
![](https://img.shields.io/github/actions/workflow/status/Code-and-Sorts/cookiecutter-api/build-typescript-pipeline.yaml?branch=main&label=Typescript-Build&style=for-the-badge)
![](https://img.shields.io/github/actions/workflow/status/Code-and-Sorts/cookiecutter-api/build-dotnet-pipeline.yaml?branch=main&label=Dotnet-Build&style=for-the-badge)

![](https://img.shields.io/github/license/Code-and-Sorts/cookiecutter-api?label=License&style=for-the-badge&color=blue)

[![](https://img.shields.io/badge/made%20using%20cookiecutter-grey?style=for-the-badge&logo=cookiecutter)](https://github.com/cookiecutter/cookiecutter)

![](https://img.shields.io/github/actions/workflow/status/Code-and-Sorts/cookiecutter-api/build-python-pipeline.yml?branch=main&label=Python-Build&style=for-the-badge)
![](https://img.shields.io/github/actions/workflow/status/Code-and-Sorts/cookiecutter-api/build-typescript-pipeline.yml?branch=main&label=Typescript-Build&style=for-the-badge)
![](https://img.shields.io/github/license/Code-and-Sorts/cookiecutter-api?label=License&style=for-the-badge)

This is a modern 🍪 Cookiecutter template to create REST APIs for multiple cloud platforms in multiple languages. This template supports the multiple cloud platforms and languages.

Expand Down Expand Up @@ -35,41 +44,41 @@ Follow the prompts and answer them with your own desired options.

## 🌟 Supported Templates

<table style="width:100%;">
<table width="100%">
<tr>
<th style="width:18px;" rowspan="2"></th>
<td style="text-align:center;width:100px;"><img src="./.docs/imgs/azure.svg" height="18"> Azure</td>
<td style="text-align:center;width:100px;"><img src="./.docs/imgs/aws.svg" height="18"> AWS</td>
<td style="text-align:center;width:100px;"><img src="./.docs/imgs/google-cloud.svg" height="18"> GCP</td>
<th width="10%" rowspan="2"></th>
<td width="30%" align="center"><img src="./.docs/imgs/azure.svg" height="18"> Azure</td>
<td width="30%" align="center"><img src="./.docs/imgs/aws.svg" height="18"> AWS</td>
<td width="30%" align="center"><img src="./.docs/imgs/google-cloud.svg" height="18"> GCP</td>
</tr>
<tr>
<td style="text-align:center;"><img src="./.docs/imgs/function-app.svg" height="18" title="Function App"></td>
<td style="text-align:center;"><img src="./.docs/imgs/lambda.svg" height="18" title="Lambda"></td>
<td style="text-align:center;"><img src="./.docs/imgs/cloud-function.svg" height="18" title="Cloud Functions"></td>
<td align="center"><img src="./.docs/imgs/function-app.svg" height="18" title="Function App"> Function App</td>
<td align="center"><img src="./.docs/imgs/lambda.svg" height="18" title="Lambda"> Lambda</td>
<td align="center"><img src="./.docs/imgs/cloud-function.svg" height="18" title="Cloud Functions"> Cloud Function</td>
</tr>
<tr>
<td style="text-align:center;"><img src="./.docs/imgs/python.svg" width="18" title="Python"></td>
<td style="text-align:center;"><span title="Complete">✅</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td align="center"><img src="./.docs/imgs/python.svg" height="18" title="Python"></td>
<td align="center"><span title="Complete">✅</span></td>
<td align="center"><span title="Planned">📋</span></td>
<td align="center"><span title="Planned">📋</span></td>
</tr>
<tr>
<td style="text-align:center;"><img src="./.docs/imgs/typescript.svg" height="18" title="NodeJS"></td>
<td style="text-align:center;"><span title="Complete">✅</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td align="center"><img src="./.docs/imgs/typescript.svg" height="18" title="NodeJS"></td>
<td align="center"><span title="Complete">✅</span></td>
<td align="center"><span title="Planned">📋</span></td>
<td align="center"><span title="Planned">📋</span></td>
</tr>
<tr>
<td style="text-align:center;"><img src="./.docs/imgs/dotnet.svg" height="18" title="dotnet"></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td align="center"><img src="./.docs/imgs/dotnet.svg" height="18" title="dotnet"></td>
<td align="center"><span title="Complete">✅</span></td>
<td align="center"><span title="Planned">📋</span></td>
<td align="center"><span title="Planned">📋</span></td>
</tr>
<tr>
<td style="text-align:center;"><img src="./.docs/imgs/golang.svg" height="18" title="Golang"></td>
<td style="text-align:center;"><span title="Complete">📋</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td style="text-align:center;"><span title="Planned">📋</span></td>
<td align="center"><img src="./.docs/imgs/golang.svg" height="18" title="Golang"></td>
<td align="center"><span title="Complete">📋</span></td>
<td align="center"><span title="Planned">📋</span></td>
<td align="center"><span title="Planned">📋</span></td>
</tr>
</table>

Expand All @@ -85,6 +94,9 @@ Python
Typescript
- [Function App Example](https://github.com/Code-and-Sorts/cookie-ts-az-func-api)

Dotnet
- [Function App Example](https://github.com/Code-and-Sorts/cookie-cs-az-func-api)

## 📚 Resources

Below is a list of resources and documentation for the types of SDKs and frameworks used in the various Cookiecutter APIs.
Expand All @@ -99,6 +111,11 @@ Below is a list of resources and documentation for the types of SDKs and framewo
- [Jest](https://jestjs.io/) for testing
- [Zod](https://zod.dev/) for schema validtion

## Dotnet
- [Nuget](https://www.nuget.org/) for dependency management
- [xUnit](https://xunit.net/) for testing
- [FluentValidation](https://docs.fluentvalidation.net/en/latest/) for schema validtion

### Azure
- [Azure Function Apps ](https://learn.microsoft.com/en-us/azure/azure-functions/) for hosting the APIs
- [Cosmos DB](https://learn.microsoft.com/en-us/azure/cosmos-db/) for data storage
Expand Down
4 changes: 4 additions & 0 deletions dotnet/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": false,
"editor.formatOnPaste": false
}
26 changes: 26 additions & 0 deletions dotnet/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"project_name": "Cookiecutter API",
"project_description": "This is a template repository for API projects.",
"project_endpoint": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}",
"project_lower_camel_name": "{{cookiecutter.project_name | to_lower_camel }}",
"project_class_name": "{{cookiecutter.project_name | to_camel }}",
"author": "Code and Sorts (Colby Timm)",
"cloud_service": [
"Azure Function App"
],
"open_source_license": [
"MIT license",
"BSD license",
"ISC license",
"Apache Software License 2.0",
"GNU General Public License v3",
"Not open source"
],
"_local_settings": "local.settings",
"_extensions": [
"jinja2_strcase.StrcaseExtension"
],
"_copy_without_render": [
".github/workflows/build-pipeline.yml"
]
}
31 changes: 31 additions & 0 deletions dotnet/hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import annotations

import re
import sys

PROJECT_LOWER_CAMEL_REGEX = r"^[a-z]+(?:[A-Z][a-z]+)*$"
project_lower_camel = "{{cookiecutter.project_lower_camel_name}}"
if not re.match(PROJECT_LOWER_CAMEL_REGEX, project_lower_camel):
print(
f"ERROR: The project lower camel {project_lower_camel} is not valid camel case. Please create a name using camelCase."
)
# Exit to cancel project
sys.exit(1)

PROJECT_CLASS_NAME_REGEX = r"^[A-Z][a-zA-Z0-9]*$"
project_class_name = "{{cookiecutter.project_class_name}}"
if not re.match(PROJECT_CLASS_NAME_REGEX, project_class_name):
print(
f"ERROR: The project class name {project_class_name} is not a valid class name. Please create a class name using PascalCase."
)
# Exit to cancel project
sys.exit(1)

PROJECT_ENDPOINT_REGEX = r"^[a-zA-Z0-9\-_]*$"
project_endpoint = "{{cookiecutter.project_endpoint}}"
if not re.match(PROJECT_ENDPOINT_REGEX, project_endpoint):
print(
f"ERROR: The project endpoint {project_endpoint} is not a valid REST endpoint name. Please do not use a space or _ and use - instead."
)
# Exit to cancel project
sys.exit(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Dotnet API Build

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-dotnet:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
dotnet-version:
- "8.x"
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v4

- name: Setup dotnet ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}

- name: Install dependencies
run: make install

- name: Build
run: make build

- name: Test unit tests
run: make test-unit
Loading
Loading