From 6b6dea089b205c1d1b734f9d519acc14b5fa48e7 Mon Sep 17 00:00:00 2001 From: John Watson Date: Wed, 9 Oct 2024 13:21:40 +0100 Subject: [PATCH] fix: amend numbering so it's reflective of the workspace being used to execute --- .github/workflows/run-api-test.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run-api-test.yml b/.github/workflows/run-api-test.yml index 600f128fbb..9c92196d7c 100644 --- a/.github/workflows/run-api-test.yml +++ b/.github/workflows/run-api-test.yml @@ -34,21 +34,24 @@ jobs: run: | # Find .ts files, remove ./ prefix, and format as JSON array files=$(find "." -mindepth 1 -maxdepth 1 -type f -name "*.ts" | sed -r "s/\.\/(.*)\.ts/\1/") + # Get the number of tests test_count=$(echo "$files" | wc -l) - + # Get the list of workspace IDs from the environment variable workspace_ids="${{ vars.API_TEST_WORKSPACE_IDS }}" - echo "workspace_ids found to be ${{ vars.API_TEST_WORKSPACE_IDS }}" + echo "workspace_ids found to be $workspace_ids" workspace_count=$(echo "$workspace_ids" | tr ',' '\n' | wc -l) # Validate that the number of workspace IDs matches the number of tests if [ "$test_count" -ne "$workspace_count" ]; then - echo "Error: The number of workspace IDs ($workspace_count) does not match the number of tests ($test_count)." - exit 1 + echo "Error: The number of workspace IDs ($workspace_count) does not match the number of tests ($test_count)." + exit 1 fi - # Format files as JSON array and output the result - indexed_files=$(echo "$files" | awk '{print "{\"name\": \"" $0 "\", \"index\": " NR-1 "}"}' | jq -s .) + # Format files as JSON array with correct numbering + indexed_files=$(echo "$files" | nl -w1 -s': ' | awk '{print "{\"name\": \"" substr($0, index($0,$2)) "\", \"index\": " $1-1 "}"}' | jq -s .) + + # Ensure indexed_files are formatted correctly test_output=$(echo "$indexed_files" | jq -c '.') echo "tests=$test_output" >> "$GITHUB_OUTPUT" echo "$test_output"