Skip to content

Instantly share code, notes, and snippets.

@alexandrosandre
Last active November 21, 2023 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandrosandre/467de0f691885cbb4652e4c6717c4486 to your computer and use it in GitHub Desktop.
Save alexandrosandre/467de0f691885cbb4652e4c6717c4486 to your computer and use it in GitHub Desktop.
Github Action for Trackingplan Regression Testing with Cypress
name: cypress-trackingplan
on:
push:
branches:
- master
- release/*
paths:
- "frontend/**"
- "deploy/**"
- ".github/workflows/cypress-trackingplan.yml"
defaults:
run:
shell: bash
working-directory: frontend/e2e_tests
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set CYPRESS_TEST_SESSION_NAME
run: |
BRANCH_NAME="${{ github.head_ref }}"
if [ -z "$BRANCH_NAME" ]; then
BRANCH_NAME=$(echo ${{ github.ref }} | sed 's/refs\/heads\///')
fi
echo "CYPRESS_TEST_SESSION_NAME=${BRANCH_NAME}_r${{ github.run_number }}_a${{ github.run_attempt }}" >> "$GITHUB_ENV"
- name: Test frontend panel with Cypress using Chrome
uses: cypress-io/github-action@v5
with:
browser: chrome
working-directory: frontend/e2e_tests
env:
CYPRESS_TEST_SESSION_NAME: ${{ env.CYPRESS_TEST_SESSION_NAME }}
- name: Wait for all the analytics to be sent and processed (or run other steps meanwhile)
uses: jakejarvis/wait-action@master
with:
time: "10s"
- name: Consult Trackingplan Regression Testing
run: |
# Call the API and save response to a file
curl --location 'https://eu-api.trackingplan.com/public/session_status/v1'\
'?tp_id=<YOUR_TP_ID>'\
'&environment=<YOUR_CI_CD_ENVIRONMENT>'\
'&test_session=${{ env.CYPRESS_TEST_SESSION_NAME }}'\
'&baseline_session=default'\
'&sharing=<YOUR_SHARING_API_TOKEN>'\
'&destination=<OPTIONALLY_FILTER_TO_SINGLE_DESTINATION>' > tp-status.json
STATUS=$(jq -r '.status' tp-status.json)
echo "The Trackingplan Regression Testing status is $STATUS."
if [ "$STATUS" == "Not found" ]; then
echo "Test session not found. Please try again later."
exit 1
fi
if [ "$STATUS" != "OK" ]; then
echo "Test failed. Setting job status to failed."
echo "See detailed test results below:\n"
cat tp-status.json | jq
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment