Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devex): cypress roulette #29181

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
51 changes: 28 additions & 23 deletions .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:

jobs:
changes:
runs-on: ubuntu-24.04
runs-on: depot-ubuntu-24.04-4
timeout-minutes: 5
name: Determine need to run E2E checks
# Set job outputs to values from filter step
Expand All @@ -40,6 +40,7 @@ jobs:
- package.json
- pnpm-lock.yaml
- .github/actions/build-n-cache-image/action.yml
- .github/workflows/ci-e2e.yml
# We use docker compose for tests, make sure we rerun on
# changes to docker-compose.dev.yml e.g. dependency
# version changes
Expand All @@ -50,45 +51,49 @@ jobs:
chunks:
needs: changes
name: Cypress preparation
runs-on: ubuntu-24.04
runs-on: depot-ubuntu-24.04-4
timeout-minutes: 5
outputs:
chunks: ${{ steps.chunk.outputs.chunks }}
steps:
- name: Check out
uses: actions/checkout@v3

- name: Group spec files into chunks of three
- name: Pick 4 random spec files
Copy link
Member

Choose a reason for hiding this comment

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

I do think once a day we should run them all and send an event to posthog on failure so we can alert from CDP / track incidence

but otherwise 100

these tests are slow and low value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that works for me. Though the only thing these tests actually test for me is that the plugin server is running. I didn't (yet) explicitly verify if the same issue causes playwright to break as well... will report back.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For clarity I put the name of the test into the action's name, but this just means none will actually be required:

image

Copy link
Member

Choose a reason for hiding this comment

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

yeah, they're a bit of a dead end cos everyone just finds them annoying...

Copy link
Member

Choose a reason for hiding this comment

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

yep, we'd make them not required and tell everyone, plz be careful-er now

any migration to playwright that is done carefully will just take too long

id: chunk
run: |
cd cypress
# Grab all .cy.ts files in e2e/
files=$(ls e2e/*.cy.ts || true)
files=$(ls e2e/*.cy.ts 2>/dev/null || true)

# If no files exist, handle that gracefully:
# If no files exist, handle that gracefully
if [ -z "$files" ]; then
echo "chunks=[]" >> "$GITHUB_OUTPUT"
exit 0
fi

# 1. Chunk these filenames in groups of 2, then join each group with commas
chunked=$(echo "$files" | xargs -n2 | sed 's/ /,/g')
# Use the commit's SHA as a seeded random source. -n = no newline
echo -n "cf73187282afdf3d7cd5e403ae1286955d7af992" | xxd -r -p > /tmp/random_source

# 2. Convert each line into a JSON string, then produce a SINGLE-LINE JSON array
# Use `-c` for "compact" (no extra newlines).
chunk_array=$(echo "$chunked" | jq -R . | jq -s -c .)
# Shuffle (seeded by the random_source) and pick up to 4
selected=$(echo "$files" | shuf --random-source=/tmp/random_source -n 4)

# 3. Escape special characters for GitHub output:
# We want a JSON array like ["testA.cy.ts","testB.cy.ts"]
# 1. Each filename -> JSON string
# 2. Collect into a JSON array
chunk_array=$(echo "$selected" | jq -R . | jq -s -c .)

# Escape % / newlines for GITHUB_OUTPUT
chunk_array="${chunk_array//'%'/'%25'}"
chunk_array="${chunk_array//$'\n'/'%0A'}"
chunk_array="${chunk_array//$'\r'/'%0D'}"

# 4. Finally, write to GITHUB_OUTPUT in valid "key=value" form
# Finally, store as 'chunks' output
echo "chunks=$chunk_array" >> "$GITHUB_OUTPUT"

container:
name: Build and cache container image
runs-on: ubuntu-24.04
runs-on: depot-ubuntu-24.04-4
timeout-minutes: 60
needs: [changes]
permissions:
Expand All @@ -111,8 +116,8 @@ jobs:
actions-id-token-request-url: ${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }}

cypress:
name: Cypress E2E tests (${{ strategy.job-index }})
runs-on: ubuntu-24.04
name: Cypress E2E (${{ matrix.spec }})
runs-on: depot-ubuntu-24.04-4
timeout-minutes: 60
needs: [chunks, changes, container]
permissions:
Expand All @@ -124,7 +129,7 @@ jobs:
# we want to know about.
fail-fast: false
matrix:
chunk: ${{ fromJson(needs.chunks.outputs.chunks) }}
spec: ${{ fromJson(needs.chunks.outputs.chunks) }}

steps:
- name: Checkout
Expand Down Expand Up @@ -256,7 +261,7 @@ jobs:
uses: cypress-io/github-action@v6
with:
install-command: 'pnpm --filter=@posthog/cypress... install --frozen-lockfile'
command: 'pnpm --filter=@posthog/cypress exec cypress run --config-file cypress.e2e.config.ts --spec ${{ matrix.chunk }} --headed'
command: 'pnpm --filter=@posthog/cypress exec cypress run --config-file cypress.e2e.config.ts --spec ${{ matrix.spec }} --headed'
# We were seeing suprising crashes in headless mode
# See https://github.com/cypress-io/cypress/issues/28893#issuecomment-1956480875
env:
Expand All @@ -267,43 +272,43 @@ jobs:
- name: Archive test screenshots
uses: actions/upload-artifact@v4
with:
name: screenshots-${{ strategy.job-index }}
name: screenshots-${{ matrix.spec }}
path: cypress/screenshots
if: ${{ failure() }}

- name: Archive test downloads
uses: actions/upload-artifact@v4
with:
name: downloads-${{ strategy.job-index }}
name: downloads-${{ matrix.spec }}
path: cypress/downloads
if: ${{ failure() }}

- name: Archive test videos
uses: actions/upload-artifact@v4
with:
name: videos-${{ strategy.job-index }}
name: videos-${{ matrix.spec }}
path: cypress/videos
if: ${{ failure() }}

- name: Archive accessibility violations
if: needs.changes.outputs.shouldTriggerCypress == 'true'
uses: actions/upload-artifact@v4
with:
name: accessibility-violations-${{ strategy.job-index }}
name: accessibility-violations-${{ matrix.spec }}
path: '**/a11y/'
if-no-files-found: 'ignore'

- name: Show logs on failure
# use artefact here, as I think the output will be too large for display in an action
uses: actions/upload-artifact@v4
with:
name: logs-${{ strategy.job-index }}
name: logs-${{ matrix.spec }}
path: /tmp/logs
if: ${{ failure() }}

calculate-running-time:
name: Calculate running time
runs-on: ubuntu-24.04
runs-on: depot-ubuntu-24.04-4
needs: [cypress]
if: needs.changes.outputs.shouldTriggerCypress == 'true' &&
github.event.pull_request.head.repo.full_name == 'PostHog/posthog'
Expand Down
Loading