Skip to content

Commit d82f64b

Browse files
Ensure the lambda is rebuilt if, and only if, it needs to be.
1 parent ca4c399 commit d82f64b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# ==============================================================================
44
include scripts/init.mk
55

6+
MAKE_DIR := $(abspath $(shell pwd))
7+
68
#Installs dependencies using poetry.
79
install-python:
810
poetry install
@@ -39,13 +41,15 @@ publish: clean
3941
#Files to loop over in release
4042
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. tests"
4143

42-
4344
# Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc.
4445

4546
dependencies: # Install dependencies needed to build and test the project @Pipeline
4647
scripts/dependencies.sh
4748

48-
build: # Build lambda in dist
49+
.PHONY: build
50+
build: dist/lambda.zip # Build lambda.zip in dist/
51+
52+
dist/lambda.zip: $(MAKE_DIR)/pyproject.toml $(MAKE_DIR)/poetry.lock $(shell find src -type f)
4953
poetry build-lambda -vv
5054

5155
deploy: # Deploy the project artefact to the target environment @Pipeline

tests/integration/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import os
4+
import subprocess
45
from collections.abc import Generator
56
from pathlib import Path
67
from typing import TYPE_CHECKING, Any
@@ -131,9 +132,16 @@ def iam_role(iam_client: BaseClient) -> Generator[str]:
131132

132133

133134
@pytest.fixture(scope="session")
134-
def flask_function(lambda_client: BaseClient, iam_role: str) -> Generator[str]:
135+
def lambda_zip() -> Path:
136+
build_result = subprocess.run(["make", "build"], capture_output=True, text=True, check=False)
137+
assert build_result.returncode == 0, f"'make build' failed: {build_result.stderr}"
138+
return Path("dist/lambda.zip")
139+
140+
141+
@pytest.fixture(scope="session")
142+
def flask_function(lambda_client: BaseClient, iam_role: str, lambda_zip: Path) -> Generator[str]:
135143
function_name = "eligibility_signposting_api"
136-
with Path("dist/lambda.zip").open("rb") as zipfile:
144+
with lambda_zip.open("rb") as zipfile:
137145
lambda_client.create_function(
138146
FunctionName=function_name,
139147
Runtime="python3.13",

0 commit comments

Comments
 (0)