Skip to content

Commit

Permalink
cd: Add smoke tests for CJS and ES modules (#395)
Browse files Browse the repository at this point in the history
Co-authored-by: Quinn Hanam <qhanam@gmail.com>
---------

Co-authored-by: Quinn Hanam <qhanam@gmail.com>
  • Loading branch information
ps863 and qhanam authored Mar 24, 2023
1 parent db07c99 commit 5e824fc
Show file tree
Hide file tree
Showing 25 changed files with 1,541 additions and 18 deletions.
46 changes: 46 additions & 0 deletions .github/scripts/build_npm_applications.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
PRE_OR_POST_RELEASE=$1
MODULE_TYPE=$2


if [ "$PRE_OR_POST_RELEASE" = "PRE" ]; then
if [ "$MODULE_TYPE" = "NPM-ES" ]; then
cd smoke/smoke-test-application-NPM-ES
npm uninstall aws-rum-web
npm run clean
npm install
npm install /home/runner/work/aws-rum-web/aws-rum-web #Install locally
npm run build
elif [ "$MODULE_TYPE" = "NPM-CJS" ]; then
cd smoke/smoke-test-application-NPM-CJS
npm uninstall aws-rum-web
npm run clean
npm install
npm install $(npm pack /home/runner/work/aws-rum-web/aws-rum-web | tail -1) #Install locally
npm run build
else
echo "Not a valid module type"
fi
elif [ "$PRE_OR_POST_RELEASE" = "POST" ]; then

if [ "$MODULE_TYPE" = "NPM-ES" ]; then
cd smoke/smoke-test-application-NPM-ES
npm uninstall aws-rum-web
npm run clean
npm install
npm install aws-rum-web #Install latest released direct from NPM
npm run build
elif [ "$MODULE_TYPE" = "NPM-CJS" ]; then
cd smoke/smoke-test-application-NPM-CJS
npm uninstall aws-rum-web
npm run clean
npm install
npm install aws-rum-web #Install latest released direct from NPM
npm run build
else
echo "Not a valid module type"
fi
else
echo "No valid option. Please provide PRE OR POST"
fi


16 changes: 14 additions & 2 deletions .github/scripts/update_smoke_test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# App monitor details
MONITOR_ID=$1
REGION=$2
GUEST_ARN=$3
Expand All @@ -6,6 +7,17 @@ ENDPOINT=$5
CDN=$6
VERSION=$(npm pkg get version | sed 's/"//g')/cwr.js
CDN+=${VERSION}
INSTALL_METHOD=$7

if [ "$INSTALL_METHOD" = "CDN" ]; then
awk '{sub(/\$MONITOR_ID/,MONITOR_ID);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub(/\$GUEST_ARN/,GUEST_ARN);sub(/\$IDENTITY_POOL/,IDENTITY_POOL);sub(/\$ENDPOINT/,ENDPOINT);}1' \
MONITOR_ID="'$MONITOR_ID'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN="'$GUEST_ARN'" IDENTITY_POOL="'$IDENTITY_POOL'" ENDPOINT="'$ENDPOINT'" app/smoke.html

MONITOR_ID="'$MONITOR_ID'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN="'$GUEST_ARN'" IDENTITY_POOL="'$IDENTITY_POOL'" ENDPOINT="'$ENDPOINT'" smoke/smoke-test-application-CDN/smoke.html
elif [ "$INSTALL_METHOD" = "NPM_ES" ]; then
awk '{sub(/\$MONITOR_ID/,MONITOR_ID);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub(/\$GUEST_ARN/,GUEST_ARN);sub(/\$IDENTITY_POOL/,IDENTITY_POOL);sub(/\$ENDPOINT/,ENDPOINT);}1' \
MONITOR_ID="'$MONITOR_ID'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN="'$GUEST_ARN'" IDENTITY_POOL="'$IDENTITY_POOL'" ENDPOINT="'$ENDPOINT'" smoke/smoke-test-application-NPM-ES/src/loader-npm-rum.ts
elif [ "$INSTALL_METHOD" = "NPM_CJS" ]; then
awk '{sub(/\$MONITOR_ID/,MONITOR_ID);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub(/\$GUEST_ARN/,GUEST_ARN);sub(/\$IDENTITY_POOL/,IDENTITY_POOL);sub(/\$ENDPOINT/,ENDPOINT);}1' \
MONITOR_ID="'$MONITOR_ID'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN="'$GUEST_ARN'" IDENTITY_POOL="'$IDENTITY_POOL'" ENDPOINT="'$ENDPOINT'" smoke/smoke-test-application-NPM-CJS/src/loader-npm-rum.ts
else
echo "No valid installation method input"
fi
14 changes: 12 additions & 2 deletions .github/scripts/upload_smoke_test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
bucket=$1
key=smoke-$(npm pkg get version | sed 's/"//g').html
aws s3api put-object --bucket $bucket --key "$key" --body processed_smoke.html --content-type "text/html"
version=$(npm pkg get version | sed 's/"//g')

# CDN
aws s3api put-object --bucket $bucket --key "smoke-$version.html" --body processed_smoke.html --content-type "text/html"

# NPM ES
aws s3api put-object --bucket $bucket --key "npm/es/$version/smoke.html" --body smoke/smoke-test-application-NPM-ES/app/smoke.html --content-type "text/html"
aws s3api put-object --bucket $bucket --key "npm/es/$version/loader_npm_rum_tmp.js" --body smoke/smoke-test-application-NPM-ES/build/dev/loader_npm_rum_tmp.js --content-type application/x-javascript

# NPM CJS
aws s3api put-object --bucket $bucket --key "npm/cjs/$version/smoke.html" --body smoke/smoke-test-application-NPM-CJS/app/smoke.html --content-type "text/html"
aws s3api put-object --bucket $bucket --key "npm/cjs/$version/loader_npm_rum_tmp.js" --body smoke/smoke-test-application-NPM-CJS/build/dev/loader_npm_rum_tmp.js --content-type application/x-javascript
91 changes: 86 additions & 5 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,37 @@ jobs:
curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r '.value' > $AWS_WEB_IDENTITY_TOKEN_FILE
- name: Update Smoke Test Application
id: update-smoke-test
- name: Update Smoke Test Application - CDN
id: update-smoke-test-cdn
run: |
chmod u+x .github/scripts/update_smoke_test.sh
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }} >> processed_smoke.html
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }} "CDN" >> processed_smoke.html
- name: Upload Smoke Test to CloudFront
- name: Update Smoke Test Application - NPM/ES
id: update-smoke-test-npm-es
run: |
chmod u+x .github/scripts/update_smoke_test.sh
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }} "NPM_ES" >> smoke/smoke-test-application-NPM-ES/src/loader-npm-rum-tmp.ts
- name: Update Smoke Test Application - NPM/CJS
id: update-smoke-test-npm-cjs
run: |
chmod u+x .github/scripts/update_smoke_test.sh
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }} "NPM_CJS" >> smoke/smoke-test-application-NPM-CJS/src/loader-npm-rum-tmp.ts
- name: Build Smoke Test Application - NPM/ES
id: build-npm-es-application-pre-release
run: |
chmod u+x .github/scripts/build_npm_applications.sh
.github/scripts/build_npm_applications.sh "PRE" "NPM-ES"
- name: Build Smoke Test Application - NPM/CJS
id: build-npm-cjs-application-pre-release
run: |
chmod u+x .github/scripts/build_npm_applications.sh
.github/scripts/build_npm_applications.sh "PRE" "NPM-CJS"
- name: Upload Smoke Tests to CloudFront
id: upload-smoke-test
run: |
chmod u+x .github/scripts/upload_smoke_test.sh
Expand All @@ -82,19 +106,76 @@ jobs:
- name: Install PlayWright
run: npx playwright install --with-deps chromium

- name: Run Smoke Test
- name: Run Smoke Test (NPM ES)
env:
URL: ${{ secrets.SMOKE_URL }}
MONITOR: ${{ secrets.SMOKE_MONITOR }}
ENDPOINT: ${{ secrets.SMOKE_ENDPOINT }}
NAME: ${{ secrets.SMOKE_MONITOR_NAME }}
INSTALL_METHOD: 'NPM-ES'
run: npm run smoke:headless
timeout-minutes: 10

- name: Fetch AWS Credentials for Smoke Test
run: |
export AWS_ROLE_ARN=${{ secrets.SMOKE_TEST_ROLE }}
export AWS_WEB_IDENTITY_TOKEN_FILE=/tmp/awscreds
export AWS_DEFAULT_REGION=us-east-1
echo AWS_WEB_IDENTITY_TOKEN_FILE=$AWS_WEB_IDENTITY_TOKEN_FILE >> $GITHUB_ENV
echo AWS_ROLE_ARN=$AWS_ROLE_ARN >> $GITHUB_ENV
echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION >> $GITHUB_ENV
curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r '.value' > $AWS_WEB_IDENTITY_TOKEN_FILE
- name: Run Smoke Test (NPM CJS)
env:
URL: ${{ secrets.SMOKE_URL }}
MONITOR: ${{ secrets.SMOKE_MONITOR }}
ENDPOINT: ${{ secrets.SMOKE_ENDPOINT }}
NAME: ${{ secrets.SMOKE_MONITOR_NAME }}
INSTALL_METHOD: 'NPM-CJS'
run: npm run smoke:headless
timeout-minutes: 10

- name: Fetch AWS Credentials for Smoke Test
run: |
export AWS_ROLE_ARN=${{ secrets.SMOKE_TEST_ROLE }}
export AWS_WEB_IDENTITY_TOKEN_FILE=/tmp/awscreds
export AWS_DEFAULT_REGION=us-east-1
echo AWS_WEB_IDENTITY_TOKEN_FILE=$AWS_WEB_IDENTITY_TOKEN_FILE >> $GITHUB_ENV
echo AWS_ROLE_ARN=$AWS_ROLE_ARN >> $GITHUB_ENV
echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION >> $GITHUB_ENV
curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r '.value' > $AWS_WEB_IDENTITY_TOKEN_FILE
- name: Run Smoke Test (CDN)
env:
URL: ${{ secrets.SMOKE_URL }}
MONITOR: ${{ secrets.SMOKE_MONITOR }}
ENDPOINT: ${{ secrets.SMOKE_ENDPOINT }}
NAME: ${{ secrets.SMOKE_MONITOR_NAME }}
INSTALL_METHOD: 'CDN'
run: npm run smoke:headless

- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Build Smoke Test Application - NPM/ES (Post NPM Release)
id: build-npm-es-application-post-release
run: |
chmod u+x .github/scripts/build_npm_applications.sh
.github/scripts/build_npm_applications.sh "POST" "NPM-ES"
- name: Build Smoke Test Application - NPM/CJS (Post NPM Release)
id: build-npm-cjs-application-post-release
run: |
chmod u+x .github/scripts/build_npm_applications.sh
.github/scripts/build_npm_applications.sh "POST" "NPM-CJS"
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ coverage
src/events
package-lock.json
docs/
.vscode
.vscode
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"postinteg:local:nightwatch:firefox": "kill $(lsof -t -i:8080)",
"smoke:local:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.local.config.ts",
"smoke:local": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.local.config.ts --headed",
"smoke": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.config.ts --headed",
"smoke:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.config.ts",
"smoke:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version INSTALL_METHOD=$INSTALL_METHOD npx playwright test --config=playwright.config.ts",
"prepare": "husky install"
},
"devDependencies": {
Expand Down
7 changes: 5 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
// @ts-check
const { devices } = require('@playwright/test');

const config = {
var config = {
forbidOnly: !!process.env.CI,
reporter: 'list',
workers: process.env.CI ? 4 : undefined,
testDir: 'src/__smoke-test__',
testDir:
process.env.INSTALL_METHOD === 'CDN'
? 'src/__smoke-test__'
: 'src/__smoke-test-npm__',
retries: process.env.CI ? 2 : 2,
timeout: 300000,
use: {
Expand Down
Loading

0 comments on commit 5e824fc

Please sign in to comment.