|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Get all workspace names |
4 |
| -workspaces=$(yarn workspaces info | grep -o '@symfony/[^"]*') |
5 |
| - |
6 | 3 | # Flag to track if any test fails
|
7 | 4 | all_tests_passed=true
|
8 | 5 |
|
9 |
| -for workspace in $workspaces; do |
10 |
| - echo "Running tests in $workspace..." |
| 6 | +# Check if jq is installed |
| 7 | +if ! command -v jq &> /dev/null; then |
| 8 | + echo "jq is required but not installed. Aborting." |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +runTestSuite() { |
| 13 | + echo -e "Running tests for $workspace...\n" |
| 14 | + yarn workspace $workspace run vitest --run || { all_tests_passed=false; } |
| 15 | +} |
| 16 | + |
| 17 | +processWorkspace() { |
| 18 | + local workspace="$1" |
| 19 | + local location="$2" |
| 20 | + |
| 21 | + echo -e "Processing workspace $workspace at location $location...\n" |
| 22 | + |
| 23 | + package_json_path="$location/package.json" |
| 24 | + echo "Checking '$package_json_path' for peerDependencies with multiple versions defined" |
| 25 | + deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path") |
| 26 | + |
| 27 | + if [ -n "$deps_with_multiple_versions" ]; then |
| 28 | + echo " -> Multiple versions found for peerDependencies: $deps_with_multiple_versions" |
| 29 | + for library in $deps_with_multiple_versions; do |
| 30 | + versionValue=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path") |
| 31 | + |
| 32 | + IFS="||" read -ra versions <<< "$versionValue" |
| 33 | + |
| 34 | + for version in "${versions[@]}"; do |
| 35 | + trimmed_version=$(echo "$version" | tr -d '[:space:]') |
| 36 | + if [ -n "$trimmed_version" ]; then |
| 37 | + # Install each version of the library separately |
| 38 | + echo -e " - Install $library@$trimmed_version for $workspace\n" |
| 39 | + yarn workspace "$workspace" add "$library@$trimmed_version" --peer |
| 40 | + |
| 41 | + runTestSuite |
| 42 | + fi |
| 43 | + done |
| 44 | + done |
| 45 | + else |
| 46 | + echo -e " -> No peerDependencies found with multiple versions defined\n" |
| 47 | + runTestSuite |
| 48 | + fi |
| 49 | +} |
| 50 | + |
| 51 | +# Get all workspace names |
| 52 | +workspaces_info=$(yarn workspaces info) |
| 53 | + |
| 54 | +# Iterate over each workspace using process substitution |
| 55 | +while IFS= read -r workspace_info; do |
| 56 | + # Split the workspace_info into workspace and location |
| 57 | + workspace=$(echo "$workspace_info" | awk '{print $1}') |
| 58 | + location=$(echo "$workspace_info" | awk '{print $2}') |
| 59 | + |
| 60 | + # Call the function to process the workspace |
| 61 | + processWorkspace "$workspace" "$location" |
11 | 62 |
|
12 |
| - # Run the tests and if they fail, set the flag to false |
13 |
| - yarn workspace $workspace run vitest --run || { echo "$workspace failed"; all_tests_passed=false; } |
14 |
| -done |
| 63 | +done < <(echo "$workspaces_info" | jq -r 'to_entries[0:] | .[] | "\(.key) \(.value.location)"') |
15 | 64 |
|
16 | 65 | # Check the flag at the end and exit with code 1 if any test failed
|
17 | 66 | if [ "$all_tests_passed" = false ]; then
|
18 |
| - echo "Some tests failed." |
19 |
| - exit 1 |
| 67 | + echo "Some tests failed." |
| 68 | + exit 1 |
20 | 69 | else
|
21 |
| - echo "All tests passed!" |
22 |
| - exit 0 |
| 70 | + echo "All tests passed!" |
| 71 | + exit 0 |
23 | 72 | fi
|
0 commit comments