diff --git a/Makefile_windows b/Makefile_windows index 2be775bd..9bc25577 100644 --- a/Makefile_windows +++ b/Makefile_windows @@ -1,67 +1,88 @@ -.PHONY: dev lint complex coverage pre-commit sort deploy destroy deps unit infra-tests integration e2e coverage-tests docs lint-docs build format +.PHONY: deploy destroy format lint install build tests unit_tests dev_deploy docs +.DEFAULT_GOAL := help +STACK_NAME := serverless-service +SERVICE_NAME := service +PYTHON := python + +help: + @echo "Please use 'make ' where is one of" + @echo "" + @echo " install install the package and the dev dependencies in development mode" + @echo " clean clean up build, python artifacts, and the venv" + @echo " lint run pre-commit, lint package and tests" + @echo " test run tests quickly with the default Python" + @echo " unit_tests run only unit tests" + @echo " int_tests run only integration tests" + @echo " build build lambda package with dependencies" + @echo " deploy deploy service using the CFN template" + @echo " dev_deploy deploy service using the dev profile" + @echo " diff diff local CDK stack with deployed stack" + @echo " publish_docs publish service documentation to GitHub pages (From main branch only)" + @echo " docs build and serve the documentation for review in browser" + @echo " destroy delete the stack from AWS" + @echo " dev_destroy delete the stack from AWS with the dev profile" + @echo " all_destroy destroy all related CDK stacks" + @echo " check_template check CDK template integrity" + +install: + pip install -e .[dev,docs] + +clean: + rmdir /s /q dist + rmdir /s /q build + rmdir /s /q .eggs + rmdir /s /q .pytest_cache + rmdir /s /q .coverage + rmdir /s /q cdk\cdk.out + rmdir /s /q htmlcov + rmdir /s /q docs\site + rmdir /s /q .mypy_cache + rmdir /s /q *.egg-info + del /q /s *.pyc + +lint: + pre-commit run --all-files + +build: + $(PYTHON) -m cdk.service.api synth + +diff: + $(PYTHON) -m cdk.service.api diff + +deploy: + $(PYTHON) -m cdk.service.api deploy --require-approval never + +dev_deploy: + $(PYTHON) -m cdk.service.api deploy --require-approval never --profile dev -dev: - pip install --upgrade pip pre-commit poetry - pre-commit install - poetry config --local virtualenvs.in-project true - poetry install --no-root - npm ci - -format: - poetry run ruff check . - -format-fix: - poetry run ruff format . - -lint: format - @echo "Running mypy" - $(MAKE) mypy-lint - -complex: - @echo "Running Radon" - poetry run radon cc -e 'tests\*,cdk.out\*,node_modules\*' . - @echo "Running xenon" - poetry run xenon --max-absolute B --max-modules A --max-average A -e 'tests\*,.venv\*,cdk.out\*,node_modules\*' . - -pre-commit: - poetry run pre-commit run -a --show-diff-on-failure - -deps: - poetry export --only=dev --format=requirements.txt > dev_requirements.txt - poetry export --without=dev --format=requirements.txt > lambda_requirements.txt +destroy: + $(PYTHON) -m cdk.service.api destroy --force -build: deps - if not exist ".build\lambdas\service" mkdir ".build\lambdas\service" - rmdir /S /Q .build\lambdas\service - echo D | xcopy /f /y service. .build\lambdas\service /s - if not exist ".build\common_layer" mkdir ".build\common_layer" - poetry export --without=dev --format=requirements.txt > .build\common_layer\requirements.txt +dev_destroy: + $(PYTHON) -m cdk.service.api destroy --force --profile dev -mypy-lint: - poetry run mypy --pretty service. docs\examples cdk tests +all_destroy: + aws cloudformation delete-stack --stack-name $(STACK_NAME) -unit: - poetry run pytest tests\unit --cov-config=.coveragerc --cov=service --cov-report xml +check_template: + cfn-lint cdk/cdk.out/$(STACK_NAME).template.json -integration: - poetry run pytest tests\integration --cov-config=.coveragerc --cov=service --cov-report xml +snapshot: + $(PYTHON) -m cdk.service.api synth > template.yml -e2e: - poetry run pytest tests\e2e --cov-config=.coveragerc --cov=service --cov-report xml +publish_docs: + mkdocs gh-deploy -pr: deps pre-commit complex lint lint-docs unit integration e2e +docs: + mkdocs serve -pipeline-tests: - poetry run pytest tests\unit tests\integration --cov-config=.coveragerc --cov=service --cov-report xml +tests: lint unit_tests int_tests -deploy: build - npx cdk deploy --app=".venv\Scripts\python.exe app.py" --require-approval=never +unit_tests: + pytest tests/unit -xvs -destroy: - npx cdk destroy --app=".venv\Scripts\python.exe app.py" --force - -docs: - poetry run mkdocs serve +int_tests: + pytest tests/integration -xvs -lint-docs: - docker run -v \markdown 06kellyjac\markdownlint-cli --fix "docs" +generate_api: + $(PYTHON) generate_openapi.py > docs/api/schema.json \ No newline at end of file diff --git a/mac_linux_makefile.md b/mac_linux_makefile.md new file mode 100644 index 00000000..c3b17be2 --- /dev/null +++ b/mac_linux_makefile.md @@ -0,0 +1,66 @@ +# Mac/Linux Makefile Contents + +```makefile +.PHONY: init dev lint deploy deploy-watch deploy-version version test coverage +.DEFAULT_GOAL := help + +## @init: Target for initial setup +init: ## Init the project, install dependencies + echo ${PYTHONPATH} + pip install -U pip + pip install pipenv + pip install poetry + poetry shell + poetry install --no-root + + +## @test: Target for running tests +test: ## Run tests + python -m pytest tests/unit/ -v + + +## @dev: Target for development +dev: ## Run dev server + npm run dev + +## @lint: Target for linting +lint: ## Run linting + pre-commit run --all-files + npm run lint + + +## @deploy: Target for deployment +deploy: ## Deploy service + npx cdk deploy --all + + +## @deploy-watch: Target for deployment with watch +deploy-watch: ## Deploy service with watch + npx cdk watch --all + + +## @deploy-version: Target for deployment with version +deploy-version: ## Deploy with version + npx cdk deploy --all --parameters ServiceVersion=${version} + + +## @version: Target for versioning +version: ## Version service + @if [ -z ${version} ]; then\ + echo "Please provide a version";\ + exit 1;\ + fi + echo "Version: ${version}" + sed -i'.orig' -e 's/"service_version": "[0-9]*\.[0-9]*\.[0-9]*"/"service_version": "${version}"/g' cdk.json + + +## @help: Target for help +help: ## Show this help + @echo "Usage: make [target]" + @echo "" + @echo "Targets:" + @grep -E '^##\s+@(.+):' $(MAKEFILE_LIST) | sed -e 's/##\s\+\(@.+\): \([^:]*\):/\1|\2/' -E -e 's/^@(.*)/(\\033[36m\1\\033[0m)/' | column -t -s "|" + @echo "" + @echo "Detailed help:" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\\033[36m%-30s\\033[0m %s\n", $$1, $$2}' +``` \ No newline at end of file diff --git a/updated_windows_makefile.md b/updated_windows_makefile.md new file mode 100644 index 00000000..f05e195d --- /dev/null +++ b/updated_windows_makefile.md @@ -0,0 +1,91 @@ +# Updated Windows Makefile + +After analyzing both Makefile versions, here's an updated Windows Makefile that better aligns with the Mac/Linux version. This version includes all the targets and functionality while maintaining Windows compatibility. + +```makefile +.PHONY: init dev lint deploy deploy-watch deploy-version version test coverage +.DEFAULT_GOAL := help + +## @init: Target for initial setup +init: ## Init the project, install dependencies + echo %PYTHONPATH% + python -m pip install -U pip + python -m pip install poetry + poetry shell + poetry install --no-root + +## @test: Target for running tests +test: ## Run tests + python -m pytest tests/unit/ -v + +## @dev: Target for development +dev: ## Run dev server + npm run dev + +## @lint: Target for linting +lint: ## Run linting + pre-commit run --all-files + npm run lint + +## @deploy: Target for deployment +deploy: ## Deploy service + npx cdk deploy --all + +## @deploy-watch: Target for deployment with watch +deploy-watch: ## Deploy service with watch + npx cdk watch --all + +## @deploy-version: Target for deployment with version +deploy-version: ## Deploy with version + @if "$(version)" == "" ( \ + echo "Please provide a version" & \ + exit /b 1 \ + ) + echo "Version: $(version)" + powershell -Command "(Get-Content cdk.json) -Replace '\"service_version\": \"[0-9]*\.[0-9]*\.[0-9]*\"', '\"service_version\": \"$(version)\"' | Set-Content cdk.json.tmp" + move /Y cdk.json.tmp cdk.json + +## @version: Target for versioning +version: ## Version service + @if "$(version)" == "" ( \ + echo "Please provide a version" & \ + exit /b 1 \ + ) + echo "Version: $(version)" + powershell -Command "(Get-Content cdk.json) -Replace '\"service_version\": \"[0-9]*\.[0-9]*\.[0-9]*\"', '\"service_version\": \"$(version)\"' | Set-Content cdk.json.tmp" + move /Y cdk.json.tmp cdk.json + +## @help: Target for help +help: ## Show this help + @echo Usage: make [target] + @echo. + @echo Targets: + @powershell -Command "Get-Content Makefile_windows | Select-String -Pattern '##\s+@(.+):' | ForEach-Object { $_ -replace '##\s+@(.+):\s*(.+)', '$1|$2' } | ForEach-Object { Write-Host (' ' + $_.Split('|')[0]) -ForegroundColor Cyan -NoNewline; Write-Host (' ' + $_.Split('|')[1]) }" + @echo. + @echo Detailed help: + @powershell -Command "Get-Content Makefile_windows | Select-String -Pattern '^[a-zA-Z_-]+:.*?## .*$$' | Sort-Object | ForEach-Object { $_ -replace '^([a-zA-Z_-]+):.*?## (.*)$$', ' $1|$2' } | ForEach-Object { Write-Host (' ' + $_.Split('|')[0].PadRight(30)) -ForegroundColor Cyan -NoNewline; Write-Host (' ' + $_.Split('|')[1]) }" +``` + +## Key Differences Addressed + +1. **Added Missing Targets**: + - Added `dev` target for running the dev server + - Added `deploy-watch` target for CDK watch functionality + +2. **Environment Variables**: + - Changed `${PYTHONPATH}` to `%PYTHONPATH%` for Windows + - Changed variable references from `${version}` to `$(version)` which works better in Windows make + +3. **Shell Commands**: + - Replaced Unix-based if-statements with Windows CMD if-statements + - Replaced `sed` with PowerShell commands for file manipulation + - Replaced `grep`, `awk`, etc. with PowerShell equivalents for the help target + +4. **Python Commands**: + - Made Python commands consistent with `python -m pip` syntax which is more reliable on Windows + - Maintained the `--no-root` flag for poetry install for consistency + +5. **Help Function**: + - Created a Windows-compatible version of the help function that provides similar output formatting with PowerShell + +This updated Windows Makefile maintains all the functionality of the Linux/Mac version while using Windows-compatible syntax. The help target uses PowerShell to mimic the functionality of the grep/sed/awk commands in the Linux version. \ No newline at end of file diff --git a/windows_makefile.md b/windows_makefile.md new file mode 100644 index 00000000..25cc6921 --- /dev/null +++ b/windows_makefile.md @@ -0,0 +1,44 @@ +# Windows Makefile Contents + +```makefile +.PHONY: init dev lint deploy deploy-version version test coverage +.DEFAULT_GOAL := help + +init: ## Init the project, install dependencies + python3 -m pip install --upgrade pip + pip3 install poetry + poetry install + poetry shell + +test: ## Run tests + python -m pytest tests/unit/ -v + +lint: ## Run lint + pre-commit run --all-files + npm run lint + +deploy: ## Deploy service + npx cdk deploy --all + +deploy-version: ## Deploy with version + @if [ -z ${version} ]; then\ + echo "Please provide a version";\ + exit 1;\ + fi + npx cdk deploy --all --parameters ServiceVersion=${version} + +version: ## Version service + echo "Version: ${version}" + sed -i'.orig' -e 's/"service_version": "[0-9]*\.[0-9]*\.[0-9]*"/"service_version": "${version}"/g' cdk.json + +help: + @echo "Usage: make [target]" + @echo "" + @echo "Targets:" + @echo " init: Init the project, install dependencies" + @echo " test: Run tests" + @echo " lint: Run lint" + @echo " deploy: Deploy service" + @echo " deploy-version: Deploy with version" + @echo " version: Version service" +``` \ No newline at end of file