Skip to content

Validate, Import and run E2E Tests #7

Validate, Import and run E2E Tests

Validate, Import and run E2E Tests #7

Workflow file for this run

name: Validate, Import and run E2E Tests
on:
pull_request:
types: [opened, synchronize]
workflow_run:
workflows: ["Clone Project"]
types:
- completed
env:
FILES_PATH: 'project-mvp-gold'
jobs:
validate:
name: Validate Snapshot
runs-on: ubuntu-latest
steps:
- name: Checkout Files
uses: actions/checkout@v4
- name: Get Cloned Project ID via API
id: get-cloned-project-id
run: |
max_attempts=20
delay_seconds=30
attempt=0
while [ $attempt -lt $max_attempts ]; do
attempt=$((attempt + 1))
echo "Attempt $attempt"
PR_NUMBER=$(echo "${GITHUB_REF}" | awk -F'/' '{print $3}')
COMMENTS=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments")
CLONED_PROJECT_ID=$(echo "$COMMENTS" | jq -r '.[] | select(.body | contains("CLONED_PROJECT_ID_'$PR_NUMBER'")) | .body' | cut -d '=' -f2)
if [ -z "$CLONED_PROJECT_ID" ]; then
echo "Failed to find CLONED_PROJECT_ID in the comments."
if [ $attempt -lt $max_attempts ]; then
echo "Retrying in $delay_seconds seconds..."
sleep $delay_seconds
else
echo "Max attempts reached. Exiting."
exit 1
fi
else
echo "CLONED_PROJECT_ID=$CLONED_PROJECT_ID" >> $GITHUB_ENV
echo "::set-output name=cloned_project_id::$CLONED_PROJECT_ID"
break
fi
done
- name: Validate Snapshot
id: validate
uses: descope/descopecli/.github/actions/[email protected]
with:
project_id: ${{ env.CLONED_PROJECT_ID }}
management_key: ${{ secrets.PRODUCTION_MANAGEMENT_KEY || secrets.MANAGEMENT_KEY }}
files_path: ${{ env.FILES_PATH }}
secrets: ${{ inputs.secrets }}
validate_only: true
import:
if: github.event.pull_request
runs-on: ubuntu-latest
needs: validate
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get Cloned Project ID via API
id: get-cloned-project-id
run: |
max_attempts=20
delay_seconds=30
attempt=0
while [ $attempt -lt $max_attempts ]; do
attempt=$((attempt + 1))
echo "Attempt $attempt"
PR_NUMBER=$(echo "${GITHUB_REF}" | awk -F'/' '{print $3}')
COMMENTS=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments")
CLONED_PROJECT_ID=$(echo "$COMMENTS" | jq -r '.[] | select(.body | contains("CLONED_PROJECT_ID_'$PR_NUMBER'")) | .body' | cut -d '=' -f2)
if [ -z "$CLONED_PROJECT_ID" ]; then
echo "Failed to find CLONED_PROJECT_ID in the comments."
if [ $attempt -lt $max_attempts ]; then
echo "Retrying in $delay_seconds seconds..."
sleep $delay_seconds
else
echo "Max attempts reached. Exiting."
exit 1
fi
else
echo "CLONED_PROJECT_ID=$CLONED_PROJECT_ID" >> $GITHUB_ENV
echo "::set-output name=cloned_project_id::$CLONED_PROJECT_ID"
break
fi
done
- name: Import Snapshot
id: import
uses: descope/descopecli/.github/actions/[email protected]
with:
project_id: ${{ env.CLONED_PROJECT_ID }}
management_key: ${{ secrets.PRODUCTION_MANAGEMENT_KEY || secrets.MANAGEMENT_KEY }}
files_path: ${{ env.FILES_PATH }}
secrets: ${{ inputs.secrets }}
import_only: true
e2e-tests:
if: github.event.pull_request
runs-on: ubuntu-latest
needs: import
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Get Cloned Project ID via API
id: get-cloned-project-id
run: |
max_attempts=20
delay_seconds=30
attempt=0
while [ $attempt -lt $max_attempts ]; do
attempt=$((attempt + 1))
echo "Attempt $attempt"
PR_NUMBER=$(echo "${GITHUB_REF}" | awk -F'/' '{print $3}')
COMMENTS=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments")
CLONED_PROJECT_ID=$(echo "$COMMENTS" | jq -r '.[] | select(.body | contains("CLONED_PROJECT_ID_'$PR_NUMBER'")) | .body' | cut -d '=' -f2)
if [ -z "$CLONED_PROJECT_ID" ]; then
echo "Failed to find CLONED_PROJECT_ID in the comments."
if [ $attempt -lt $max_attempts ]; then
echo "Retrying in $delay_seconds seconds..."
sleep $delay_seconds
else
echo "Max attempts reached. Exiting."
exit 1
fi
else
echo "CLONED_PROJECT_ID=$CLONED_PROJECT_ID" >> $GITHUB_ENV
echo "::set-output name=cloned_project_id::$CLONED_PROJECT_ID"
break
fi
done
- name: Cypress run
uses: cypress-io/github-action@v5
env:
MVP_GOLD_ID: ${{ env.CLONED_PROJECT_ID }}
MANAGEMENT_KEY: ${{ secrets.MANAGEMENT_KEY }}
with:
browser: chrome