Skip to content

Commit

Permalink
use envs
Browse files Browse the repository at this point in the history
  • Loading branch information
sprutton1 committed Jun 24, 2024
1 parent 15190a4 commit 9d874fc
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 52 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/deploy-on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ jobs:
service: all
version: stable
secrets: inherit

e2e-validation:
uses: ./.github/workflows/e2e-validation.yml
with:
environment: tools
secrets: inherit
66 changes: 33 additions & 33 deletions .github/workflows/e2e-validation.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
name: Cypress E2E Tests

on:
workflow_dispatch:
# schedule:
# - cron: '*/5 * * * *' # Runs every 5 minutes
workflow_call:
inputs:
environment:
description: 'Select environment'
type: string
required: true
default: 'PROD'
description: "where to deploy"
default: "tools"
workflow_dispatch:
inputs:
environment:
type: choice
required: true
description: "where to deploy"
default: "tools"
options:
- PROD
- TOOLS
- tools
- production

jobs:
cypress-tests:
environment: ${{ inputs.environment }}
runs-on: ubuntu-latest
strategy:
# don't fail the entire matrix on failure
Expand All @@ -25,31 +33,13 @@ jobs:
containers: [1] # , 2, 3, 4, 5, 6, 7, 8, 9, 10] - temp disabled mass
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18.18.2'

- name: Setup authentication for vite & other synthetic test variables
working-directory: app/web
run: |
sudo apt update
sudo apt install uuid -y
cp .env .env.local
echo "VITE_AUTH0_USERNAME=${{ secrets.VITE_AUTH0_USERNAME }}" >> .env.local
echo "VITE_AUTH0_PASSWORD=${{ secrets.VITE_AUTH0_PASSWORD }}" >> .env.local
echo "VITE_SI_CYPRESS_MULTIPLIER=${{ vars.VITE_SI_CYPRESS_MULTIPLIER }}" >> .env.local
if [ "${{ github.event.inputs.environment }}" == "PROD" ]; then
echo "VITE_SI_WORKSPACE_URL=${{ vars.VITE_PROD_SI_WORKSPACE_URL }}" >> .env.local
echo "VITE_SI_WORKSPACE_ID=${{ vars.VITE_PROD_SI_WORKSPACE_ID }}" >> .env.local
elif [ "${{ github.event.inputs.environment }}" == "TOOLS" ]; then
echo "VITE_SI_WORKSPACE_URL=${{ vars.VITE_TOOLS_SI_WORKSPACE_URL }}" >> .env.local
echo "VITE_SI_WORKSPACE_ID=${{ vars.VITE_TOOLS_SI_WORKSPACE_ID }}" >> .env.local
fi
echo "VITE_UUID=$(uuid)" >> .env.local
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
Expand All @@ -60,19 +50,29 @@ jobs:
run: |
pnpm i
pnpm install cypress
- name: install uuid
run: |
sudo apt update
sudo apt install uuid -y
- uses: nick-fields/retry@v2
with:
max_attempts: 3
timeout_minutes: 20
command: |
if [ "${{ github.event.inputs.environment }}" == "PROD" ]; then
export VITE_HOST_URL=${{ vars.VITE_PROD_SI_WORKSPACE_URL }}
elif [ "${{ github.event.inputs.environment }}" == "TOOLS" ]; then
export VITE_HOST_URL=${{ vars.VITE_TOOLS_SI_WORKSPACE_URL }}
fi
cd app/web
npx cypress run --spec "cypress/e2e/**"
export VITE_AUTH0_USERNAME=${{ secrets.VITE_AUTH0_USERNAME }}
export VITE_AUTH0_PASSWORD=${{ secrets.VITE_AUTH0_PASSWORD }}
export VITE_SI_CYPRESS_MULTIPLIER=${{ vars.VITE_SI_CYPRESS_MULTIPLIER }}
export VITE_SI_WORKSPACE_URL=${{ vars.VITE_SI_WORKSPACE_URL }}
export VITE_HOST_URL=${{ vars.VITE_SI_WORKSPACE_URL }}
export VITE_SI_WORKSPACE_ID=${{ vars.VITE_SI_WORKSPACE_ID }}
export VITE_UUID=$(uuid)
export VITE_AUTH_API_URL=https://auth-api.systeminit.com
export VITE_AUTH_PORTAL_URL=https://auth.systeminit.com
npx cypress run --spec "cypress/e2e/**" --parallel --record --key ${{ secrets.CYPRESS_RECORD_KEY }}
- name: 'Upload Cypress Recordings to Github'
uses: actions/upload-artifact@v4
Expand All @@ -85,4 +85,4 @@ jobs:
- name: Send Slack Failure Webhook
if: failure()
run: |
curl -X POST -H 'Content-type: application/json' --data "{\"text\": \":si: Failed Cypress E2E Test for ${{ github.event.inputs.environment }}: <https://github.com/systeminit/si/actions/runs/$GITHUB_RUN_ID|:test_tube: Link>\"}" ${{ secrets.SLACK_WEBHOOK_URL }}
curl -X POST -H 'Content-type: application/json' --data "{\"text\": \":si: Failed Cypress E2E Test for ${{ inputs.environment }}: <https://github.com/systeminit/si/actions/runs/$GITHUB_RUN_ID|:test_tube: Link>\"}" ${{ secrets.SLACK_WEBHOOK_URL }}
4 changes: 4 additions & 0 deletions app/web/cypress/e2e/authentication/login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Cypress._.times(SI_CYPRESS_MULTIPLIER, () => {
it("log_in", () => {
cy.loginToAuth0(AUTH0_USERNAME, AUTH0_PASSWORD);
cy.visit(AUTH_API_URL + '/workspaces/' + SI_WORKSPACE_ID + '/go');
cy.on('uncaught:exception', (e) => {
console.log(e);
return false;
});
cy.sendPosthogEvent(Cypress.currentTest.titlePath.join("/"), "test_uuid", UUID);
// check that you're on head i.e. that you were redirected correctly
cy.wait(4000)
Expand Down
8 changes: 7 additions & 1 deletion app/web/cypress/e2e/authentication/logout.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const SI_CYPRESS_MULTIPLIER = Cypress.env('VITE_SI_CYPRESS_MULTIPLIER') || import.meta.env.VITE_SI_CYPRESS_MULTIPLIER || 1;
const SI_WORKSPACE_ID = Cypress.env('VITE_SI_WORKSPACE_ID') || import.meta.env.VITE_SI_WORKSPACE_ID;
const AUTH0_USERNAME = Cypress.env('VITE_AUTH0_USERNAME') || import.meta.env.VITE_AUTH0_USERNAME;
const AUTH0_PASSWORD = Cypress.env('VITE_AUTH0_PASSWORD') || import.meta.env.VITE_AUTH0_PASSWORD;
const AUTH_API_URL = Cypress.env('VITE_AUTH_API_URL') || import.meta.env.VITE_AUTH_API_URL;
const AUTH_PORTAL_URL = Cypress.env('VITE_AUTH_PORTAL_URL') || import.meta.env.VITE_AUTH_PORTAL_URL;
const UUID = Cypress.env('VITE_UUID') || import.meta.env.VITE_UUID || "local";

Expand All @@ -12,7 +14,11 @@ Cypress._.times(SI_CYPRESS_MULTIPLIER, () => {
});

it("log_out", () => {
cy.visit("/");
cy.visit(AUTH_API_URL + '/workspaces/' + SI_WORKSPACE_ID + '/go');
cy.on('uncaught:exception', (e) => {
console.log(e);
return false;
});
cy.sendPosthogEvent(Cypress.currentTest.titlePath.join("/"), "test_uuid", UUID);
cy.contains('Create change set', { timeout: 10000 }).should('be.visible');
cy.get('.modal-close-button').should('exist').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Cypress._.times(SI_CYPRESS_MULTIPLIER, () => {

it('create', () => {
cy.visit(AUTH_API_URL + '/workspaces/' + SI_WORKSPACE_ID + '/go');
cy.on('uncaught:exception', (e) => {
console.log(e);
return false;
});
cy.sendPosthogEvent(Cypress.currentTest.titlePath.join("/"), "test_uuid", UUID);

cy.get('#vorm-input-3', { timeout: 30000 }).should('have.value', 'Change Set 1');
Expand Down
18 changes: 8 additions & 10 deletions app/web/cypress/e2e/modelling-functionality/delete-component.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Cypress._.times(SI_CYPRESS_MULTIPLIER, () => {

it('delete', () => {
cy.visit(AUTH_API_URL + '/workspaces/' + SI_WORKSPACE_ID + '/go');
cy.on('uncaught:exception', (e) => {
console.log(e);
return false;
});
cy.sendPosthogEvent(Cypress.currentTest.titlePath.join("/"), "test_uuid", UUID);
cy.get('#vorm-input-3', { timeout: 30000 }).should('have.value', 'Change Set 1');

Expand All @@ -28,18 +32,12 @@ Cypress._.times(SI_CYPRESS_MULTIPLIER, () => {
// Give time to redirect onto the new change set
cy.url().should('not.include', 'head', { timeout: 10000 });

// Find the AWS Credential
cy.get('div[class="text-sm"]', { timeout: 30000 }).contains('AWS Credential').as('awsCred');

// Find the canvas to get a location to drag to
cy.get('canvas').first().as('konvaStage');

// Drag to the canvas
cy.dragTo('@awsCred', '@konvaStage');
// Create a region component
cy.createComponent("region");

// Check to make sure a component has been added to the outliner
cy.get('[class="diagram-outline-node"]', { timeout: 30000 })
.contains('AWS Credential', { timeout: 30000 })
.contains('Region', { timeout: 30000 })
.should('be.visible')
.rightclick();

Expand All @@ -51,7 +49,7 @@ Cypress._.times(SI_CYPRESS_MULTIPLIER, () => {
.click();

// Check to make sure a component has been added to the outliner
cy.get('[class="diagram-outline-node"]', { timeout: 30000 }).contains('AWS Credential', { timeout: 30000 }).should('be.visible');
cy.get('[class="diagram-outline-node"]', { timeout: 30000 }).contains('Region', { timeout: 30000 }).should('be.visible');

// Click the button to destroy change set
cy.get('nav.navbar button.vbutton.--variant-ghost.--size-sm.--tone-action')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ Cypress._.times(SI_CYPRESS_MULTIPLIER, () => {
cy.log(UUID);

// Go to the Synthetic Workspace
cy.visit(SI_WORKSPACE_URL + '/w/' + SI_WORKSPACE_ID + '/head');
cy.visit(AUTH_API_URL + '/workspaces/' + SI_WORKSPACE_ID + '/go');
cy.on('uncaught:exception', (e) => {
console.log(e);
return false;
});
cy.sendPosthogEvent(Cypress.currentTest.titlePath.join("/"), "test_uuid", UUID);
cy.get('#vorm-input-3', { timeout: 30000 }).should('have.value', 'Change Set 1');

Expand Down
4 changes: 4 additions & 0 deletions app/web/cypress/e2e/web-functionality/get-summary.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe('web', () => {
it('get_summary', () => {
// Go to the Synthetic Workspace
cy.visit(SI_WORKSPACE_URL + '/w/' + SI_WORKSPACE_ID + '/head');
cy.on('uncaught:exception', (e) => {
console.log(e);
return false;
});
cy.sendPosthogEvent(Cypress.currentTest.titlePath.join("/"), "test_uuid", UUID);
cy.intercept('GET', SI_WORKSPACE_URL + '/api/qualification/get_summary?visibility_change_set_pk=00000000000000000000000000', (req) => {
// Log the intercepted request URL and response status code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe("workspace", () => {
.should('be.visible')
.invoke('removeAttr', 'target')
.click();
cy.on('uncaught:exception', (e) => {
console.log(e);
return false;
});

cy.wait(5000);

Expand Down
12 changes: 6 additions & 6 deletions app/web/cypress/support/auth-provider-commands/auth0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ Cypress.Commands.add("loginToAuth0", (username: string, password: string) => {
cy.visit(import.meta.env.VITE_AUTH_API_URL + '/workspaces/' + import.meta.env.VITE_SI_WORKSPACE_ID + '/go');

},
{
validate: () => {
// Validate presence of access token in localStorage.
cy.window().its("localStorage").invoke("getItem", "si-auth").should("exist");
},
}
// {
// validate: () => {
// // Validate presence of access token in localStorage.
// cy.window().its("localStorage").invoke("getItem", "si-auth").should("exist");
// },
// }
);

log.snapshot("after");
Expand Down
2 changes: 1 addition & 1 deletion app/web/cypress/support/component-actions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Cypress.Commands.add("createComponent", (componentName: string) => {
log.snapshot("before");

// Find the component in the AssetPalette
cy.get('.asset-palette div[class="text-sm"]', { timeout: 30000 }).contains(componentName, { matchCase: false }).as('component');
cy.get('.asset-palette').find('.text-sm', { timeout: 30000 }).contains(componentName, { matchCase: false }).as('component');

// Find the canvas to get a location to drag to
cy.get('.modeling-diagram .konvajs-content').first().as('konvaStage');
Expand Down

0 comments on commit 9d874fc

Please sign in to comment.