Skip to content

Commit bd27a4d

Browse files
authored
Run Greengrass samples in CI (#717)
- Add tests for Greengrass samples: IPC and discovery. - Add new CI job for Greengrass tests. - Fix greengrass-discovery sample to iterate over all connections it discovered. - Add to run_in_ci.py script a possibility to provide data to runnable's stdin.
1 parent eaea863 commit bd27a4d

File tree

23 files changed

+901
-212
lines changed

23 files changed

+901
-212
lines changed

.builder/actions/build_gg_samples.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0.
3+
4+
import Builder
5+
import os
6+
7+
8+
class BuildGGSamples(Builder.Action):
9+
"""
10+
Defines a custom build step for Greengrass samples.
11+
It's used via builder.json config file in the project root directory.
12+
"""
13+
14+
def run(self, env):
15+
# parse extra cmake configs
16+
cmd_args = env.args
17+
18+
steps = []
19+
samples = [
20+
'samples/greengrass/ipc',
21+
'samples/greengrass/basic_discovery',
22+
]
23+
24+
for sample_path in samples:
25+
build_path = os.path.join('build', sample_path)
26+
steps.append(['cmake',
27+
f'-B{build_path}',
28+
f'-H{sample_path}',
29+
f'-DCMAKE_PREFIX_PATH={env.install_dir}',
30+
'-DCMAKE_BUILD_TYPE=RelWithDebInfo'])
31+
# append extra cmake configs
32+
steps[-1].extend(cmd_args.cmake_extra)
33+
steps.append(['cmake',
34+
'--build', build_path,
35+
'--config', 'RelWithDebInfo'])
36+
37+
return Builder.Script(steps)

.builder/actions/build_samples.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0.
3+
14
import Builder
25
import os
36
import sys
4-
import argparse
57

68

79
class BuildSamples(Builder.Action):
10+
"""
11+
Defines a custom build step for samples and tests.
12+
It's used via builder.json config file in the project root directory.
13+
"""
14+
815
def run(self, env):
916
# parse extra cmake configs
1017
cmd_args = env.args

.github/workflows/ci.yml

+60-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ env:
3737
CI_X509_ROLE: arn:aws:iam::180635532705:role/CI_X509_Role
3838
CI_MQTT5_ROLE: arn:aws:iam::180635532705:role/CI_MQTT5_Role
3939
CI_GREENGRASS_ROLE: arn:aws:iam::180635532705:role/CI_Greengrass_Role
40+
CI_GREENGRASS_INSTALLER_ROLE: arn:aws:iam::180635532705:role/CI_GreengrassInstaller_Role
4041
CI_JOBS_SERVICE_CLIENT_ROLE: arn:aws:iam::180635532705:role/CI_JobsServiceClient_Role
4142
CI_SHADOW_SERVICE_CLIENT_ROLE: arn:aws:iam::180635532705:role/CI_ShadowServiceClient_Role
4243

@@ -641,14 +642,66 @@ jobs:
641642
- name: run X509 sample
642643
run: |
643644
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_x509_connect_cfg.json
644-
- name: configure AWS credentials (Greengrass)
645-
uses: aws-actions/configure-aws-credentials@v2
646-
with:
647-
role-to-assume: ${{ env.CI_GREENGRASS_ROLE }}
648-
aws-region: ${{ env.AWS_DEFAULT_REGION }}
649-
- name: run Greengrass Discovery sample
645+
646+
# Runs the Greengrass samples
647+
linux-greengrass-tests:
648+
runs-on: ubuntu-latest
649+
permissions:
650+
id-token: write # This is required for requesting the JWT
651+
steps:
652+
- name: Setup C++
653+
run: |
654+
sudo apt-get -qq update -y
655+
sudo apt-get -qq install -y build-essential
656+
sudo apt install cmake
657+
gcc --version
658+
cmake --version
659+
- name: Build ${{ env.PACKAGE_NAME }} + consumers
650660
run: |
651-
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_greengrass_discovery_cfg.json
661+
echo "Downloading source"
662+
git clone --recursive https://github.com/aws/aws-iot-device-sdk-cpp-v2.git --branch ${{ env.HEAD_REF || github.ref_name }}
663+
echo "Running builder"
664+
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
665+
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --variant build_gg_samples_only
666+
- name: Install Greengrass Development Kit
667+
run: |
668+
python3 -m pip install awsiotsdk
669+
python3 -m pip install -U git+https://github.com/aws-greengrass/[email protected]
670+
- name: Configure AWS credentials (Greengrass)
671+
uses: aws-actions/configure-aws-credentials@v2
672+
with:
673+
role-to-assume: ${{ env.CI_GREENGRASS_INSTALLER_ROLE }}
674+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
675+
- name: Build and run Greengrass basic discovery sample
676+
working-directory: ./aws-iot-device-sdk-cpp-v2/tests/greengrass/basic_discovery
677+
run: |
678+
gdk component build
679+
gdk test-e2e build
680+
gdk test-e2e run
681+
- name: Show logs
682+
working-directory: ./aws-iot-device-sdk-cpp-v2/tests/greengrass/basic_discovery
683+
# Print logs unconditionally to provide more details on Greengrass run even if the test failed.
684+
if: always()
685+
run: |
686+
echo "=== greengrass.log"
687+
cat testResults/gg*/greengrass.log
688+
echo "=== software.amazon.awssdk.sdk-gg-test-discovery.log"
689+
cat testResults/gg*/software.amazon.awssdk.sdk-gg-test-discovery.log
690+
- name: Build and run Greengrass IPC sample
691+
working-directory: ./aws-iot-device-sdk-cpp-v2/tests/greengrass/ipc
692+
run: |
693+
gdk component build
694+
gdk test-e2e build
695+
gdk test-e2e run
696+
- name: Show logs
697+
working-directory: ./aws-iot-device-sdk-cpp-v2/tests/greengrass/ipc
698+
# Print logs unconditionally to provide more details on Greengrass run even if the test failed.
699+
if: always()
700+
run: |
701+
echo "=== greengrass.log"
702+
cat testResults/gg*/greengrass.log
703+
echo "=== software.amazon.awssdk.sdk-gg-ipc.log"
704+
cat testResults/gg*/software.amazon.awssdk.sdk-gg-ipc.log
652705
653706
# check that docs can still build
654707
check-docs:
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
{
22
"language": "CPP",
3-
"sample_file": "./aws-iot-device-sdk-cpp-v2/build/samples/greengrass/basic_discovery/basic-discovery",
4-
"sample_region": "us-east-1",
5-
"sample_main_class": "",
3+
"runnable_file": "basic-discovery",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
66
"arguments": [
77
{
88
"name": "--cert",
9-
"secret": "ci/Greengrass/cert",
9+
"secret": "ci/GreengrassDiscovery/cert",
1010
"filename": "tmp_certificate.pem"
1111
},
1212
{
1313
"name": "--key",
14-
"secret": "ci/Greengrass/key",
14+
"secret": "ci/GreengrassDiscovery/key",
1515
"filename": "tmp_key.pem"
1616
},
1717
{
18-
"name": "--ca_file",
19-
"secret": "ci/Greengrass/ca",
20-
"filename": "tmp_ca.pem"
18+
"name": "--thing_name",
19+
"data": "CI_Greengrass_Discovery_Thing"
2120
},
2221
{
2322
"name": "--region",
2423
"data": "us-east-1"
2524
},
2625
{
27-
"name": "--thing_name",
28-
"data": "CI_GreenGrass_Thing"
29-
},
30-
{
31-
"name": "--is_ci",
32-
"data": "true"
26+
"name": "--topic",
27+
"data": "clients/CI_Greengrass_Discovery_Thing/hello/world/$INPUT_UUID"
3328
},
3429
{
35-
"name": "--print_discover_resp_only",
36-
"data": ""
30+
"name": "--mode",
31+
"data": "publish"
3732
}
38-
]
33+
],
34+
"stdin_file": "messages.txt"
3935
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"language": "CPP",
3+
"runnable_file": "greengrass-ipc",
4+
"runnable_region": "us-east-1",
5+
"runnable_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--topic",
9+
"data": "test/gg-ipc-topic"
10+
},
11+
{
12+
"name": "--message",
13+
"data": "hello"
14+
},
15+
{
16+
"name": "--is_ci",
17+
"data": "true"
18+
}
19+
20+
]
21+
}

builder.json

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
"!build_steps": [
2929
"build"
3030
]
31+
},
32+
"build_gg_samples_only": {
33+
"!build_steps": [
34+
"build",
35+
"build-gg-samples"
36+
]
3137
}
3238
}
3339
}

0 commit comments

Comments
 (0)