Skip to content

Commit 3715ed2

Browse files
bchamppParidelPooya
authored andcommitted
wip: create GitHub action for deploying samples to AWS (#11)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. ### Issue Link, if available N/A ### Description Adding a GitHub Action workflow which fans out the "examples" catalog and does the following: 1. Builds the Lambda Function ZIP folder, 2. Creates the Function in Lambda (using `aws cli` currently) -- the function is suffixed with `-PR-##`, 3. Tests the function (no-op currently, will iterate in another PR), 4. Deletes the function ### Demo/Screenshots See GitHub workflow that ran! ### Checklist - [X] I have filled out every section of the PR template - [X] I have thoroughly tested this change
1 parent 03e6d00 commit 3715ed2

File tree

2 files changed

+146
-1
lines changed

2 files changed

+146
-1
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [ "main", "development" ]
6+
paths:
7+
- 'packages/lambda-durable-functions-sdk-js/**'
8+
- 'packages/examples/**'
9+
- '.github/workflows/integration-tests.yml'
10+
pull_request:
11+
branches: [ "main", "development" ]
12+
paths:
13+
- 'packages/lambda-durable-functions-sdk-js/**'
14+
- 'packages/examples/**'
15+
- '.github/workflows/integration-tests.yml'
16+
workflow_dispatch:
17+
18+
env:
19+
AWS_REGION: us-west-2
20+
21+
jobs:
22+
setup:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
examples: ${{ steps.get-examples.outputs.examples }}
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: '22.x'
33+
cache: 'npm'
34+
35+
- name: Install dependencies
36+
run: npm run install-all
37+
38+
- name: Build project
39+
run: npm run build
40+
41+
- name: Upload build artifacts
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: built-examples
45+
path: |
46+
packages/examples/dist/
47+
packages/examples/node_modules/
48+
49+
- name: Get examples from catalog
50+
id: get-examples
51+
working-directory: ./packages/examples
52+
run: |
53+
echo "examples=$(jq -c '.examples' examples-catalog.json)" >> $GITHUB_OUTPUT
54+
55+
integration-test:
56+
needs: setup
57+
runs-on: ubuntu-latest
58+
name: ${{ matrix.example.name }}
59+
strategy:
60+
matrix:
61+
example: ${{ fromJson(needs.setup.outputs.examples) }}
62+
fail-fast: false
63+
64+
steps:
65+
- uses: actions/checkout@v4
66+
67+
- name: Download build artifacts
68+
uses: actions/download-artifact@v4
69+
with:
70+
name: built-examples
71+
path: packages/examples/
72+
73+
- name: Configure AWS credentials
74+
uses: aws-actions/configure-aws-credentials@v4
75+
with:
76+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
77+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
78+
aws-region: ${{ env.AWS_REGION }}
79+
80+
- name: Deploy Lambda function - ${{ matrix.example.name }}
81+
working-directory: ./packages/examples
82+
env:
83+
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
84+
run: |
85+
BASE_NAME=$(echo "${{ matrix.example.name }}" | sed 's/ //g')-TypeScript
86+
if [ "${{ github.event_name }}" = "pull_request" ]; then
87+
FUNCTION_NAME="${BASE_NAME}-PR-${{ github.event.number }}"
88+
else
89+
FUNCTION_NAME="${BASE_NAME}"
90+
fi
91+
echo "FUNCTION_NAME=$FUNCTION_NAME" >> $GITHUB_ENV
92+
93+
ROLE_ARN="arn:aws:iam::${AWS_ACCOUNT_ID}:role/DurableFunctionsIntegrationTestRole"
94+
95+
echo "Packaging Lambda function..."
96+
# Create a temporary directory for this specific function
97+
mkdir -p temp-package
98+
99+
# Copy the specific example file
100+
HANDLER_FILE=$(echo "${{ matrix.example.handler }}" | sed 's/\.handler$//')
101+
cp dist/examples/${HANDLER_FILE}.js temp-package/
102+
cp dist/examples/${HANDLER_FILE}.js.map temp-package/ 2>/dev/null || true
103+
104+
# Copy node_modules
105+
cp -r node_modules temp-package/
106+
107+
# Create zip from temp directory
108+
cd temp-package
109+
zip -r ../lambda-function.zip .
110+
cd ..
111+
rm -rf temp-package
112+
113+
echo "Deploying function: $FUNCTION_NAME with handler: ${{ matrix.example.handler }}"
114+
115+
if aws lambda get-function --function-name "$FUNCTION_NAME" --region "${{ env.AWS_REGION }}" >/dev/null 2>&1; then
116+
echo "Updating existing function: $FUNCTION_NAME"
117+
aws lambda update-function-code \
118+
--function-name "$FUNCTION_NAME" \
119+
--zip-file fileb://lambda-function.zip \
120+
--region "${{ env.AWS_REGION }}"
121+
else
122+
echo "Creating new function: $FUNCTION_NAME"
123+
aws lambda create-function \
124+
--function-name "$FUNCTION_NAME" \
125+
--runtime nodejs22.x \
126+
--role "$ROLE_ARN" \
127+
--handler "${{ matrix.example.handler }}" \
128+
--zip-file fileb://lambda-function.zip \
129+
--timeout 60 \
130+
--memory-size 128 \
131+
--region "${{ env.AWS_REGION }}"
132+
fi
133+
134+
- name: Test Lambda function - ${{ matrix.example.name }}
135+
run: |
136+
echo "Testing function: $FUNCTION_NAME"
137+
# TODO: Add testing logic here
138+
139+
- name: Cleanup Lambda function
140+
if: always()
141+
run: |
142+
echo "Deleting function: $FUNCTION_NAME"
143+
aws lambda delete-function \
144+
--function-name "$FUNCTION_NAME" \
145+
--region "${{ env.AWS_REGION }}" || echo "Function already deleted or doesn't exist"

.github/workflows/node.js.yml renamed to .github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
33

4-
name: Node.js CI
4+
name: Unit Tests
55

66
on:
77
push:

0 commit comments

Comments
 (0)