From 577bf20dc6465bed3b3879ce8390ed7db560faa0 Mon Sep 17 00:00:00 2001 From: John Watson Date: Wed, 9 Oct 2024 12:52:38 +0100 Subject: [PATCH] feat: add workspace separation between API tests --- .github/workflows/run-api-test.yml | 38 +++++++++++++++++-- .../tests/{add_action.ts => 0-add_action.ts} | 0 ... 1-create_and_apply_across_change_sets.ts} | 0 ...nt.ts => 2-create_and_delete_component.ts} | 0 ...variant.ts => 3-create_and_use_variant.ts} | 0 ...e_two_components_connect_and_propagate.ts} | 0 ..._paul_stack.ts => 5-emulate_paul_stack.ts} | 0 ...d_changeset.ts => 6-get_head_changeset.ts} | 0 8 files changed, 34 insertions(+), 4 deletions(-) rename bin/si-api-test/tests/{add_action.ts => 0-add_action.ts} (100%) rename bin/si-api-test/tests/{create_and_apply_across_change_sets.ts => 1-create_and_apply_across_change_sets.ts} (100%) rename bin/si-api-test/tests/{create_and_delete_component.ts => 2-create_and_delete_component.ts} (100%) rename bin/si-api-test/tests/{create_and_use_variant.ts => 3-create_and_use_variant.ts} (100%) rename bin/si-api-test/tests/{create_two_components_connect_and_propagate.ts => 4-create_two_components_connect_and_propagate.ts} (100%) rename bin/si-api-test/tests/{emulate_paul_stack.ts => 5-emulate_paul_stack.ts} (100%) rename bin/si-api-test/tests/{get_head_changeset.ts => 6-get_head_changeset.ts} (100%) diff --git a/.github/workflows/run-api-test.yml b/.github/workflows/run-api-test.yml index 0fdb9608bb..f6af02c66e 100644 --- a/.github/workflows/run-api-test.yml +++ b/.github/workflows/run-api-test.yml @@ -24,6 +24,7 @@ on: jobs: define-test-matrix: runs-on: ubuntu-latest + environment: ${{ inputs.environment }} outputs: tests: ${{ steps.tests.outputs.tests }} steps: @@ -32,8 +33,26 @@ jobs: working-directory: bin/si-api-test/tests 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/" | jq -R -s 'split("\n") | map(select(length > 0))') - test_output=$(echo "$files" | jq -c '.') + files=$(find "." -mindepth 1 -maxdepth 1 -type f -name "*.ts" | sed -r "s/\.\/(.*)\.ts/\1/" | sort) + # 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 $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 + fi + + # Format files as JSON array with correct numbering and sorted order + indexed_files=$(echo "$files" | awk '{print "{\"name\": \"" $0 "\", \"index\": " NR-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" @@ -62,6 +81,17 @@ jobs: run: | cd bin/si-api-test + echo "Running test ${{ matrix.tests.name }} with index: ${{ matrix.tests.index }}" + + # Split the workspace IDs into an array + workspace_ids="${{ vars.API_TEST_WORKSPACE_IDS }}" + IFS=',' read -r -a workspace_array <<< "$workspace_ids" + + # Pick the correct workspace ID based on the index + workspace_id=${workspace_array[${{ matrix.tests.index }}]} + + echo "Using workspace ID: $workspace_id" + # Retry loop with 3 attempts n=0 max_retries=3 @@ -72,10 +102,10 @@ jobs: # Run the deno task and store exit code in a variable deno task run \ - --workspaceId ${{ vars.API_TEST_WORKSPACE_ID }} \ + --workspaceId "$workspace_id" \ --userId ${{ secrets.API_TEST_EMAIL }} \ --password ${{ secrets.API_TEST_PASSWORD }} \ - --tests ${{ matrix.tests }} || exit_code=$? + --tests ${{ matrix.tests.name }} || exit_code=$? # Check the exit code if [ -z "$exit_code" ]; then diff --git a/bin/si-api-test/tests/add_action.ts b/bin/si-api-test/tests/0-add_action.ts similarity index 100% rename from bin/si-api-test/tests/add_action.ts rename to bin/si-api-test/tests/0-add_action.ts diff --git a/bin/si-api-test/tests/create_and_apply_across_change_sets.ts b/bin/si-api-test/tests/1-create_and_apply_across_change_sets.ts similarity index 100% rename from bin/si-api-test/tests/create_and_apply_across_change_sets.ts rename to bin/si-api-test/tests/1-create_and_apply_across_change_sets.ts diff --git a/bin/si-api-test/tests/create_and_delete_component.ts b/bin/si-api-test/tests/2-create_and_delete_component.ts similarity index 100% rename from bin/si-api-test/tests/create_and_delete_component.ts rename to bin/si-api-test/tests/2-create_and_delete_component.ts diff --git a/bin/si-api-test/tests/create_and_use_variant.ts b/bin/si-api-test/tests/3-create_and_use_variant.ts similarity index 100% rename from bin/si-api-test/tests/create_and_use_variant.ts rename to bin/si-api-test/tests/3-create_and_use_variant.ts diff --git a/bin/si-api-test/tests/create_two_components_connect_and_propagate.ts b/bin/si-api-test/tests/4-create_two_components_connect_and_propagate.ts similarity index 100% rename from bin/si-api-test/tests/create_two_components_connect_and_propagate.ts rename to bin/si-api-test/tests/4-create_two_components_connect_and_propagate.ts diff --git a/bin/si-api-test/tests/emulate_paul_stack.ts b/bin/si-api-test/tests/5-emulate_paul_stack.ts similarity index 100% rename from bin/si-api-test/tests/emulate_paul_stack.ts rename to bin/si-api-test/tests/5-emulate_paul_stack.ts diff --git a/bin/si-api-test/tests/get_head_changeset.ts b/bin/si-api-test/tests/6-get_head_changeset.ts similarity index 100% rename from bin/si-api-test/tests/get_head_changeset.ts rename to bin/si-api-test/tests/6-get_head_changeset.ts