|
| 1 | +name: nightswatch-workflow |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '10 1 * * *' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + |
| 10 | + deploy-latest-clo-us-west-2: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + env: |
| 13 | + REGION: 'us-west-2' |
| 14 | + steps: |
| 15 | + - name: Initialize build AWS credentials |
| 16 | + uses: aws-actions/configure-aws-credentials@v1 |
| 17 | + with: |
| 18 | + aws-access-key-id: ${{ secrets.BUILD_AWS_ACCESS_KEY_ID }} |
| 19 | + aws-secret-access-key: ${{ secrets.BUILD_AWS_SECRET_ACCESS_KEY }} |
| 20 | + aws-region: us-west-2 |
| 21 | + - name: Generate short sha |
| 22 | + run: | |
| 23 | + echo "CONTENT_LOCALIZATION_STACK_NAME=clsol" >> $GITHUB_ENV |
| 24 | + echo "SHORT_SHA=`git rev-parse --short HEAD`" >> $GITHUB_ENV |
| 25 | + - name: Download all workflow run artifacts |
| 26 | + uses: actions/download-artifact@v2 |
| 27 | + - name: Deploy |
| 28 | + run: | |
| 29 | + EMAIL=${{ secrets.TEST_ADMIN_EMAIL }} |
| 30 | + REGION=us-west-2 |
| 31 | + VERSION={SHORT_SHA} |
| 32 | + TEMPLATE=https://solutions-reference.s3.amazonaws.com/content-localization-on-aws/latest/content-localization-on-aws.template |
| 33 | +
|
| 34 | + # Delete $CONTENT_LOCALIZATION_STACK_NAME if it already exists. |
| 35 | + # This is necessary in order to rerun github action workflows. |
| 36 | + # If $CONTENT_LOCALIZATION_STACK_NAME exists... |
| 37 | + if [ $(echo $(aws cloudformation list-stacks --query 'StackSummaries[?StackName==`$CONTENT_LOCALIZATION_STACK_NAME`]' --output text) | tr -d '\n' | wc -c) > 0 ]; then |
| 38 | + echo "Removing stack, $CONTENT_LOCALIZATION_STACK_NAME" |
| 39 | + aws cloudformation delete-stack --stack-name $CONTENT_LOCALIZATION_STACK_NAME --region $REGION |
| 40 | + aws cloudformation wait stack-delete-complete --stack-name $CONTENT_LOCALIZATION_STACK_NAME |
| 41 | + fi |
| 42 | +
|
| 43 | + echo "deploy cloudformation: 'aws cloudformation create-stack --stack-name $CONTENT_LOCALIZATION_STACK_NAME --template-url $TEMPLATE --region $REGION --parameters ParameterKey=AdminEmail,ParameterValue=$EMAIL ParameterKey=OpensearchNodeSize,ParameterValue=t3.small.search --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND --disable-rollback'" |
| 44 | +
|
| 45 | + aws cloudformation create-stack --stack-name $CONTENT_LOCALIZATION_STACK_NAME --template-url $TEMPLATE --region $REGION --parameters ParameterKey=AdminEmail,ParameterValue=$EMAIL ParameterKey=OpensearchNodeSize,ParameterValue=t3.small.search --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND --disable-rollback |
| 46 | + aws cloudformation wait stack-create-complete --stack-name $CONTENT_LOCALIZATION_STACK_NAME |
| 47 | + status=$(aws cloudformation describe-stacks --stack-name $CONTENT_LOCALIZATION_STACK_NAME --query 'Stacks[0].StackStatus') |
| 48 | + while [ "$status" == "CREATE_IN_PROGRESS" ]; do aws cloudformation wait stack-create-complete --stack-name $CONTENT_LOCALIZATION_STACK_NAME; status=$(aws cloudformation describe-stacks --stack-name $CONTENT_LOCALIZATION_STACK_NAME --query 'Stacks[0].StackStatus'); done |
| 49 | + echo "Create stack $CONTENT_LOCALIZATION_STACK_NAME status: $status" |
| 50 | + exit 0 |
| 51 | +
|
| 52 | + - name: Build Failed |
| 53 | + if: ${{ failure() }} |
| 54 | + uses: nashmaniac/create-issue-action@v1.1 |
| 55 | + with: |
| 56 | + title: Nightswatch deploy for Content Localization failed |
| 57 | + token: ${{secrets.GITHUB_TOKEN}} |
| 58 | + assignees: ianwow |
| 59 | + labels: bug |
| 60 | + body: Nightswatch deploy for Content Localization failed |
| 61 | + |
| 62 | + test-content-localization-us-west-2: |
| 63 | + needs: deploy-latest-clo-us-west-2 |
| 64 | + runs-on: ubuntu-latest |
| 65 | + env: |
| 66 | + MIE_REGION: 'us-west-2' |
| 67 | + steps: |
| 68 | + - name: Check out release branch |
| 69 | + uses: actions/checkout@v2.3.4 |
| 70 | + with: |
| 71 | + ref: main |
| 72 | + |
| 73 | + - name: Initialize test AWS credentials |
| 74 | + uses: aws-actions/configure-aws-credentials@v1 |
| 75 | + with: |
| 76 | + aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY_ID }} |
| 77 | + aws-secret-access-key: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }} |
| 78 | + aws-region: us-west-2 |
| 79 | + |
| 80 | + - name: Generate short sha |
| 81 | + run: | |
| 82 | + echo "CONTENT_LOCALIZATION_STACK_NAME=clsol" >> $GITHUB_ENV |
| 83 | + - name: Run cfn_nag |
| 84 | + uses: stelligent/cfn_nag@master |
| 85 | + continue-on-error: true |
| 86 | + with: |
| 87 | + input_path: deployment |
| 88 | + - name: Initialize build AWS credentials |
| 89 | + uses: aws-actions/configure-aws-credentials@v1 |
| 90 | + with: |
| 91 | + aws-access-key-id: ${{ secrets.BUILD_AWS_ACCESS_KEY_ID }} |
| 92 | + aws-secret-access-key: ${{ secrets.BUILD_AWS_SECRET_ACCESS_KEY }} |
| 93 | + aws-region: us-west-2 |
| 94 | + - name: Setup Chromedriver |
| 95 | + uses: nanasess/setup-chromedriver@master |
| 96 | + - name: Get user pool id |
| 97 | + run: | |
| 98 | + aws cloudformation describe-stacks --query 'Stacks[?starts_with(StackName, `clsol-AuthStack`)].Outputs[1].OutputValue' --output text --region us-west-2 |
| 99 | + echo "USER_POOL_ID=`aws cloudformation describe-stacks --query 'Stacks[?starts_with(StackName, \`clsol-AuthStack\`)].Outputs[1].OutputValue' --output text --region us-west-2`" >> $GITHUB_ENV |
| 100 | + - name: Reset CL user password |
| 101 | + run: | |
| 102 | + aws cognito-idp admin-set-user-password --user-pool-id $USER_POOL_ID --username ${{ secrets.TEST_ADMIN_EMAIL }} --password ${{ secrets.TEST_ADMIN_PASSWORD }} --permanent --region us-west-2 |
| 103 | + - name: Get MIE stack name |
| 104 | + run: | |
| 105 | + echo "MIE_STACK_NAME=`aws cloudformation describe-stacks --region us-west-2 --query 'sort_by(Stacks[?starts_with(StackName, \`clsol-MieStack\`)].{StackName: StackName, CreationTime: CreationTime}, &CreationTime)[0].StackName' --output text`" >> $GITHUB_ENV |
| 106 | + - name: Get Content Localization endpoint |
| 107 | + run: | |
| 108 | + echo "APP_ENDPOINT=`aws cloudformation describe-stacks --query 'Stacks[?starts_with(StackName, \`clsol-WebStack\`)].Outputs[0].OutputValue' --output text`" >> $GITHUB_ENV |
| 109 | + - name: Set admin creds |
| 110 | + run: | |
| 111 | + echo APP_USERNAME=${{ secrets.TEST_ADMIN_EMAIL }} >> $GITHUB_ENV |
| 112 | + echo APP_PASSWORD=${{ secrets.TEST_ADMIN_PASSWORD }} >> $GITHUB_ENV |
| 113 | + - name: Set media path and file name |
| 114 | + run: | |
| 115 | + echo TEST_MEDIA_PATH=$GITHUB_WORKSPACE/test/e2e/ >> $GITHUB_ENV |
| 116 | + echo TEST_FILE_NAME=run_e2e.sh >> $GITHUB_ENV |
| 117 | + - name: Initialize test AWS credentials |
| 118 | + uses: aws-actions/configure-aws-credentials@v1 |
| 119 | + with: |
| 120 | + aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY_ID }} |
| 121 | + aws-secret-access-key: ${{ secrets.TEST_AWS_SECRET_ACCESS_KEY }} |
| 122 | + aws-region: us-west-2 |
| 123 | + - name: Run e2e tests |
| 124 | + run: | |
| 125 | + cd $GITHUB_WORKSPACE |
| 126 | + cd test/e2e |
| 127 | + ./run_e2e.sh |
| 128 | + - name: Test Failed |
| 129 | + if: ${{ failure() }} |
| 130 | + uses: nashmaniac/create-issue-action@v1.1 |
| 131 | + with: |
| 132 | + title: Nightswatch test for Content Localization failed |
| 133 | + token: ${{secrets.GITHUB_TOKEN}} |
| 134 | + assignees: ianwow |
| 135 | + labels: bug |
| 136 | + body: Nightswatch test for Content Localization failed |
| 137 | + - name: Initialize build AWS credentials |
| 138 | + uses: aws-actions/configure-aws-credentials@v1 |
| 139 | + with: |
| 140 | + aws-access-key-id: ${{ secrets.BUILD_AWS_ACCESS_KEY_ID }} |
| 141 | + aws-secret-access-key: ${{ secrets.BUILD_AWS_SECRET_ACCESS_KEY }} |
| 142 | + aws-region: us-west-2 |
| 143 | + - name: Delete stacks |
| 144 | + run: | |
| 145 | + aws cloudformation delete-stack --stack-name $CONTENT_LOCALIZATION_STACK_NAME |
| 146 | + aws cloudformation wait stack-delete-complete --stack-name $CONTENT_LOCALIZATION_STACK_NAME |
0 commit comments