Skip to content

Commit cf151f2

Browse files
authored
Merge pull request #318 from aws-samples/acceptance-testing
Add acceptance tests pipeline and Github actions for building microservices
2 parents 396cb48 + 510c708 commit cf151f2

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: acceptance-testing
2+
3+
on:
4+
# this will allow to run test on main and not modify the status badge when opening a PR
5+
push:
6+
7+
concurrency:
8+
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
9+
cancel-in-progress: false
10+
11+
permissions:
12+
id-token: write
13+
contents: read
14+
15+
jobs:
16+
trigger-code-pipeline:
17+
runs-on: ubuntu-latest
18+
name: Trigger AWS CodePipeline
19+
environment: acceptance
20+
steps:
21+
- name: Configure AWS credentials from Test account
22+
uses: aws-actions/configure-aws-credentials@v4
23+
with:
24+
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
25+
aws-region: us-east-2
26+
role-duration-seconds: 3600
27+
role-session-name: GithubActions-Session
28+
29+
- name: Run AWS Pipeline
30+
run: |
31+
echo "Triggering AWS Pipeline"
32+
aws codepipeline start-pipeline-execution --name ${{ secrets.PIPELINE_NAME }} \
33+
--region us-east-2 \
34+
--variables name=GithubUser,value=${{ github.repository_owner }} name=GithubBranch,value=${{ github.ref_name }} \
35+
--output text \
36+
--query 'pipelineExecutionId'
37+
sleep 30
38+
39+
- name: Check CFN Status
40+
run: |
41+
while true; do
42+
# Check if the stack exists and get its status
43+
STACK_STATUS=$(aws cloudformation describe-stacks \
44+
--stack-name "Observability-Workshop" \
45+
--query 'Stacks[0].StackStatus' \
46+
--output text 2>/dev/null || echo "STACK_NOT_FOUND")
47+
48+
if [ "$STACK_STATUS" == "STACK_NOT_FOUND" ]; then
49+
echo "Stack 'Observability-Workshop' not found yet. Waiting..."
50+
else
51+
echo "Stack 'Observability-Workshop' status: $STACK_STATUS"
52+
53+
# Check if the stack is in a completed state
54+
if [[ "$STACK_STATUS" == *"COMPLETE"* ]]; then
55+
if [[ "$STACK_STATUS" == "CREATE_COMPLETE" || "$STACK_STATUS" == "UPDATE_COMPLETE" ]]; then
56+
echo "Stack deployment succeeded!"
57+
exit 0
58+
else
59+
echo "Stack deployment failed with status: $STACK_STATUS"
60+
exit 1
61+
fi
62+
elif [[ "$STACK_STATUS" == *"FAILED"* || "$STACK_STATUS" == *"ROLLBACK"* ]]; then
63+
echo "Stack deployment failed with status: $STACK_STATUS"
64+
exit 1
65+
fi
66+
fi
67+
echo "Waiting for stack deployment to complete..."
68+
sleep 30
69+
done

.github/workflows/build-test.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build Test
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
docker-builds:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
service:
16+
- name: payforadoption-go
17+
path: PetAdoptions/payforadoption-go
18+
- name: petadoptionshistory-py
19+
path: PetAdoptions/petadoptionshistory-py
20+
- name: petlistadoptions-go
21+
path: PetAdoptions/petlistadoptions-go
22+
- name: petsearch-java
23+
path: PetAdoptions/petsearch-java
24+
- name: petsite
25+
path: PetAdoptions/petsite/petsite
26+
- name: trafficgenerator
27+
path: PetAdoptions/trafficgenerator/trafficgenerator
28+
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v2
34+
35+
- name: Build ${{ matrix.service.name }}
36+
uses: docker/build-push-action@v4
37+
with:
38+
context: ${{ matrix.service.path }}
39+
push: false
40+
load: true
41+
tags: ${{ matrix.service.name }}:test
42+
cache-from: type=gha
43+
cache-to: type=gha,mode=max
44+
45+
nodejs-build:
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v3
49+
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v3
52+
with:
53+
node-version: '16'
54+
cache: 'npm'
55+
cache-dependency-path: PetAdoptions/petstatusupdater/package-lock.json
56+
57+
- name: Install dependencies
58+
run: npm ci
59+
working-directory: PetAdoptions/petstatusupdater
60+
61+
- name: Verify build
62+
run: npm run build --if-present
63+
working-directory: PetAdoptions/petstatusupdater
64+
65+
dotnet-builds:
66+
runs-on: ubuntu-latest
67+
strategy:
68+
fail-fast: false
69+
matrix:
70+
project:
71+
- name: petsite
72+
path: PetAdoptions/petsite/petsite.sln
73+
- name: trafficgenerator
74+
path: PetAdoptions/trafficgenerator/trafficgenerator.sln
75+
76+
steps:
77+
- uses: actions/checkout@v3
78+
79+
- name: Setup .NET
80+
uses: actions/setup-dotnet@v3
81+
with:
82+
dotnet-version: '7.0.x'
83+
84+
- name: Restore dependencies
85+
run: dotnet restore ${{ matrix.project.path }}
86+
87+
- name: Build
88+
run: dotnet build ${{ matrix.project.path }} --no-restore

0 commit comments

Comments
 (0)