diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 82b0951dc7a..302b2056bba 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -143,5 +143,5 @@ jobs: key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }} restore-keys: | ${{ runner.os }}-yarn- - - run: yarn --frozen-lockfile + - run: yarn --immutable - run: yarn test diff --git a/bin/run-vitest-all.sh b/bin/run-vitest-all.sh index 0fe315baa9b..fa40dc1ee00 100755 --- a/bin/run-vitest-all.sh +++ b/bin/run-vitest-all.sh @@ -1,23 +1,72 @@ #!/bin/bash -# Get all workspace names -workspaces=$(yarn workspaces info | grep -o '@symfony/[^"]*') - # Flag to track if any test fails all_tests_passed=true -for workspace in $workspaces; do - echo "Running tests in $workspace..." +# Check if jq is installed +if ! command -v jq &> /dev/null; then + echo "jq is required but not installed. Aborting." + exit 1 +fi + +runTestSuite() { + echo -e "Running tests for $workspace...\n" + yarn workspace $workspace run vitest --run || { all_tests_passed=false; } +} + +processWorkspace() { + local workspace="$1" + local location="$2" + + echo -e "Processing workspace $workspace at location $location...\n" + + package_json_path="$location/package.json" + echo "Checking '$package_json_path' for peerDependencies with multiple versions defined" + deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path") + + if [ -n "$deps_with_multiple_versions" ]; then + echo " -> Multiple versions found for peerDependencies: $deps_with_multiple_versions" + for library in $deps_with_multiple_versions; do + versionValue=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path") + + IFS="||" read -ra versions <<< "$versionValue" + + for version in "${versions[@]}"; do + trimmed_version=$(echo "$version" | tr -d '[:space:]') + if [ -n "$trimmed_version" ]; then + # Install each version of the library separately + echo -e " - Install $library@$trimmed_version for $workspace\n" + yarn workspace "$workspace" add "$library@$trimmed_version" --peer + + runTestSuite + fi + done + done + else + echo -e " -> No peerDependencies found with multiple versions defined\n" + runTestSuite + fi +} + +# Get all workspace names +workspaces_info=$(yarn workspaces info) + +# Iterate over each workspace using process substitution +while IFS= read -r workspace_info; do + # Split the workspace_info into workspace and location + workspace=$(echo "$workspace_info" | awk '{print $1}') + location=$(echo "$workspace_info" | awk '{print $2}') + + # Call the function to process the workspace + processWorkspace "$workspace" "$location" - # Run the tests and if they fail, set the flag to false - yarn workspace $workspace run vitest --run || { echo "$workspace failed"; all_tests_passed=false; } -done +done < <(echo "$workspaces_info" | jq -r 'to_entries[0:] | .[] | "\(.key) \(.value.location)"') # Check the flag at the end and exit with code 1 if any test failed if [ "$all_tests_passed" = false ]; then - echo "Some tests failed." - exit 1 + echo "Some tests failed." + exit 1 else - echo "All tests passed!" - exit 0 + echo "All tests passed!" + exit 0 fi