Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add workspace separation between API tests #4753

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions .github/workflows/run-api-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:
jobs:
define-test-matrix:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
tests: ${{ steps.tests.outputs.tests }}
steps:
Expand All @@ -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"

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading