ci: Add dynamic shard count calculation for Playwright tests in CI workflow (#4844)
* Add dynamic shard count calculation for Playwright tests in CI workflow * Fix incorrect format for shardTotal in TypeScript test workflow * Enhance CI workflow by dynamically generating shard indices using JSON array * Set default test suites to an empty array in TypeScript CI workflow * Improve shard index array creation using jq in CI workflow * Add Playwright installation step to CI workflow * Update CI workflow to use setup-node and install Node.js dependencies * Refactor shard index array creation in CI workflow for proper escaping * Refactor CI workflow to use matrix combinations for test sharding * Refactor CI workflow to improve matrix handling and shard configuration * Remove redundant condition from Playwright Tests job in CI workflow * Add grep pattern for release tests and conditional job execution in CI workflow
This commit is contained in:
parent
1962e48266
commit
c941936db3
1 changed files with 55 additions and 11 deletions
66
.github/workflows/typescript_test.yml
vendored
66
.github/workflows/typescript_test.yml
vendored
|
|
@ -33,7 +33,7 @@ on:
|
|||
description: "Test suites to run (JSON array)"
|
||||
required: false
|
||||
type: string
|
||||
default: '["starter-projects", "components", "workspace", "api", "database"]'
|
||||
default: '[]'
|
||||
release:
|
||||
description: "Whether this is a release build"
|
||||
required: false
|
||||
|
|
@ -56,8 +56,9 @@ jobs:
|
|||
determine-test-suite:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
suites: ${{ steps.set-matrix.outputs.matrix }}
|
||||
matrix: ${{ steps.setup-matrix.outputs.matrix }}
|
||||
test_grep: ${{ steps.set-matrix.outputs.test_grep }}
|
||||
suites: ${{ steps.set-matrix.outputs.suites }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
|
|
@ -86,8 +87,8 @@ jobs:
|
|||
if [[ "$RELEASE" == "true" ]]; then
|
||||
SUITES='["release"]'
|
||||
echo "Release build detected - setting suites to: $SUITES"
|
||||
# No grep pattern for release - run all tests
|
||||
TEST_GREP=""
|
||||
# grep pattern for release is the @release tag - run all tests
|
||||
TEST_GREP="--grep=\"@release\""
|
||||
else
|
||||
# If input suites were not provided, determine based on changes
|
||||
if [[ "$SUITES" == "[]" ]]; then
|
||||
|
|
@ -162,16 +163,59 @@ jobs:
|
|||
echo "matrix=$(echo $SUITES | jq -c .)" >> $GITHUB_OUTPUT
|
||||
echo "test_grep=$TEST_GREP" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Setup Node ${{ env.NODE_VERSION }}
|
||||
uses: actions/setup-node@v4
|
||||
id: setup-node
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
cache: "npm"
|
||||
cache-dependency-path: ./src/frontend/package-lock.json
|
||||
|
||||
- name: Install Node.js dependencies
|
||||
run: npm ci
|
||||
working-directory: ./src/frontend
|
||||
|
||||
- name: Setup Matrix Combinations
|
||||
id: setup-matrix
|
||||
run: |
|
||||
cd src/frontend
|
||||
|
||||
# Get the test count using playwright's built-in grep
|
||||
if [ -n "${{ steps.set-matrix.outputs.test_grep }}" ]; then
|
||||
TEST_COUNT=$(npx playwright test ${{ inputs.tests_folder }} ${{ steps.set-matrix.outputs.test_grep }} --list | wc -l)
|
||||
else
|
||||
TEST_COUNT=$(npx playwright test ${{ inputs.tests_folder }} --list | wc -l)
|
||||
fi
|
||||
|
||||
echo "Total tests to run: $TEST_COUNT"
|
||||
|
||||
# Calculate optimal shard count - 1 shard per 5 tests, min 1, max 10
|
||||
SHARD_COUNT=$(( (TEST_COUNT + 4) / 5 ))
|
||||
if [ $SHARD_COUNT -lt 1 ]; then
|
||||
SHARD_COUNT=1
|
||||
elif [ $SHARD_COUNT -gt 10 ]; then
|
||||
SHARD_COUNT=10
|
||||
fi
|
||||
|
||||
# Create the matrix combinations string
|
||||
MATRIX_COMBINATIONS=""
|
||||
for i in $(seq 1 $SHARD_COUNT); do
|
||||
if [ $i -gt 1 ]; then
|
||||
MATRIX_COMBINATIONS="$MATRIX_COMBINATIONS,"
|
||||
fi
|
||||
MATRIX_COMBINATIONS="$MATRIX_COMBINATIONS{\"shardIndex\": $i, \"shardTotal\": $SHARD_COUNT}"
|
||||
done
|
||||
|
||||
echo "matrix={\"include\":[$MATRIX_COMBINATIONS]}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
setup-and-test:
|
||||
name: Playwright Tests - Group ${{ matrix.shardIndex }}
|
||||
name: Playwright Tests - Group ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ needs.determine-test-suite.outputs.test_grep != '' }}
|
||||
needs: determine-test-suite
|
||||
if: ${{ fromJson(needs.determine-test-suite.outputs.suites)[0] != null }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
shardIndex: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
shardTotal: [10]
|
||||
matrix: ${{ fromJson(needs.determine-test-suite.outputs.matrix) }}
|
||||
env:
|
||||
OPENAI_API_KEY: ${{ inputs.openai_api_key || secrets.OPENAI_API_KEY }}
|
||||
STORE_API_KEY: ${{ inputs.store_api_key || secrets.STORE_API_KEY }}
|
||||
|
|
@ -226,8 +270,8 @@ jobs:
|
|||
command: |
|
||||
cd src/frontend
|
||||
echo 'Running tests with pattern: ${{ needs.determine-test-suite.outputs.test_grep }}'
|
||||
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --list
|
||||
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --trace on --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers 2
|
||||
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --shard ${{ matrix.shardIndex }} --list
|
||||
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --trace on --shard ${{ matrix.shardIndex }} --workers 2
|
||||
|
||||
- name: Upload blob report to GitHub Actions Artifacts
|
||||
if: always()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue