|
| 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 |
0 commit comments