Skip to content

Commit

Permalink
Merge pull request aws-geospatial#204 from aws-geospatial/enhancement…
Browse files Browse the repository at this point in the history
…_ALS-1790_github-worflows

[Enhancement] [ALS-1790] Github workflows
  • Loading branch information
wadhawh authored Jul 19, 2024
2 parents f61fbd8 + 6dd6e7a commit 059f210
Show file tree
Hide file tree
Showing 18 changed files with 2,038 additions and 1,936 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VITE_PINPOINT_APPLICATION_ID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
VITE_AWS_CF_TEMPLATE=https://us-east-1.console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/create?stackName=amazon-location-resources-setup&templateURL=https://amazon-location-demo-resources.s3.us-west-2.amazonaws.com/main-cf-template.yaml
VITE_APPLE_APP_STORE_LINK=https://apps.apple.com/app/amazon-location-demo/id1670477797?trk=18347227-315a-4761-a6a7-07e2ffdf08b6&sc_channel=el
VITE_GOOGLE_PLAY_STORE_LINK=https://play.google.com/store/apps/details?id=com.aws.amazonlocation&trk=7246fb27-1ed0-4c04-ba03-7af6c090739b&sc_channel=el
VITE_APP_VERSION=2.1.0
VITE_APP_VERSION=3.0.0
VITE_MIGRATE_FROM_GOOGLE_MAPS_PAGE=1
VITE_MIGRATE_A_WEB_APP_PAGE=1
VITE_MIGRATE_AN_ANDROID_APP_PAGE=1
Expand Down
58 changes: 50 additions & 8 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: E2E_Tests
name: E2E tests

on:
push:
Expand All @@ -9,23 +9,51 @@ on:

jobs:
e2e-tests:
name: E2E-Testing
name: E2E tests
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
- name: Setup node
uses: actions/setup-node@v3

- name: Install Dependencies
run: npm install
- name: Create .env file
run: |
echo "VITE_AWS_COGNITO_IDENTITY_POOL_IDS=${{ secrets.VITE_AWS_COGNITO_IDENTITY_POOL_IDS }}" > .env
echo "VITE_AWS_WEB_SOCKET_URLS=${{ secrets.VITE_AWS_WEB_SOCKET_URLS }}" >> .env
echo "VITE_PINPOINT_IDENTITY_POOL_ID=${{ secrets.VITE_PINPOINT_IDENTITY_POOL_ID }}" >> .env
echo "VITE_PINPOINT_APPLICATION_ID=${{ secrets.VITE_PINPOINT_APPLICATION_ID }}" >> .env
echo "VITE_AWS_CF_TEMPLATE=${{ secrets.VITE_AWS_CF_TEMPLATE }}" >> .env
echo "VITE_APPLE_APP_STORE_LINK=${{ secrets.VITE_APPLE_APP_STORE_LINK }}" >> .env
echo "VITE_GOOGLE_PLAY_STORE_LINK=${{ secrets.VITE_GOOGLE_PLAY_STORE_LINK }}" >> .env
echo "VITE_DATA_FILES_URL=${{ secrets.VITE_DATA_FILES_URL }}" >> .env
echo "VITE_SAMPLES_LIST_FILENAME=${{ secrets.VITE_SAMPLES_LIST_FILENAME }}" >> .env
echo "VITE_APP_VERSION=${{ secrets.VITE_APP_VERSION }}" >> .env
echo "VITE_MIGRATE_FROM_GOOGLE_MAPS_PAGE=${{ secrets.VITE_MIGRATE_FROM_GOOGLE_MAPS_PAGE }}" >> .env
echo "VITE_MIGRATE_A_WEB_APP_PAGE=${{ secrets.VITE_MIGRATE_A_WEB_APP_PAGE }}" >> .env
echo "VITE_MIGRATE_AN_ANDROID_APP_PAGE=${{ secrets.VITE_MIGRATE_AN_ANDROID_APP_PAGE }}" >> .env
echo "VITE_MIGRATE_AN_IOS_APP_PAGE=${{ secrets.VITE_MIGRATE_AN_IOS_APP_PAGE }}" >> .env
echo "VITE_MIGRATE_A_WEB_SERVICE_PAGE=${{ secrets.VITE_MIGRATE_A_WEB_SERVICE_PAGE }}" >> .env
echo "VITE_PRICING_PAGE=${{ secrets.VITE_PRICING_PAGE }}" >> .env
echo "VITE_CUSTOM_ASSETS_URL=${{ secrets.VITE_CUSTOM_ASSETS_URL }}" >> .env
- name: Setup Cypress
run: npm install cypress --save-dev
- name: Clone the amazon-location-web-marketing repository
run: |
mkdir -p ../amazon-location-web-marketing-temp
git clone --branch main https://${{ secrets.GH_USERNAME }}:${{ secrets.GH_PAT }}@github.com/aws-geospatial/amazon-location-web-marketing.git ../amazon-location-web-marketing-temp
- name: Run Cypress test
- name: Create build
run: npm run create-build-with-demo-lib

- name: Run build
run: |
npm run start-build &
echo "Server started"
sleep 10
- name: Run cypress tests
env:
CYPRESS_WEB_DOMAIN: ${{ secrets.WEB_DOMAIN }}
CYPRESS_WEB_DOMAIN_USERNAME: ${{ secrets.WEB_DOMAIN_USERNAME }}
Expand All @@ -40,3 +68,17 @@ jobs:
PINPOINT_IDENTITY_POOL_ID: ${{ secrets.VITE_PINPOINT_IDENTITY_POOL_ID }}
PINPOINT_APPLICATION_ID: ${{ secrets.VITE_PINPOINT_APPLICATION_ID }}
run: npm run cypress

- name: Upload cypress report
if: always()
uses: actions/upload-artifact@v4
with:
name: cypress-reports
path: cypress/reports

- name: Upload cypress screenshots
if: always()
uses: actions/upload-artifact@v4
with:
name: cypress-screenshots
path: cypress/screenshots
16 changes: 8 additions & 8 deletions .github/workflows/security-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Security_Tests
name: Security tests

on:
push:
Expand All @@ -8,21 +8,21 @@ on:
branches: [main]

jobs:
e2e-tests:
name: Security-Testing
security-tests:
name: Security tests
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
- name: Setup node
uses: actions/setup-node@v3

- name: Install Dependencies
run: cd security-tests/ ; npm install
- name: Install dependencies
run: cd security-tests/ && npm install

- name: Run Security test
- name: Run security tests
env:
IDENTITY_POOL_ID: ${{ secrets.IDENTITY_POOL_ID }}
USER_POOL_ID: ${{ secrets.USER_POOL_ID }}
Expand All @@ -31,4 +31,4 @@ jobs:
COGNITO_PASSWORD: ${{ secrets.COGNITO_PASSWORD }}
IAM_AUTH_ROLE_NAME: ${{ secrets.IAM_AUTH_ROLE_NAME }}
IAM_UNAUTH_ROLE_NAME: ${{ secrets.IAM_UNAUTH_ROLE_NAME }}
run: cd security-tests/ ; npm run test
run: cd security-tests/ && npm run test
12 changes: 6 additions & 6 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit_Tests
name: Unit tests

on:
push:
Expand All @@ -8,21 +8,21 @@ on:
branches: [main]

jobs:
e2e-tests:
name: Unit-Testing
unit-tests:
name: Unit tests
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
- name: Setup node
uses: actions/setup-node@v3

- name: Install Dependencies
- name: Install dependencies
run: npm install

- name: Run Unit Tests
- name: Run unit tests
env:
VITE_PINPOINT_IDENTITY_POOL_ID: ${{ secrets.VITE_PINPOINT_IDENTITY_POOL_ID }}
VITE_PINPOINT_APPLICATION_ID: ${{ secrets.VITE_PINPOINT_APPLICATION_ID }}
Expand Down
72 changes: 41 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,45 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
7. Once, the stack is created → Go to outputs of the stack & Copy them all.
8. Now, Browse to Github [amazon-location-features-demo-web](https://github.com/aws-geospatial/amazon-location-features-demo-web) repo.
9. Under the repo settings → Go to Secrets & Variables → Click on Actions.
10. Now, Add/Update the values in secrets as per the output values gathered from the cloudformation

10. Now, Add/Update the values in secrets as per the output values gathered from the cloudformation.
11. Add all keys from `.env` file to the secrets section of the repo as well from the above Requirements section.
12. Also create a Personal Access Token (PAT) from [here](https://github.com/settings/tokens), which will be added against `GH_PAT` and the username against `GH_USERNAME` in the secrets section of the repo.
```
WEB_DOMAIN: "https://location.aws.com" // Production URL
WEB_DOMAIN_USERNAME: "XXXXX" // This is the username for the web domain (only required for dev and qa environments, not needed for prod environment)
WEB_DOMAIN_PASSWORD: "XXXXX" // This is the password for the web domain (only required for dev and qa environments, not needed for prod environment)
IDENTITY_POOL_ID: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab" // Stack output as IdentityPoolId
USER_DOMAIN: "https://XXXXXXXXXXXX.XXXX.XX-XXXX-X.amazoncognito.com/" // Stack output as UserDomain
USER_POOL_CLIENT_ID: "XXXXXXXXXXXX" // Stack output as UserPoolClientId
USER_POOL_ID: "XX-XXXX-X_XXXXXXXXXX" // Stack output as UserPoolId
WEB_SOCKET_URL: "XXXXXXXXXXX-ats.iot.us-east-1.amazonaws.com" // Stack output as WebSocketUrl
COGNITO_EMAIL: "[email protected]" // Stack output as UserEmail
COGNITO_PASSWORD: "XXXXXX" // This is the password for the cognito user (received on registered email)
VITE_PINPOINT_IDENTITY_POOL_ID: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab" // Same as VITE_PINPOINT_IDENTITY_POOL_ID
VITE_PINPOINT_APPLICATION_ID: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // Same as VITE_PINPOINT_APPLICATION_ID
> WEB_DOMAIN: "http://localhost:3000"
> WEB_DOMAIN_USERNAME: "XXXXX" // This is the username for the web domain (only required for dev and qa environments, not needed for prod environment)
> WEB_DOMAIN_PASSWORD: "XXXXX" // This is the password for the web domain (only required for dev and qa environments, not needed for prod environment)
> IDENTITY_POOL_ID: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab" // Stack output as IdentityPoolId
> USER_DOMAIN: "https://XXXXXXXXXXXX.XXXX.XX-XXXX-X.amazoncognito.com/" // Stack output as UserDomain
> USER_POOL_CLIENT_ID: "XXXXXXXXXXXX" // Stack output as UserPoolClientId
> USER_POOL_ID: "XX-XXXX-X_XXXXXXXXXX" // Stack output as UserPoolId
> WEB_SOCKET_URL: "XXXXXXXXXXX-ats.iot.us-east-1.amazonaws.com" // Stack output as WebSocketUrl
> COGNITO_EMAIL: "[email protected]" // Stack output as UserEmail
> COGNITO_PASSWORD: "XXXXXX" // This is the password for the cognito user (received on registered email)
> VITE_AWS_COGNITO_IDENTITY_POOL_IDS
> VITE_AWS_WEB_SOCKET_URLS
> VITE_PINPOINT_IDENTITY_POOL_ID
> VITE_PINPOINT_APPLICATION_ID
> VITE_AWS_CF_TEMPLATE
> VITE_APPLE_APP_STORE_LINK
> VITE_GOOGLE_PLAY_STORE_LINK
> VITE_DATA_FILES_URL
> VITE_SAMPLES_LIST_FILENAME
> VITE_APP_VERSION
> VITE_MIGRATE_FROM_GOOGLE_MAPS_PAGE
> VITE_MIGRATE_A_WEB_APP_PAGE
> VITE_MIGRATE_AN_ANDROID_APP_PAGE
> VITE_MIGRATE_AN_IOS_APP_PAGE
> VITE_MIGRATE_A_WEB_SERVICE_PAGE
> VITE_PRICING_PAGE
> VITE_CUSTOM_ASSETS_URL
> GH_USERNAME: XXXXXXXX
> GH_PAT: ghp_XXXXXXXXXXXXXXXXXXXXXX
```

#### `npm run cypress`

Runs Cypress tests to completion in a headed chrome browser.

#### `npm run cypress run`

Runs Cypress tests to completion. By default, `cypress run` will run all tests headlessly. https://docs.cypress.io/guides/guides/command-line#cypress-run

#### `npm run cypress open`

Runs Cypress tests to completion in a browser which can be specified in the `options`. https://docs.cypress.io/guides/guides/command-line#cypress-open

## Security Tests

#### Env keys required in `security-tests/.env` file, see `security-tests/.env.example` for reference.
Expand All @@ -122,13 +132,13 @@ Runs Cypress tests to completion in a browser which can be specified in the `opt
#### If you are configuring Github actions for the Security tests, make sure to add the below env keys to the secrets section of the repo. You will need to use the values from the stack that was created when setting up the E2E tests.

```
IDENTITY_POOL_ID: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab" // Stack output as IdentityPoolId
USER_POOL_ID: "XX-XXXX-X_XXXXXXXXXX" // Stack output as UserPoolId
USER_POOL_CLIENT_ID: "XXXXXXXXXXXX" // Stack output as UserPoolClientId
COGNITO_EMAIL: "[email protected]" // Stack output as UserEmail
COGNITO_PASSWORD: "XXXXXX" // This is the password for the cognito user (received on registered email)
IAM_AUTH_ROLE_NAME: "amazon-location-resources-AmazonLocationDemoCognit-XXXXXXXX" // Stack output as IAMAuthRoleName
IAM_UNAUTH_ROLE_NAME: "amazon-location-resources-AmazonLocationDemoCognit-XXXXXXXX" // Stack output as IAMUnAuthRoleName
> IDENTITY_POOL_ID: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab" // Stack output as IdentityPoolId
> USER_POOL_ID: "XX-XXXX-X_XXXXXXXXXX" // Stack output as UserPoolId
> USER_POOL_CLIENT_ID: "XXXXXXXXXXXX" // Stack output as UserPoolClientId
> COGNITO_EMAIL: "[email protected]" // Stack output as UserEmail
> COGNITO_PASSWORD: "XXXXXX" // This is the password for the cognito user (received on registered email)
> IAM_AUTH_ROLE_NAME: "amazon-location-resources-AmazonLocationDemoCognit-XXXXXXXX" // Stack output as IAMAuthRoleName
> IAM_UNAUTH_ROLE_NAME: "amazon-location-resources-AmazonLocationDemoCognit-XXXXXXXX" // Stack output as IAMUnAuthRoleName
```

#### `npm run security-tests`
Expand All @@ -145,8 +155,8 @@ Runs Security tests insuring policies match the expected values.
#### If you are configuring Github actions for the Unit tests, make sure to add the below env keys to the secrets section of the repo. You will need to use the values from the stack that was created when setting up the app env in the very first step (These should already exist if you have setup secrets for E2E tests).

```
VITE_PINPOINT_IDENTITY_POOL_ID: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab" // Same as VITE_PINPOINT_IDENTITY_POOL_ID
VITE_PINPOINT_APPLICATION_ID: "XXXXXXXX" // Same as VITE_PINPOINT_APPLICATION_ID
> VITE_PINPOINT_IDENTITY_POOL_ID: "XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab" // Same as VITE_PINPOINT_IDENTITY_POOL_ID
> VITE_PINPOINT_APPLICATION_ID: "XXXXXXXX" // Same as VITE_PINPOINT_APPLICATION_ID
```

#### `npm run test`
Expand Down
4 changes: 2 additions & 2 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { afterRunHook, beforeRunHook } from "cypress-mochawesome-reporter/lib";

export default defineConfig({
defaultCommandTimeout: 20000,
viewportWidth: 1024,
viewportWidth: 1440,
viewportHeight: 733,
retries: 2,
retries: 3,
video: false,
env: {
browserPermissions: {
Expand Down
2 changes: 1 addition & 1 deletion cypress.env.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"WEB_DOMAIN": "https://dev.amazonlocation.services",
"WEB_DOMAIN": "http://localhost:3000",
"WEB_DOMAIN_USERNAME": "XXXXXX",
"WEB_DOMAIN_PASSWORD": "XXXXXXXXXX",
"IDENTITY_POOL_ID": "XX-XXXX-X:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
Expand Down
6 changes: 2 additions & 4 deletions cypress/e2e/userIsAbleToUseGeofence.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ import { Viewport } from "../support/constants";

describe("Geofence", () => {
context("Desktop view", () => {
const geofenceName = faker.random.word();

beforeEach(() => {
cy.visitDomain(`${Cypress.env("WEB_DOMAIN")}/demo`);
cy.connectAwsAccount(Viewport.DESKTOP);
});

it("GF-001 - should allow user to add, edit and delete geofence", () => {
const geofenceName = faker.random.word();
cy.addEditAndDeleteGeofence(Viewport.DESKTOP, geofenceName);
});
});

context("Responsive view", () => {
const geofenceName = faker.random.word();

beforeEach(() => {
cy.visitDomainInResponsiveView(`${Cypress.env("WEB_DOMAIN")}/demo`);
cy.connectAwsAccount(Viewport.RESPONSIVE);
});

it("GF-002 - should allow user to add, edit and delete geofence", () => {
const geofenceName = faker.random.word();
cy.addEditAndDeleteGeofence(Viewport.RESPONSIVE, geofenceName);
});
});
Expand Down
4 changes: 4 additions & 0 deletions cypress/e2e/userIsAbleToUseRoute.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ describe("Route", () => {
context("Desktop view", () => {
beforeEach(() => {
cy.visitDomain(`${Cypress.env("WEB_DOMAIN")}/demo`);
cy.reload();
cy.wait(10000);
cy.get('[class="amplify-flex icon outter-end-component"]').click();
cy.wait(2000);
});
Expand Down Expand Up @@ -39,6 +41,8 @@ describe("Route", () => {
context("Responsive view", () => {
beforeEach(() => {
cy.visitDomainInResponsiveView(`${Cypress.env("WEB_DOMAIN")}/demo`);
cy.reload();
cy.wait(10000);
cy.get('[data-testid="explore-button-container-Routes"]').click();
cy.wait(2000);
});
Expand Down
6 changes: 2 additions & 4 deletions cypress/e2e/userIsAbleToUseTracker.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ import { Viewport } from "../support/constants";

describe("Tracker", () => {
context("Desktop view", () => {
const geofenceName = faker.random.word();

beforeEach(() => {
cy.visitDomain(`${Cypress.env("WEB_DOMAIN")}/demo`);
cy.connectAwsAccount(Viewport.DESKTOP);
});

it("TR-001 - should allow user to add a tracker and the user should see the notifications for Geofence enter and exit events", () => {
const geofenceName = faker.random.word();
cy.addTrackerAndGeofenceEnterExit(Viewport.DESKTOP, geofenceName);
});
});

context("Responsive view", () => {
const geofenceName = faker.random.word();

beforeEach(() => {
cy.visitDomainInResponsiveView(`${Cypress.env("WEB_DOMAIN")}/demo`);
cy.connectAwsAccount(Viewport.RESPONSIVE);
});

it("TR-002 - should allow user to add a tracker and the user should see the notifications for Geofence enter and exit events", () => {
const geofenceName = faker.random.word();
cy.addTrackerAndGeofenceEnterExit(Viewport.RESPONSIVE, geofenceName);
});
});
Expand Down
10 changes: 5 additions & 5 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Cypress.Commands.add("visitDomain", domain => {
})
: cy.visit(domain);

cy.wait(20000);
cy.wait(10000);
cy.get('[data-testid="welcome-modal-continue-button"]').click();
}
});
Expand Down Expand Up @@ -97,17 +97,17 @@ Cypress.Commands.add("connectAwsAccount", isResponsive => {
isResponsive
? cy.openResponsiveMenu('[data-testid="bottomsheet"]')
: cy.get('[data-testid="hamburger-menu"]').click();
cy.wait(5000);
cy.get("#root").then($root => {
const asd = $root.find('[class="amplify-button amplify-field-group__control amplify-button--primary"]');

if (asd.length && asd[0].innerText === "Sign in") {
asd[0].click();
if ($root.find('[data-testid="sign-in-button"]').length > 0) {
cy.get('[data-testid="sign-in-button"]').click();
} else {
isResponsive
? cy.closeResponsiveMenu('[data-testid="bottomsheet"]')
: cy.get('[data-testid="hamburger-menu"]').click();
}
});
cy.wait(15000);
});

Cypress.Commands.add("signOutAndDisconnectFromAwsAccount", isResponsive => {
Expand Down
Loading

0 comments on commit 059f210

Please sign in to comment.