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 3034db3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 40 deletions.
65 changes: 32 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,28 @@ 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/authentication/**"
- name: 'Upload Cypress Recordings to Github'
uses: actions/upload-artifact@v4
Expand All @@ -85,4 +84,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
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

0 comments on commit 3034db3

Please sign in to comment.