Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: smoke test automation #13162

Merged
merged 63 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cd4457b
chore: add very basic smoke test
sobolk Aug 25, 2023
a4eba6c
chore: upload artifacts
sobolk Aug 25, 2023
ceb1f15
chore: debug logs
sobolk Aug 25, 2023
f0b847e
chore: debug logs
sobolk Aug 25, 2023
4d9b826
chore: undo logs
sobolk Aug 25, 2023
6e604de
chore: install amplify
sobolk Aug 25, 2023
1d21586
chore: does this work
sobolk Aug 25, 2023
bfb018d
chore: nope
sobolk Aug 25, 2023
b2ffb23
chore: creds
sobolk Aug 25, 2023
c5783bb
chore: creds
sobolk Aug 25, 2023
56b0dc6
chore: does this work
sobolk Aug 25, 2023
5b92742
chore: does this work
sobolk Aug 25, 2023
919a05a
chore: don't run twice
sobolk Aug 25, 2023
0e07521
chore: refactor that
sobolk Aug 25, 2023
4ce4efb
chore: refactor that
sobolk Aug 25, 2023
fcddba9
chore: refactor that
sobolk Aug 25, 2023
137102f
chore: refactor that
sobolk Aug 25, 2023
4ca86f1
try this
sobolk Aug 25, 2023
8435269
try this
sobolk Aug 25, 2023
f348811
try this
sobolk Aug 25, 2023
8257209
try this
sobolk Aug 25, 2023
f7573ee
try this
sobolk Aug 25, 2023
2877bbb
try this
sobolk Aug 25, 2023
d072aff
try this
sobolk Aug 25, 2023
3c63b83
try this
sobolk Aug 25, 2023
0eccdae
try this
sobolk Aug 25, 2023
3cf1d96
try this
sobolk Aug 25, 2023
4b838c0
try this
sobolk Aug 25, 2023
06461ac
try this
sobolk Aug 25, 2023
a8dd6ea
Undo that.
sobolk Aug 25, 2023
7099db4
try this
sobolk Aug 25, 2023
a1507ad
try this
sobolk Aug 25, 2023
305893b
try this
sobolk Aug 26, 2023
aa72ed4
try this
sobolk Aug 26, 2023
e197f29
exclude windows for now
sobolk Aug 26, 2023
6dd959d
exclude windows for now
sobolk Aug 26, 2023
fe4e011
schedule
sobolk Aug 26, 2023
1b396ed
try this
sobolk Aug 26, 2023
fadb62d
try this
sobolk Aug 26, 2023
eee5661
try this
sobolk Aug 26, 2023
932cbfb
try this
sobolk Aug 26, 2023
c9929bf
try this
sobolk Aug 26, 2023
cfdacaf
try this
sobolk Aug 26, 2023
2ec1c55
chore: move smoke tests to dir
sobolk Aug 28, 2023
66cbd0b
chore: add sample ios test
sobolk Aug 28, 2023
16b4835
chore: add sample ios test
sobolk Aug 28, 2023
04a93a4
chore: add sample ios test
sobolk Aug 28, 2023
1035da5
chore: add sample ios test
sobolk Aug 28, 2023
da9a856
chore: add sample ios test
sobolk Aug 28, 2023
ba203c8
chore: parallelize
sobolk Aug 28, 2023
7cc128d
chore: with codegen
sobolk Aug 28, 2023
087da3c
chore: with codegen
sobolk Aug 28, 2023
4fa584b
chore: lint
sobolk Aug 28, 2023
4643eee
chore: tests
sobolk Aug 28, 2023
ef75a4f
chore: pin actions versions
sobolk Aug 29, 2023
fcfc627
Merge branch 'dev' into smoke-tests-prototype
sobolk Aug 29, 2023
893b3da
chore: undo debug outputs
sobolk Aug 29, 2023
d020721
chore: pr feedback
sobolk Aug 29, 2023
8afc86d
chore: pr feedback
sobolk Aug 29, 2023
0bcae81
chore: pr feedback
sobolk Aug 29, 2023
6ea64ca
Merge remote-tracking branch 'origin/dev' into smoke-tests-prototype
sobolk Aug 29, 2023
31ca2ac
chore: pr feedback
sobolk Aug 30, 2023
feea838
chore: pr feedback
sobolk Aug 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/actions/install-cli/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Install Amplify CLI
description: Installs Amplify CLI
inputs:
cli-version:
description: a version of Amplify CLI
required: true
runs:
using: 'composite'
steps:
- name: Install CLI
shell: bash
if: runner.os != 'Windows'
run: |
npm install -g @aws-amplify/cli@${{ inputs.cli-version }}
AMPLIFY_PATH=$(which amplify)
echo "AMPLIFY_PATH=$AMPLIFY_PATH"
echo "AMPLIFY_PATH=$AMPLIFY_PATH" >> $GITHUB_ENV

- name: Install CLI Windows
shell: powershell
if: runner.os == 'Windows'
run: |
npm install -g @aws-amplify/cli@${{ inputs.cli-version }}
$AMPLIFY_PATH=(Get-Command amplify).Path
echo "AMPLIFY_PATH=$AMPLIFY_PATH"
"AMPLIFY_PATH=$AMPLIFY_PATH" >> $env:GITHUB_ENV
2 changes: 2 additions & 0 deletions .github/actions/run-smoke-tests-windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The Run Smoke Tests contains lightweight version of smoke tests for Windows.
GitHub Action's Windows workers are small and using our E2E testing framework for smoke testing overwhelms them.
53 changes: 53 additions & 0 deletions .github/actions/run-smoke-tests-windows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Run Smoke Tests
description: Executes Smoke Tests
inputs:
role-to-assume:
description: an IAM role to use in tests
required: true
region:
description: an AWS region to run in
required: false
default: us-west-2
runs:
using: 'composite'
steps:
- name: Verify Amplify Path
shell: bash
run: |
if [[ -z "$AMPLIFY_PATH" ]]; then
echo "AMPLIFY_PATH must be defined"
exit 1
fi
echo "AMPLIFY_PATH=$AMPLIFY_PATH"
$AMPLIFY_PATH version

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1
with:
role-to-assume: ${{ inputs.role-to-assume }}
aws-region: ${{ inputs.region }}

- name: Install AWS CLI
shell: powershell
run: |
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi /qn
aws --version

- name: Configure Profile
shell: bash
run: |
aws configure set region ${{ inputs.region }} --profile default
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set aws_session_token $AWS_SESSION_TOKEN --profile default

- name: Run Smoke Tests
shell: bash
run: .github/actions/run-smoke-tests-windows/windows-smoke-tests.sh

- name: Cleanup
shell: bash
if: always()
run: |
cd $AMPLIFY_PROJ_DIR
$AMPLIFY_PATH delete --force
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 1,
"serviceConfiguration": {
"serviceName": "AppSync",
"apiName": "myApiName",
"transformSchema": "type Todo @model { id: ID! content: String}",
"defaultAuthType": { "mode": "API_KEY" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 2,
"resourceName": "myAuthResource",
"serviceConfiguration": {
"serviceName": "Cognito",
"includeIdentityPool": false,
"userPoolConfiguration": { "requiredSignupAttributes": ["EMAIL", "PHONE_NUMBER"], "signinMethod": "USERNAME" }
}
}
41 changes: 41 additions & 0 deletions .github/actions/run-smoke-tests-windows/windows-smoke-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash -e

$AMPLIFY_PATH version

random_guid=$(powershell -Command "[guid]::NewGuid().ToString()")
random_guid=${random_guid//-/}
random_guid=${random_guid:0:6}
projDir="smoke-test-${random_guid}"
echo "AMPLIFY_PROJ_DIR=$projDir" >> $GITHUB_ENV

# Read headless requests content. This must be done before we change directory to $projDir.
THIS_SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
ADD_AUTH_REQUEST=$(cat $THIS_SCRIPT_PATH/add_auth_request.json)
ADD_AUTH_REQUEST=${ADD_AUTH_REQUEST//[$'\r\n']}
ADD_API_REQUEST=$(cat $THIS_SCRIPT_PATH/add_api_request.json)
ADD_API_REQUEST=${ADD_API_REQUEST//[$'\r\n']}

mkdir $projDir
cd $projDir

$AMPLIFY_PATH init --yes

$AMPLIFY_PATH status

echo $ADD_AUTH_REQUEST
$AMPLIFY_PATH add auth --headless <<< $ADD_AUTH_REQUEST

$AMPLIFY_PATH status

$AMPLIFY_PATH push --yes

$AMPLIFY_PATH status

echo $ADD_API_REQUEST
$AMPLIFY_PATH add api --headless <<< $ADD_API_REQUEST

$AMPLIFY_PATH status

$AMPLIFY_PATH push --yes

$AMPLIFY_PATH status
66 changes: 66 additions & 0 deletions .github/actions/run-smoke-tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Run Smoke Tests
description: Executes Smoke Tests
inputs:
role-to-assume:
description: an IAM role to use in tests
required: true
region:
description: an AWS region to run in
required: false
default: us-west-2
runs:
using: 'composite'
steps:
- name: Verify Amplify Path
shell: bash
run: |
if [[ -z "$AMPLIFY_PATH" ]]; then
echo "AMPLIFY_PATH must be defined"
exit 1
fi
echo "AMPLIFY_PATH=$AMPLIFY_PATH"
$AMPLIFY_PATH version

- name: Install Dependencies
shell: bash
run: yarn install --immutable

- name: Build
shell: bash
run: yarn build-tests

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1
with:
role-to-assume: ${{ inputs.role-to-assume }}
aws-region: ${{ inputs.region }}

# For iOS tests
- name: Setup Ruby
uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # v1.152.0
if: runner.os == 'macOS'
with:
ruby-version: '3.2.1'

# For iOS tests
- name: Set Default Xcode Version
if: runner.os == 'macOS'
shell: bash
run: |
sudo xcode-select -s "/Applications/Xcode_14.1.app"
xcodebuild -version

- name: Run Smoke Tests
shell: bash
run: yarn smoketest -- --forceExit --no-cache --maxWorkers=2
env:
CLI_REGION: ${{ inputs.region }}
CI: true
CIRCLECI: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to trigger test profile configuration

.


- name: Upload Report
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce #v3.1.2
if: always()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not the default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. By default step is skipped if previous step fails. This makes sure that report is uploaded regardless of test success.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with:
name: test report
path: packages/amplify-e2e-tests/amplify-e2e-reports
17 changes: 17 additions & 0 deletions .github/workflows/smoke-tests-canaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Smoke Tests - Canaries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the notification mechanism for this canary? I.e. how would the oncall find out if a run has failed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question.

Options to pursue:

I'd try that Slack integration first after merging this and explore cloudwatch if this is not working.


# This is required by aws-actions/configure-aws-credentials
permissions:
id-token: write
contents: read

on:
schedule:
- cron: '0 16 * * *' # Everyday 16:00 UTC

jobs:
call-smoke-tests:
uses: ./.github/workflows/smoke-tests.yml
secrets: inherit
with:
versions: '["rc", "latest"]'
27 changes: 27 additions & 0 deletions .github/workflows/smoke-tests-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Smoke Tests - Manual Run

# This is required by aws-actions/configure-aws-credentials
permissions:
id-token: write
contents: read

on:
workflow_dispatch:
inputs:
os:
required: false
type: string
default: '["macos-latest-xl", "ubuntu-latest", "windows-latest"]'
versions:
required: false
type: string
default: '["rc", "latest"]'

jobs:
call-smoke-tests:
if: github.event_name == 'workflow_dispatch'
uses: ./.github/workflows/smoke-tests.yml
secrets: inherit
with:
os: ${{ github.event.inputs.os }}
versions: ${{ github.event.inputs.versions }}
53 changes: 53 additions & 0 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Smoke Tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be an action rather than a workflow? Seems like it is being dispatched from the canary and manual workflow

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this is "reusable workflow" (see https://docs.github.com/en/actions/using-workflows/reusing-workflows )
Is the matrix element that runs the same steps on cartesian product of versions and agents.
That's not available in actions.

I created "canary" and "manual" as "lightweight entry points"
Think about smoke-tests.yml as base class and canary/manual as lightweight implementation of base that encapsulate invocation and parameters.
In other words smoke-tests.yml contains workflow logic. canary/manual are just different entry points (like cli throw over programatic interface).

Another reason to have canary and manual entry points is that they'll appear as separate top level workflows in GH ui so that person who wants to look at canaries vs person who wants to smoke test RC won't have to reason about modality of parameters.

And yet other reason is that creating single workflow definition with multiple "triggers" would require workarounds to have matrix populated correctly in every case. (Depending on trigger we'd need different logic to populate matrix which is hard problem in declarative yaml).


# This is required by aws-actions/configure-aws-credentials
permissions:
id-token: write
contents: read

on:
workflow_call:
inputs:
os:
required: false
type: string
default: '["macos-latest-xl", "ubuntu-latest", "windows-latest"]'
versions:
required: false
type: string
default: '["rc", "latest"]'

env:
NODE_OPTIONS: --max-old-space-size=8096

jobs:
run-smoke-tests:
strategy:
fail-fast: false
matrix:
os: ${{ fromJson(inputs.os) }}
cli-version: ${{ fromJson(inputs.versions) }}
name: Smoke Tests ${{ matrix.os }} ${{ matrix.cli-version }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
persist-credentials: false

- name: Install Amplify CLI
uses: ./.github/actions/install-cli
with:
cli-version: ${{ matrix.cli-version }}

- name: Run Smoke Tests Unix
if: runner.os != 'Windows'
uses: ./.github/actions/run-smoke-tests
with:
role-to-assume: ${{ secrets.SMOKE_TESTS_ROLE_ARN }}

- name: Run Smoke Tests Windows
if: runner.os == 'Windows'
uses: ./.github/actions/run-smoke-tests-windows
with:
role-to-assume: ${{ secrets.SMOKE_TESTS_ROLE_ARN }}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ packages/amplify-cli-core/src/__tests__/testFiles/packageManager-npm/package-loc
packages/amplify-cli-core/src/__tests__/testFiles/testProject-initialize-json-error/amplify/cli.json
packages/amplify-e2e-core/dist/index.html
packages/amplify-e2e-tests/amplify-e2e-reports
packages/amplify-e2e-tests/resources/example-ios-app
packages/amplify-environment-parameters/src/schemas/BackendParameters.schema.json
packages/amplify-nodejs-function-runtime-provider/src/__tests__/utils/handlerWithSyntaxError.js
packages/amplify-velocity-template/src/parse/velocity.yy
Expand Down
Loading