Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions web/cypress/run-changed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

CHANGED_FILES=$(git diff --name-only origin/main...HEAD)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target branch might be different we should provide it from env defaulting to main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add error handling, in shallow checkouts the main branch might not exist.


RUN_ALL=false
declare -A TAGS_TO_RUN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to change this into something POSIX compatible, I got the following issue while trying to run on mac:

./cypress/run-changed.sh: line 6: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]


# Create frontend folder to tag map
declare -A FEATURE_MAP
FEATURE_MAP["incidents"]="@cluster-health-analyzer"
FEATURE_MAP["alerts"]="@alerting"
FEATURE_MAP["legacy-dashboards"]="@legacy-dashboards"
FEATURE_MAP["metrics"]="@metrics"
FEATURE_MAP["perses-dashboards"]="@perses-dashboards"
FEATURE_MAP["targets"]="@targets"

for FILE in $CHANGED_FILES; do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we have file paths with white spaces, but this will split on white space


# Check if any file is outside of web/src/features/
if [[ ! "$FILE" =~ ^web/src/features/ ]]; then
echo "Global or shared file changed: $FILE"
RUN_ALL=true
break
fi

# File is in features and looks like: web/src/features/incidents/components/App.tsx
# awk splits by '/' and grabs the 4th segment
FEATURE_DIR=$(echo "$FILE" | awk -F'/' '{print $4}')
CYPRESS_TAG=${FEATURE_MAP[$FEATURE_DIR]}

if [ -n "$CYPRESS_TAG" ]; then
TAGS_TO_RUN["$CYPRESS_TAG"]=1
else
echo "Error: Unmapped feature directory changed: $FEATURE_DIR"
exit 1
fi
done

if [ "$RUN_ALL" = true ]; then
echo "Changes affect global scope or unmapped features. Running ALL monitoring tests..."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unmapped features already exits

Suggested change
echo "Changes affect global scope or unmapped features. Running ALL monitoring tests..."
echo "Changes affect global scope. Running ALL monitoring tests..."


DEFAULT_TAGS="@alerting @legacy-dashboards @metrics @targets acm-alerting @cluster-health-analyzer @perses-dashboards --@flaky --@xfail"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEFAULT_TAGS="@alerting @legacy-dashboards @metrics @targets acm-alerting @cluster-health-analyzer @perses-dashboards --@flaky --@xfail"
DEFAULT_TAGS="@alerting @legacy-dashboards @metrics @targets @acm-alerting @cluster-health-analyzer @perses-dashboards --@flaky --@xfail"

npm run test-cypress-monitoring:base -- --env grepTags="${DEFAULT_TAGS}"
else
UNIQUE_TAGS=("${!TAGS_TO_RUN[@]}")

if [ ${#UNIQUE_TAGS[@]} -eq 0 ]; then
echo "No relevant source files changed. Skipping tests."
exit 0
fi

FEATURE_TAGS=$(
IFS=" "
echo "${UNIQUE_TAGS[*]}"
)

GREP_TAGS="${FEATURE_TAGS} --@flaky --@xfail"

echo "Running specific tests for tags: $GREP_TAGS"

npm run test-cypress-monitoring:base -- --env grepTags="${GREP_TAGS}"
fi
18 changes: 2 additions & 16 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,8 @@
"test:unit": "TZ=UTC jest --config jest.config.js --passWithNoTests",
"test:unit:ci": "TZ=UTC jest --config jest.config.js --passWithNoTests --maxWorkers=2",
"test": "npm run cypress:run:ci",
"test-cypress-console": "./node_modules/.bin/cypress open --browser chrome",
"test-cypress-console-headless": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless",
"test-cypress-monitoring": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting+@legacy-dashboards+@metrics+@targets --@flaky --@xfail'",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update the cypress docs with these removals?

"test-cypress-monitoring-dev": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting+@legacy-dashboards+@metrics+@targets --@xfail'",
"test-cypress-monitoring-bvt": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting+@legacy-dashboards+@metrics+@targets --@xfail'",
"test-cypress-monitoring-regression": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting+@legacy-dashboards+@metrics+@targets --@flaky --@xfail'",
"test-cypress-alerts": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@alerting --@flaky --@xfail'",
"test-cypress-metrics": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@metrics --@flaky --@xfail'",
"test-cypress-dashboards": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@legacy-dashboards --@flaky --@xfail'",
"test-cypress-coo": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@acm-alerting+@perses-dashboards+@cluster-health-analyzer --@flaky --@xfail'",
"test-cypress-coo-bvt": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@acm-alerting+@perses-dashboards+@cluster-health-analyzer --@xfail'",
"test-cypress-incidents": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@cluster-health-analyzer --@flaky --@xfail'",
"test-cypress-incidents-e2e": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@cluster-health-analyzer --@flaky --@xfail'",
"test-cypress-perses-dev": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@perses-dashboards --@xfail'",
"test-cypress-perses": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@perses-dashboards --@smoke --@flaky --@xfail'",
"test-cypress-perses-ivt": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless --env grepTags='@perses-dashboards --@smoke --@flaky --@xfail'",
"test-cypress-monitoring": "../scripts/run-selective-e2e.sh",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script in a different PR or should be ./cypress/run-changed.sh

"test-cypress-monitoring:base": "node --max-old-space-size=4096 ./node_modules/.bin/cypress run --browser chrome --headless",
"ts-node": "ts-node -O '{\"module\":\"commonjs\"}'"
},
"dependencies": {
Expand Down