Cypress E2E Tests #1666
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cypress E2E Tests | |
on: | |
workflow_call: | |
inputs: | |
environment: | |
type: string | |
required: true | |
description: "where to test" | |
workflow_dispatch: | |
inputs: | |
environment: | |
type: choice | |
required: true | |
description: "where to test" | |
default: "tools" | |
options: | |
- tools | |
- production | |
jobs: | |
define-test-matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
tests: ${{ steps.tests.outputs.tests }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: tests | |
working-directory: app/web/cypress/e2e | |
run: | | |
# get the names of all test subdirs with out slashes | |
test_dirs=$(find . -mindepth 1 -maxdepth 1 -type d | sed 's|^\./||') | |
test_array="[]" | |
# put them into an array | |
for d in $test_dirs; do | |
test_array=$(echo "$test_array" | jq --arg d "$d" '. += [$d]') | |
done | |
test_array=$(echo "$test_array" | jq -c '.') | |
echo "$test_array" | |
echo "tests=$test_array" >> "$GITHUB_OUTPUT" | |
cypress-tests: | |
environment: ${{ inputs.environment }} | |
runs-on: ubuntu-latest | |
needs: define-test-matrix | |
strategy: | |
fail-fast: false | |
matrix: | |
tests: ${{ fromJSON(needs.define-test-matrix.outputs.tests) }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.18.2' | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Install Cypress | |
working-directory: app/web | |
run: | | |
pnpm i | |
pnpm install cypress | |
- name: install uuid | |
run: | | |
sudo apt update | |
sudo apt install uuid -y | |
- name: Run Cypress Tests | |
run: | | |
cd app/web | |
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 }}" | |
VITE_UUID="$(uuid)" | |
export VITE_UUID | |
export VITE_AUTH_API_URL="https://auth-api.systeminit.com" | |
export VITE_AUTH_PORTAL_URL="https://auth.systeminit.com" | |
# Retry loop with 3 attempts | |
n=0 | |
max_retries=3 | |
until [ $n -ge $max_retries ] | |
do | |
unset exit_code || echo "exit_code not set" | |
# Run the npx task and store exit code in a variable | |
npx cypress run --spec "cypress/e2e/${{ matrix.tests }}/**" || exit_code=$? | |
if [[ "$(( ( RANDOM % 3 ) + 1 ))" == "3" ]]; then | |
echo "generic kaboom" | |
exit 53 | |
fi | |
# Check the exit code | |
if [ -z "$exit_code" ]; then | |
echo "Cypress Test task succeeded!" | |
break | |
fi | |
if [ $n -ge $max_retries ]; then | |
echo "All $max_retries attempts failed." | |
exit 1 | |
fi | |
n=$((n+1)) | |
echo "Attempt $n/$max_retries failed with exit code $exit_code! Retrying..." | |
done | |
- name: 'Upload Cypress Recordings to Github' | |
uses: actions/upload-artifact@v3 | |
if: failure() | |
with: | |
name: cypress-recordings-run-${{ matrix.tests }} | |
path: app/web/cypress/videos/**/*.mp4 | |
retention-days: 5 | |
- name: Check Test Results | |
if: failure() | |
run: exit 1 | |
on-failure: | |
runs-on: ubuntu-latest | |
needs: cypress-tests | |
if: ${{ failure() }} # && github.ref == 'refs/heads/main' }} | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: / | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: app | |
- name: Download all artifacts | |
uses: actions/download-artifact@v3 | |
- name: List available artifacts | |
run: ls -R app/web/cypress/videos || echo "nada" | |
- name: List available artifacts ii | |
run: ls ./ || echo "nada" | |
- run: | | |
has_artifacts=false | |
# Check for marker files | |
for marker in cypress-recordings-run*; do | |
if [ -f "$marker" ]; then | |
echo "Artifact detected for failed test: $marker" | |
echo "Setting failure to true and breaking" | |
has_artifacts=true | |
break | |
fi | |
done | |
# If at least one valid failure marker is present, then page | |
if [ "$has_artifacts" = true ]; then | |
curl --location "${{ secrets.FIREHYDRANT_WEBHOOK_URL }}" \ | |
--header "Content-Type: application/json" \ | |
--data "{ | |
\"summary\": \"E2E ${{ inputs.environment }} Tests Fail\", | |
\"body\": \"E2E Tests have failed for ${{ inputs.environment }}.\", | |
\"links\": [ | |
{ | |
\"href\": \"https://github.com/systeminit/si/actions/runs/$GITHUB_RUN_ID\", | |
\"text\": \"E2E Test Run ${{ inputs.environment }}\" | |
} | |
], | |
\"tags\": [ | |
\"service:github\" | |
] | |
}" | |
fi | |
- run: | | |
curl -X POST \ | |
--header '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 }} |