Skip to content
Latchkey

Flaky Test Detector workflow (usebruno/bruno)

The Flaky Test Detector workflow from usebruno/bruno, explained and optimized by Latchkey.

A

CI health: A - excellent

Point runs-on at Latchkey and get run de-duplication, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: usebruno/bruno.github/workflows/flaky-test-detector.ymlLicense MITView source

What it does

This is the Flaky Test Detector workflow from the usebruno/bruno repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Flaky Test Detector

on:
  pull_request:
    branches: [main]
    paths:
      - 'tests/**/*.spec.ts'

permissions:
  contents: read
  pull-requests: write
  issues: write
  checks: write

jobs:
  detect-flaky-tests:
    name: Detect Flaky Tests
    runs-on: ubuntu-24.04
    timeout-minutes: 60

    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 0  # Need full history to compare with main

      - name: Setup Node.js
        uses: actions/setup-node@v5
        with:
          node-version-file: '.nvmrc'
          cache: 'npm'

      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get --no-install-recommends install -y \
            libglib2.0-0 libnss3 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 \
            libcups2 libgtk-3-0 libasound2t64 xvfb

      - name: Install npm dependencies
        run: |
          npm ci --legacy-peer-deps
          CHROME_SANDBOX="${GITHUB_WORKSPACE}/node_modules/electron/dist/chrome-sandbox"
          if [[ -f "$CHROME_SANDBOX" ]]; then
            sudo chown root "$CHROME_SANDBOX"
            sudo chmod 4755 "$CHROME_SANDBOX"
          fi

      - name: Install test collection dependencies
        run: npm ci --prefix packages/bruno-tests/collection

      - name: Build libraries
        run: |
          npm run build:graphql-docs
          npm run build:bruno-query
          npm run build:bruno-common
          npm run sandbox:bundle-libraries --workspace=packages/bruno-js
          npm run build:bruno-converters
          npm run build:bruno-requests
          npm run build:schema-types
          npm run build:bruno-filestore

      - name: Run Playwright tests
        run: xvfb-run npm run test:e2e
        continue-on-error: true  # Continue even if tests fail

      - name: Detect flaky tests
        id: detect
        run: node .github/scripts/detect-flaky-tests.js
        continue-on-error: true  # Don't fail workflow if flaky tests found

      - name: Check modified flaky tests
        id: check-modified
        run: node .github/scripts/comment-on-flaky-tests.js
        continue-on-error: true

      - name: Post PR comment
        if: hashFiles('pr-comment.md') != ''
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const comment = fs.readFileSync('pr-comment.md', 'utf8');

            // Check if we already commented
            const { data: comments } = await github.rest.issues.listComments({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number
            });

            const botComment = comments.find(c =>
              c.user.type === 'Bot' && c.body.includes('Warning: You modified flaky/failed test files')
            );

            if (botComment) {
              // Update existing comment
              await github.rest.issues.updateComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                comment_id: botComment.id,
                body: comment
              });
            } else {
              // Create new comment
              await github.rest.issues.createComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.issue.number,
                body: comment
              });
            }

      - name: Upload flaky test artifacts
        if: always()
        uses: actions/upload-artifact@v6
        with:
          name: flaky-test-results
          path: |
            flaky-tests.json
            flaky-report.md
            playwright-report/
          retention-days: 30

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Flaky Test Detector
 
on:
  pull_request:
    branches: [main]
    paths:
      - 'tests/**/*.spec.ts'
 
permissions:
  contents: read
  pull-requests: write
  issues: write
  checks: write
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  detect-flaky-tests:
    name: Detect Flaky Tests
    runs-on: latchkey-small
    timeout-minutes: 60
 
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 0  # Need full history to compare with main
 
      - name: Setup Node.js
        uses: actions/setup-node@v5
        with:
          node-version-file: '.nvmrc'
          cache: 'npm'
 
      - name: Install system dependencies
        run: |
          sudo apt-get update
          sudo apt-get --no-install-recommends install -y \
            libglib2.0-0 libnss3 libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 \
            libcups2 libgtk-3-0 libasound2t64 xvfb
 
      - name: Install npm dependencies
        run: |
          npm ci --legacy-peer-deps
          CHROME_SANDBOX="${GITHUB_WORKSPACE}/node_modules/electron/dist/chrome-sandbox"
          if [[ -f "$CHROME_SANDBOX" ]]; then
            sudo chown root "$CHROME_SANDBOX"
            sudo chmod 4755 "$CHROME_SANDBOX"
          fi
 
      - name: Install test collection dependencies
        run: npm ci --prefix packages/bruno-tests/collection
 
      - name: Build libraries
        run: |
          npm run build:graphql-docs
          npm run build:bruno-query
          npm run build:bruno-common
          npm run sandbox:bundle-libraries --workspace=packages/bruno-js
          npm run build:bruno-converters
          npm run build:bruno-requests
          npm run build:schema-types
          npm run build:bruno-filestore
 
      - name: Run Playwright tests
        run: xvfb-run npm run test:e2e
        continue-on-error: true  # Continue even if tests fail
 
      - name: Detect flaky tests
        id: detect
        run: node .github/scripts/detect-flaky-tests.js
        continue-on-error: true  # Don't fail workflow if flaky tests found
 
      - name: Check modified flaky tests
        id: check-modified
        run: node .github/scripts/comment-on-flaky-tests.js
        continue-on-error: true
 
      - name: Post PR comment
        if: hashFiles('pr-comment.md') != ''
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const comment = fs.readFileSync('pr-comment.md', 'utf8');
 
            // Check if we already commented
            const { data: comments } = await github.rest.issues.listComments({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number
            });
 
            const botComment = comments.find(c =>
              c.user.type === 'Bot' && c.body.includes('Warning: You modified flaky/failed test files')
            );
 
            if (botComment) {
              // Update existing comment
              await github.rest.issues.updateComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                comment_id: botComment.id,
                body: comment
              });
            } else {
              // Create new comment
              await github.rest.issues.createComment({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.issue.number,
                body: comment
              });
            }
 
      - name: Upload flaky test artifacts
        if: always()
        uses: actions/upload-artifact@v6
        with:
          name: flaky-test-results
          path: |
            flaky-tests.json
            flaky-report.md
            playwright-report/
          retention-days: 30
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow