Skip to content

Commit 0b1f840

Browse files
ran-isenbergRan Isenberg
andauthored
feature: Makefile : update-deps automatically updates your cdk version (#956)
Co-authored-by: Ran Isenberg <[email protected]>
1 parent 8fc3298 commit 0b1f840

File tree

7 files changed

+302
-239
lines changed

7 files changed

+302
-239
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
exclude: "^(?!helpers/)"
2727
- repo: https://github.com/astral-sh/ruff-pre-commit
2828
# Ruff version.
29-
rev: v0.11.12
29+
rev: v0.12.0
3030
hooks:
3131
# Run the Ruff linter.
3232
- id: ruff

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,19 @@ watch:
7878
npx cdk watch
7979

8080
update-deps:
81+
@echo "Updating Poetry dependencies..."
8182
poetry update
83+
@echo "Updating pre-commit hooks..."
8284
pre-commit autoupdate
85+
@echo "Fetching latest CDK version from npm..."
86+
$(eval LATEST_CDK_VERSION := $(shell npm view aws-cdk version))
87+
@echo "Found CDK version: $(LATEST_CDK_VERSION)"
88+
@echo "Updating package.json with latest CDK version..."
89+
node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json')); pkg.dependencies['aws-cdk'] = '$(LATEST_CDK_VERSION)'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 4));"
8390
npm i --package-lock-only
91+
@echo "Installing npm dependencies..."
92+
npm install
93+
@echo "All dependencies updated successfully!"
8494

8595
openapi:
8696
poetry run python generate_openapi.py

Makefile_windows

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
.PHONY: dev lint complex coverage pre-commit sort deploy destroy deps unit infra-tests integration e2e coverage-tests docs lint-docs build format
1+
.PHONY: dev lint mypy-lint complex coverage pre-commit sort deploy destroy deps unit infra-tests integration e2e coverage-tests docs lint-docs build format format-fix compare-openapi openapi pr watch update-deps
2+
PYTHON := ".venv\Scripts\python.exe"
3+
# Use CMD shell explicitly for Windows commands
4+
SHELL := cmd.exe
5+
.SHELLFLAGS := /D /C
6+
7+
OPENAPI_DIR := .\docs\swagger
8+
CURRENT_OPENAPI := $(OPENAPI_DIR)\openapi.json
9+
LATEST_OPENAPI := openapi_latest.json
10+
211

312
dev:
413
pip install --upgrade pip pre-commit poetry
514
pre-commit install
15+
REM ensures poetry creates a local virtualenv (.venv)
616
poetry config --local virtualenvs.in-project true
717
poetry install --no-root
818
npm ci
919

1020
format:
11-
poetry run ruff check .
21+
poetry run ruff check . --fix
1222

1323
format-fix:
1424
poetry run ruff format .
@@ -19,49 +29,86 @@ lint: format
1929

2030
complex:
2131
@echo "Running Radon"
22-
poetry run radon cc -e 'tests\*,cdk.out\*,node_modules\*' .
32+
poetry run radon cc -e "tests\*,cdk.out\*,node_modules\*" .
2333
@echo "Running xenon"
24-
poetry run xenon --max-absolute B --max-modules A --max-average A -e 'tests\*,.venv\*,cdk.out\*,node_modules\*' .
34+
poetry run xenon --max-absolute B --max-modules A --max-average A -e "tests\*,.venv\*,cdk.out\*,node_modules\*" .
2535

2636
pre-commit:
2737
poetry run pre-commit run -a --show-diff-on-failure
2838

39+
mypy-lint:
40+
poetry run mypy --pretty service cdk tests
41+
2942
deps:
3043
poetry export --only=dev --format=requirements.txt > dev_requirements.txt
3144
poetry export --without=dev --format=requirements.txt > lambda_requirements.txt
3245

46+
unit:
47+
poetry run pytest tests\unit --cov-config=.coveragerc --cov=service --cov-report xml
48+
3349
build: deps
34-
if not exist ".build\lambdas\service" mkdir ".build\lambdas\service"
35-
rmdir /S /Q .build\lambdas\service
36-
echo D | xcopy /f /y service. .build\lambdas\service /s
50+
if not exist ".build\lambdas" mkdir ".build\lambdas"
51+
if exist ".build\lambdas\service" rmdir /S /Q ".build\lambdas\service"
52+
xcopy /E /I /Y service ".build\lambdas\service"
3753
if not exist ".build\common_layer" mkdir ".build\common_layer"
38-
poetry export --without=dev --format=requirements.txt > .build\common_layer\requirements.txt
39-
40-
mypy-lint:
41-
poetry run mypy --pretty service. docs\examples cdk tests
54+
poetry export --without=dev --format=requirements.txt > ".build\common_layer\requirements.txt"
4255

43-
unit:
44-
poetry run pytest tests\unit --cov-config=.coveragerc --cov=service --cov-report xml
56+
infra-tests: build
57+
poetry run pytest tests\infrastructure
4558

4659
integration:
47-
poetry run pytest tests\integration --cov-config=.coveragerc --cov=service --cov-report xml
60+
poetry run pytest tests\integration --cov-config=.coveragerc --cov=service --cov-report xml
4861

4962
e2e:
50-
poetry run pytest tests\e2e --cov-config=.coveragerc --cov=service --cov-report xml
63+
poetry run pytest tests\e2e --cov-config=.coveragerc --cov=service --cov-report xml
5164

52-
pr: deps pre-commit complex lint lint-docs unit integration e2e
65+
pr: deps format pre-commit complex lint lint-docs unit deploy coverage-tests e2e openapi
5366

54-
pipeline-tests:
55-
poetry run pytest tests\unit tests\integration --cov-config=.coveragerc --cov=service --cov-report xml
67+
coverage-tests:
68+
poetry run pytest tests\unit tests\integration --cov-config=.coveragerc --cov=service --cov-report xml
5669

5770
deploy: build
58-
npx cdk deploy --app=".venv\Scripts\python.exe app.py" --require-approval=never
71+
npx cdk deploy --app="$(PYTHON) app.py" --require-approval=never
5972

6073
destroy:
61-
npx cdk destroy --app=".venv\Scripts\python.exe app.py" --force
74+
npx cdk destroy --app="$(PYTHON) app.py" --force
6275

6376
docs:
6477
poetry run mkdocs serve
6578

6679
lint-docs:
67-
docker run -v \markdown 06kellyjac\markdownlint-cli --fix "docs"
80+
@echo "Linting documentation with Docker. Make sure Docker is running."
81+
docker run -v "%cd%:/markdown" 06kellyjac/markdownlint-cli --fix "docs"
82+
83+
watch:
84+
npx cdk watch
85+
86+
update-deps:
87+
@echo "Updating Poetry dependencies..."
88+
poetry update
89+
@echo "Updating pre-commit hooks..."
90+
pre-commit autoupdate
91+
@echo "Fetching latest CDK version from npm..."
92+
for /f "tokens=*" %%i in ('npm view aws-cdk version') do set LATEST_CDK_VERSION=%%i
93+
@echo "Found CDK version: %LATEST_CDK_VERSION%"
94+
@echo "Updating package.json with latest CDK version..."
95+
node -e "const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('package.json')); pkg.dependencies['aws-cdk'] = process.env.LATEST_CDK_VERSION; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 4));"
96+
npm i --package-lock-only
97+
@echo "Installing npm dependencies..."
98+
npm install
99+
@echo "All dependencies updated successfully!"
100+
101+
openapi:
102+
poetry run python generate_openapi.py
103+
104+
compare-openapi:
105+
poetry run python generate_openapi.py --out-destination "." --out-filename "openapi_latest.json"
106+
fc /B "$(CURRENT_OPENAPI)" "$(LATEST_OPENAPI)" >nul 2>&1
107+
if errorlevel 1 (
108+
del "$(LATEST_OPENAPI)"
109+
echo "Swagger files are not equal, did you run 'make pr' or 'make openapi'?"
110+
exit /b 1
111+
) else (
112+
del "$(LATEST_OPENAPI)"
113+
echo "Swagger file is up to date"
114+
)

docs/pipeline.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ All steps can be run locally using the makefile. See details below:
3333
- Code coverage tests - run `make coverage-tests` in the IDE after CDK dep
3434
- OpenAPI Swagger file - run
3535
- Update GitHub documentation branch
36+
- Update dependencies and CDK version automatically to the latest versions: run `make update-deps`.
3637

3738
### **Other Capabilities**
3839

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"aws-cdk": "2.1017.1"
3+
"aws-cdk": "2.1019.2"
44
}
55
}

0 commit comments

Comments
 (0)