Skip to content

Commit d63884e

Browse files
authored
Feature/multi projects (#3)
* Add support for building multiple Lambda functions and install jq * Refactor Lambda packaging logic to improve function handling * Comment out unused build and test steps in the CI configuration * Add debug output for dotnet version in Lambda function input parsing * Refactor CI configuration to enable building and packaging of Lambda functions * Refactor Lambda build process to enhance packaging output and add dotnet version checks * Remove commented-out export of dotnet path in CI build configuration * Add debug output for function packaging details in CI configuration * Update CI configuration to include dotnet tools in PATH for Lambda packaging * Add current working directory output to CI build process for debugging * Refactor Lambda packaging script to improve variable handling and remove unnecessary debug output * Fix packaging path variable in Lambda build script for correct function packaging * Refactor build scripts to support multiple Lambda functions packaging and remove deprecated inputs
1 parent aebd569 commit d63884e

3 files changed

Lines changed: 50 additions & 26 deletions

File tree

.github/workflows/build-deploy.yaml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ on:
1111
description: "Solution file name"
1212
required: false
1313
type: string
14-
functionPath:
15-
description: "Path to the API project"
16-
required: false
17-
type: string
18-
functionName:
19-
description: "Name of the API"
20-
required: false
21-
type: string
2214
buildPlatform:
2315
description: "Build platform"
2416
required: false
@@ -63,6 +55,11 @@ on:
6355
description: "Name of the AWS CDK stack"
6456
required: false
6557
type: string
58+
functions:
59+
description: "JSON array of Lambda functions to build"
60+
required: false
61+
type: string
62+
default: '[]' # e.g. [{"path": "src/Foo", "name": "foo-func"}, {"path": "src/Bar", "name": "bar-func"}]
6663

6764
permissions:
6865
id-token: write
@@ -102,7 +99,7 @@ jobs:
10299
run: dotnet test --no-restore
103100

104101
- name: Setup Local .NET Tools
105-
if: inputs.functionPath != '' && inputs.functionName != ''
102+
if: inputs.functions != '[]'
106103
run: |
107104
dotnet new tool-manifest --force
108105
dotnet tool install Amazon.Lambda.Tools
@@ -111,9 +108,25 @@ jobs:
111108
if: inputs.webPath != ''
112109
run: dotnet publish ${{ inputs.webPath }} --configuration ${{ inputs.buildConfiguration }} --no-restore --output ${{ env.outputPath }}
113110

114-
- name: Build and Package Lambda Function Code
115-
if: inputs.functionPath != '' && inputs.functionName != ''
116-
run: dotnet tool run dotnet-lambda package -pl ${{ inputs.functionPath }} --configuration ${{ inputs.buildConfiguration }} --no-restore --framework ${{ inputs.lambdaRuntimeVersion }} --output-package ${{ env.outputPath }}/${{ inputs.functionName }}.zip
111+
- name: Install jq
112+
if: inputs.functions != '[]'
113+
run: sudo apt-get update && sudo apt-get install -y jq
114+
115+
- name: Build and Package All Lambda Functions
116+
run: |
117+
FUNCTIONS='${{ inputs.functions }}'
118+
COUNT=$(echo "$FUNCTIONS" | jq length)
119+
120+
for i in $(seq 0 $((COUNT - 1))); do
121+
NAME=$(echo "$FUNCTIONS" | jq -r ".[$i].name")
122+
FUNC_PATH=$(echo "$FUNCTIONS" | jq -r ".[$i].path")
123+
ZIP_PATH="${{ env.outputPath }}/${NAME}.zip"
124+
125+
echo "Packaging $NAME from FUNC_PATH..."
126+
dotnet tool run dotnet-lambda package -pl "$FUNC_PATH" --configuration ${{ inputs.buildConfiguration }} --no-restore --framework ${{ inputs.lambdaRuntimeVersion }} --output-package "$ZIP_PATH"
127+
128+
echo "Packaged: $ZIP_PATH"
129+
done
117130
118131
- name: Setup Node.js
119132
if: inputs.runCdk == true

.github/workflows/pr-build.yaml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ on:
1111
description: "Solution file name"
1212
required: false
1313
type: string
14-
functionPath:
15-
description: "Path to the function project"
16-
required: false
17-
type: string
18-
functionName:
19-
description: "Name of the function"
20-
required: false
21-
type: string
2214
buildPlatform:
2315
description: "Build platform"
2416
required: false
@@ -59,7 +51,11 @@ on:
5951
required: false
6052
default: true
6153
type: boolean
62-
54+
functions:
55+
description: "JSON array of Lambda functions to build"
56+
required: false
57+
type: string
58+
default: '[]' # e.g. [{"path": "src/Foo", "name": "foo-func"}, {"path": "src/Bar", "name": "bar-func"}]
6359
permissions:
6460
id-token: write
6561
contents: write
@@ -95,7 +91,7 @@ jobs:
9591
run: dotnet test --no-restore
9692

9793
- name: Setup Local .NET Tools
98-
if: inputs.functionPath != '' && inputs.functionName != ''
94+
if: inputs.functions != '[]'
9995
run: |
10096
dotnet new tool-manifest --force
10197
dotnet tool install Amazon.Lambda.Tools
@@ -104,9 +100,25 @@ jobs:
104100
if: inputs.webPath != ''
105101
run: dotnet publish ${{ inputs.webPath }} --configuration ${{ inputs.buildConfiguration }} --no-restore --output ${{ env.outputPath }}
106102

107-
- name: Build and Package Lambda Function Code
108-
if: inputs.functionPath != '' && inputs.functionName != ''
109-
run: dotnet tool run dotnet-lambda package -pl ${{ inputs.functionPath }} --configuration ${{ inputs.buildConfiguration }} --no-restore --framework ${{ inputs.lambdaRuntimeVersion }} --output-package ${{ env.outputPath }}/${{ inputs.functionName }}.zip
103+
- name: Install jq
104+
if: inputs.functions != '[]'
105+
run: sudo apt-get update && sudo apt-get install -y jq
106+
107+
- name: Build and Package All Lambda Functions
108+
run: |
109+
FUNCTIONS='${{ inputs.functions }}'
110+
COUNT=$(echo "$FUNCTIONS" | jq length)
111+
112+
for i in $(seq 0 $((COUNT - 1))); do
113+
NAME=$(echo "$FUNCTIONS" | jq -r ".[$i].name")
114+
FUNC_PATH=$(echo "$FUNCTIONS" | jq -r ".[$i].path")
115+
ZIP_PATH="${{ env.outputPath }}/${NAME}.zip"
116+
117+
echo "Packaging $NAME from FUNC_PATH..."
118+
dotnet tool run dotnet-lambda package -pl "$FUNC_PATH" --configuration ${{ inputs.buildConfiguration }} --no-restore --framework ${{ inputs.lambdaRuntimeVersion }} --output-package "$ZIP_PATH"
119+
120+
echo "Packaged: $ZIP_PATH"
121+
done
110122
111123
- name: Setup Node.js
112124
if: inputs.runCdk == true

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ jobs:
2525
outputPath: 'publish'
2626
hasTests: true
2727
runCdk: true
28-
serverlessDeploy: false
2928
```
3029
3130
## Permissions

0 commit comments

Comments
 (0)