Skip to content

Commit 51bbdea

Browse files
committed
chore(ci): add new GH action for service check batch and e2e tests
1 parent 7d51339 commit 51bbdea

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
3+
error_exit() {
4+
echo "$1" 1>&2
5+
exit 1
6+
}
7+
8+
PROJECT_NAME=$1
9+
# get the source version to be built (defaults to main branch if not specified)
10+
SOURCE_VERSION=${2:-main}
11+
12+
echo "Starting CodeBuild project ${PROJECT_NAME}"
13+
14+
# dump all GITHUB_* environment variables to file and pass to start job
15+
jq -n 'env | to_entries | [.[] | select(.key | startswith("GITHUB_"))] | [.[] | {name: .key, value:.value, type:"PLAINTEXT"}]' >/tmp/gh_env_vars.json
16+
17+
START_RESULT=$(
18+
aws codebuild start-build-batch \
19+
--project-name ${PROJECT_NAME} \
20+
--source-version $SOURCE_VERSION \
21+
--environment-variables-override file:///tmp/gh_env_vars.json
22+
)
23+
24+
if [ "$?" != "0" ]; then
25+
error_exit "Could not start project. Exiting."
26+
else
27+
echo "Build started successfully."
28+
fi
29+
30+
BUILD_ID=$(echo ${START_RESULT} | jq '.buildBatch.id' -r)
31+
echo "Build id $BUILD_ID"
32+
33+
BUILD_STATUS="IN_PROGRESS"
34+
while [ "$BUILD_STATUS" == "IN_PROGRESS" ]; do
35+
echo "Checking build status."
36+
BUILD=$(aws codebuild batch-get-build-batches --ids ${BUILD_ID})
37+
BUILD_STATUS=$(echo $BUILD | jq '.buildBatches[0].buildBatchStatus' -r)
38+
39+
JOBS=$(echo $BUILD | jq '.buildBatches[0].buildGroups | [.[] | {identifier: .identifier, status: .currentBuildSummary.buildStatus} | select(.identifier | startswith("JOB"))]')
40+
TOTAL_JOBS=$(echo $JOBS | jq 'length')
41+
42+
SUCCEEDED_CNT=$(echo $JOBS | jq '[.[] | select(.status == "SUCCEEDED")] | length')
43+
IN_PROGRESS_CNT=$(echo $JOBS | jq '[.[] | select(.status == "IN_PROGRESS")] | length')
44+
45+
FAILED_CNT=$(($TOTAL_JOBS - $SUCCEEDED_CNT - $IN_PROGRESS_CNT))
46+
47+
if [ "$BUILD_STATUS" == "IN_PROGRESS" ]; then
48+
echo "Build is still in progress (failed=$FAILED_CNT; in_progress=$IN_PROGRESS_CNT; succeeded=$SUCCEEDED_CNT; total=$TOTAL_JOBS), waiting..."
49+
50+
fi
51+
sleep 10
52+
done
53+
54+
if [ "$BUILD_STATUS" != "SUCCEEDED" ]; then
55+
BUILD=$(aws codebuild batch-get-build-batches --ids ${BUILD_ID})
56+
FAILED_BUILDS=$(echo $BUILD | jq '.buildBatches[0].buildGroups | [.[] | {identifier: .identifier, status: .currentBuildSummary.buildStatus} | select(.status == "FAILED")]')
57+
echo "Failed builds in batch"
58+
echo $FAILED_BUILDS
59+
error_exit "Build failed, please review job output"
60+
else
61+
echo "Build succeeded."
62+
fi

.github/workflows/codebuild-ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: AWS CodeBuild CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
id-token: write
11+
12+
jobs:
13+
e2e-tests:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Configure AWS Credentials
17+
uses: aws-actions/configure-aws-credentials@v1
18+
with:
19+
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
20+
aws-region: us-west-2
21+
- name: Run E2E Tests
22+
uses: aws-actions/aws-codebuild-run-build@v1
23+
with:
24+
project-name: gh-aws-sdk-kotlin-e2e-tests
25+
26+
service-check-batch:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Configure AWS Credentials
30+
uses: aws-actions/configure-aws-credentials@v1
31+
with:
32+
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
33+
aws-region: us-west-2
34+
- name: Run Service Check Batch
35+
run: |
36+
.github/scripts/runCodeBuildBatchJob.sh gh-aws-sdk-kotlin-svc-check-batch ${{ github.event.pull_request.head.sha }}

0 commit comments

Comments
 (0)