Skip to content

Commit 0ae4282

Browse files
authored
Add in Python Build for GitHub Actions (#125)
* Add Python Build * check for requirements.txt * config was pointing to python folder instead of the_basic_mq * Add in missing dependencies * Support multiple python stacks * Update the_alexa_skill_stack.py * Make tsc more specific * hide lambda stdout compile logs * add respository to lambda fn * move ts build to external file
1 parent d420121 commit 0ae4282

File tree

10 files changed

+57
-22
lines changed

10 files changed

+57
-22
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ jobs:
2424
steps:
2525
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
2626
- uses: actions/checkout@v2
27+
28+
# Validate Python Patterns
29+
- name: Build/Synth Python Patterns
30+
run: ./build-python.sh
2731

28-
# Runs a single command using the runners shell
29-
- name: Parse info.json and run TS tests
30-
run: |
31-
readarray -t arr < <(jq -r '.[] | keys | .[]' info.json);
32-
for i in "${arr[@]}"
33-
do
34-
cd $i/typescript;
35-
npm i;
36-
npm run build;
37-
npm run test;
38-
cd ../../;
39-
done
32+
# Validate TypeScript Patterns
33+
- name: Build/Test TypeScript Patterns
34+
run: ./build-typescript.sh
35+
36+

build-python.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
readarray -t patterns < <(jq -r '.[] | keys | .[]' info.json);
2+
for pattern in "${patterns[@]}"
3+
do
4+
cd $pattern/python;
5+
if test -f "requirements.txt"; then
6+
python3 -m venv .env;
7+
source .env/bin/activate;
8+
pip3 install -r requirements.txt;
9+
readarray -t stacks < <(npx -q cdk ls);
10+
for stack in "${stacks[@]}"
11+
do
12+
echo "npx cdk synth $stack";
13+
npx cdk synth "$stack";
14+
done
15+
deactivate
16+
fi
17+
cd ../../;
18+
done

build-typescript.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
readarray -t arr < <(jq -r '.[] | keys | .[]' info.json);
2+
for i in "${arr[@]}"
3+
do
4+
cd $i/typescript;
5+
npm i;
6+
npm run build;
7+
npm run test;
8+
cd ../../;
9+
done

the-alexa-skill/python/lambda_fns/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "alexa",
33
"version": "1.0.0",
44
"description": "lambda for Alexa backend",
5+
"repository": "https://github.com/cdk-patterns/serverless.git",
56
"main": "lambda.ts",
67
"scripts": {
78
"build": "tsc lambda.ts",

the-alexa-skill/python/the_alexa_skill/the_alexa_skill_stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
4848

4949
# install node dependencies for lambdas
5050
lambda_folder = os.path.dirname(os.path.realpath(__file__)) + "/../lambda_fns"
51-
subprocess.check_call("npm i".split(), cwd=lambda_folder)
52-
subprocess.check_call("npm run build".split(), cwd=lambda_folder)
51+
subprocess.check_call("npm i".split(), cwd=lambda_folder, stdout=subprocess.DEVNULL)
52+
subprocess.check_call("npm run build".split(), cwd=lambda_folder, stdout=subprocess.DEVNULL)
5353

5454
alexa_lambda = _lambda.Function(self, "AlexaLambdaHandler",
5555
runtime=_lambda.Runtime.NODEJS_12_X,

the-basic-mq/python/setup.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
setuptools.setup(
9-
name="python",
9+
name="basicmq",
1010
version="0.0.1",
1111

1212
description="An empty CDK Python app",
@@ -15,11 +15,20 @@
1515

1616
author="author",
1717

18-
package_dir={"": "python"},
19-
packages=setuptools.find_packages(where="python"),
18+
package_dir={"": "the_basic_mq"},
19+
packages=setuptools.find_packages(where="the_basic_mq"),
2020

2121
install_requires=[
2222
"aws-cdk.core==1.51.0",
23+
"aws-cdk.aws-route53==1.51.0",
24+
"aws-cdk.aws-route53-targets==1.51.0",
25+
"aws-cdk.aws-certificatemanager==1.51.0",
26+
"aws-cdk.aws-ec2==1.51.0",
27+
"aws-cdk.aws-ssm==1.51.0",
28+
"aws-cdk.aws-amazonmq==1.51.0",
29+
"aws-cdk.aws-elasticloadbalancingv2==1.51.0",
30+
"aws-cdk.aws-elasticloadbalancingv2-targets==1.51.0",
31+
"aws-cdk.custom-resources==1.51.0"
2332
],
2433

2534
python_requires=">=3.6",

the-lambda-circuit-breaker/python/lambda_fns/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "1.0.0",
44
"description": "this is an unreliable lambda with a circuit breaker",
55
"main": "unreliable.js",
6+
"repository": "https://github.com/cdk-patterns/serverless.git",
67
"scripts": {
7-
"build": "tsc",
8+
"build": "tsc unreliable.ts",
89
"test": "echo \"Error: no test specified\" && exit 1"
910
},
1011
"author": "nideveloper",

the-lambda-circuit-breaker/python/the_lambda_circuit_breaker/the_lambda_circuit_breaker_stack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
2121

2222
# install node dependencies for lambdas
2323
lambda_folder = os.path.dirname(os.path.realpath(__file__)) + "/../lambda_fns"
24-
subprocess.check_call("npm i".split(), cwd=lambda_folder)
25-
subprocess.check_call("npm run build".split(), cwd=lambda_folder)
24+
subprocess.check_call("npm i".split(), cwd=lambda_folder, stdout=subprocess.DEVNULL)
25+
subprocess.check_call("npm run build".split(), cwd=lambda_folder, stdout=subprocess.DEVNULL)
2626

2727
# defines an AWS Lambda resource with unreliable code
2828
unreliable_lambda = _lambda.Function(self, "UnreliableLambdaHandler",

the-rds-proxy/python/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from the_rds_proxy.the_rds_proxy_stack import TheRdsProxyStack
66

77
# install node dependencies for lambdas
8-
subprocess.check_call("npm i".split(), cwd="lambda_fns/rds")
8+
subprocess.check_call("npm i".split(), cwd="lambda_fns/rds", stdout=subprocess.DEVNULL)
99

1010
app = core.App()
1111
TheRdsProxyStack(app, "the-rds-proxy", env=core.Environment(region="us-east-1"))

the-xray-tracer/python/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from the_xray_tracer.the_sqs_flow_stack import TheSqsFlowStack
1010

1111
# install node dependencies for lambdas
12-
subprocess.check_call("npm i".split(), cwd="lambda_fns")
12+
subprocess.check_call("npm i".split(), cwd="lambda_fns", stdout=subprocess.DEVNULL)
1313

1414
app = core.App()
1515
xray_tracer = TheXrayTracerStack(app, "the-xray-tracer")

0 commit comments

Comments
 (0)