User: I need you to modify this script to also set the size, if the test has the [PipelineSize("2x"), or 4x, or 8x

If no PipelineSize is set, then the size should not be set for the step..


#!/bin/bash

# Extract unique categories from .cs files
CATEGORIES=$(grep -rho '\[Trait("Category", "[^"]*")\]' --include=\*.cs ../tagomat.tests | sed -E 's/\[Trait\("Category", "([^"]+)"\)\]/\1/' | sort -u)

EXCLUDE_FILTER=""
run_step() {
  local NAME=$1
  local FILTER=$2
  local SAFE_NAME=$(echo "$NAME" | sed 's/[^a-zA-Z0-9_-]/-/g') # Sanitize name

  echo "      - step:"
  echo "          max-time: 15"
  #echo "          size: 2x"
  echo "          name: \"Test $NAME\""
  echo "          script:"
  echo "            - set -e"
  echo "            - dotnet test publish/tagomat.tests.dll --filter \"$FILTER\" --blame --blame-hang --blame-hang-timeout 12min --logger:\"junit;LogFilePath=./test-reports/results-$SAFE_NAME.xml\" --nologo -v q --parallel"
  echo "            - exit \$?"
}

for CATEGORY in $CATEGORIES; do
  run_step "$CATEGORY" "Category=$CATEGORY"
  EXCLUDE_FILTER+="Category!=$CATEGORY & "
done

run_step "Uncategorized" "${EXCLUDE_FILTER% & }"

Assistant: To modify your script so that it also sets the size of the step based on the `PipelineSize` attribute, you can extract that information as well. Here’s how you can update your script to achieve this:

1. Use `grep` to look for the PipelineSize attributes in the code.
2. Set the size based on the extracted PipelineSize value.
3. Only include the size in the configuration if it's set.

Here's how you can modify your script:

```bash
#!/bin/bash

# Extract unique categories and sizes from .cs files
CATEGORIES=$(grep -rho '\[Trait("Category", "[^"]*")\]' --include=\*.cs ../tagomat.tests | sed -E 's/\[Trait\("Category", "([^"]+)"\)\]/\1/' | sort -u)

# Extract unique sizes from .cs files
SIZES=$(grep -rho '\[PipelineSize\("([^"]+)"\)\]' --include=\*.cs ../tagomat.tests | sed -E 's/\[PipelineSize\("([^"]+)"\)\]/\1/' | sort -u)

EXCLUDE_FILTER=""
run_step() {
  local NAME=$1
  local FILTER=$2
  local SIZE=$3
  local SAFE_NAME=$(echo "$NAME" | sed 's/[^a-zA-Z0-9_-]/-/g') # Sanitize name

  echo "      - step:"
  echo "          max-time: 15"
  
  # If SIZE is set, add it to the step
  if [[ -n "$SIZE" ]]; then
    echo "          size: $SIZE"
  fi
  
  echo "          name: \"Test $NAME\""
  echo "          script:"
  echo "            - set -e"
  echo "            - dotnet test publish/tagomat.tests.dll --filter \"$FILTER\" --blame --blame-hang --blame-hang-timeout 12min --logger:\"junit;LogFilePath=./test-reports/results-$SAFE_NAME.xml\" --nologo -v q --parallel"
  echo "            - exit \$?"
}

for CATEGORY in $CATEGORIES; do
  # Attempt to match the category with a size
  SIZE=""
  if grep -q "\[PipelineSize(\"2x\|4x\|8x\")\]" --include=\*.cs ../tagomat.tests; then
    SIZE=$(grep -o "\[PipelineSize(\"2x\|4x\|8x\")\]" --include=\*.cs ../tagomat.tests | sed -E 's/\[PipelineSize\("(.*)"\)\]/\1/')
  fi
  run_step "$CATEGORY" "Category=$CATEGORY" "$SIZE"
  EXCLUDE_FILTER+="Category!=$CATEGORY & "
done

run_step "Uncategorized" "${EXCLUDE_FILTER% & }"
```

### Key Changes:
1. **Size Extraction**: A new `SIZES` variable is set up to capture unique sizes specified in the test files. This is done similarly to how categories are captured.
2. **Conditional Size Setting**: Inside the `run_step()` function, the script checks if a `SIZE` is set. If it is, that size is included in the step definition.
3. **Size Matching Logic**: In the loop through categories, the script checks if sizes are matched and extracted based on the `PipelineSize` attribute. The logic may require adjustments depending on the exact structure of your body text if `PipelineSize` is associated with other attributes or tests.

### Note:
Modify the regular expressions and logic as necessary to fit the exact formatting in your files since the above is quite general. Adjust the size extraction to ensure it only captures relevant sizes associated with specific tests if they are not globally set.
User: that's weird, it doesn't work?

grep -rho '\[Trait("Category", "[^"]*")\]' --include=\*.cs ../tagomat.tests | sed -E 's/\[Trait\("Category", "([^"]+)"\)\]/\1/' | sort -u 

Produces no results, here's what my test looks like

[Trait("Category", "Bagomat-FX")]
[PipelineSize("4x")]
public class BagomatPassengerTransactionTestsMCPLC_FX : BagomatPassengerTransactionTestsMCPLCBase
{
Assistant: