Refactors environment variable handling

Moves environment variable definitions to ensure they are available
before the docker container is created, resolving issues related to
undefined variables during container execution. Also, simplifies the
playwright report merging process by streamlining the execution of
commands within the docker container.
This commit is contained in:
maguire-arman 2025-07-09 14:07:50 -04:00
parent 44541ba00c
commit cd02d42da1

View file

@ -153,32 +153,32 @@ jobs:
echo "URL '$port' contains 'localhost'. Extracting port... " echo "URL '$port' contains 'localhost'. Extracting port... "
port=$(echo "$port" | sed -E 's/.*:([0-9]+).*/\1/') port=$(echo "$port" | sed -E 's/.*:([0-9]+).*/\1/')
echo "Port is '$port'" echo "Port is '$port'"
TARGET_URL="$TARGET_URL"
JIRA_CARD_NUMBER="$JIRA_CARD_NUMBER"
FILTER="$FILTER"
PLAYWRIGHT_PATH="${{ parameters.playwrightTestsPath }}"
SERVE_PATH="${{ parameters.npmServePath }}"
SHARD_NUMBER=$(shardNumber)
TOTAL_SHARDS=$(totalShards)
container_id=$(docker create \ container_id=$(docker create \
--ipc=host \ --ipc=host \
--env-file "${{ parameters.envFileName }}" \ --env-file "${{ parameters.envFileName }}" \
-e TARGET_URL="$TARGET_URL" \
-e JIRA_CARD_NUMBER="$JIRA_CARD_NUMBER" \
-e FILTER="$FILTER" \
-e PLAYWRIGHT_PATH="${{ parameters.playwrightTestsPath }}" \
-e SERVE_PATH="${{ parameters.npmServePath }}" \
-e SHARD_NUMBER=$(shardNumber) \
-e TOTAL_SHARDS=$(totalShards) \
${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \ ${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \
npx concurrently -k -n 'server,playwright' \ npx concurrently -k -n 'server,playwright' \
"npm --prefix $SERVE_PATH run serve -- --port=$port" \ "npm --prefix $SERVE_PATH run serve -- --port=$port" \
"npx --prefix $PLAYWRIGHT_PATH wait-on $TARGET_URL && npx --prefix $PLAYWRIGHT_PATH playwright test $PLAYWRIGHT_PATH --shard=$SHARD_NUMBER/$TOTAL_SHARDS --reporter=list,blob $FILTER" \ "npx --prefix $PLAYWRIGHT_PATH wait-on $TARGET_URL && npx --prefix $PLAYWRIGHT_PATH playwright test $PLAYWRIGHT_PATH --shard=$SHARD_NUMBER/$TOTAL_SHARDS --reporter=list,blob $FILTER" \
) )
else else
TARGET_URL="$TARGET_URL"
JIRA_CARD_NUMBER="$JIRA_CARD_NUMBER"
FILTER="$FILTER"
PLAYWRIGHT_PATH="${{ parameters.playwrightTestsPath }}"
SERVE_PATH="${{ parameters.npmServePath }}"
SHARD_NUMBER=$(shardNumber)
TOTAL_SHARDS=$(totalShards)
container_id=$(docker create \ container_id=$(docker create \
--ipc=host \ --ipc=host \
--env-file "${{ parameters.envFileName }}" \ --env-file "${{ parameters.envFileName }}" \
-e TARGET_URL="$TARGET_URL" \
-e JIRA_CARD_NUMBER="$JIRA_CARD_NUMBER" \
-e FILTER="$FILTER" \
-e PLAYWRIGHT_PATH=${{ parameters.playwrightTestsPath }} \
-e SERVE_PATH=${{ parameters.npmServePath }} \
-e SHARD_NUMBER=$(shardNumber) \
-e TOTAL_SHARDS=$(totalShards) \
${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \ ${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \
npx --prefix $PLAYWRIGHT_PATH playwright test $PLAYWRIGHT_PATH --shard=$SHARD_NUMBER/$TOTAL_SHARDS --reporter=list,blob $FILTER \ npx --prefix $PLAYWRIGHT_PATH playwright test $PLAYWRIGHT_PATH --shard=$SHARD_NUMBER/$TOTAL_SHARDS --reporter=list,blob $FILTER \
) )
@ -244,21 +244,21 @@ jobs:
echo "Retrieved branch name: '$branch_name'" echo "Retrieved branch name: '$branch_name'"
JIRA_CARD_NUMBER="${branch_name##*/}" JIRA_CARD_NUMBER="${branch_name##*/}"
echo "Extracted JIRA Card number: '$JIRA_CARD_NUMBER'" echo "Extracted JIRA Card number: '$JIRA_CARD_NUMBER'"
export PLAYWRIGHT_PATH="${{ parameters.playwrightTestsPath }}""
container_id=$(docker create \ container_id=$(docker create \
--ipc=host \ --ipc=host \
--env-file "${{ parameters.envFileName }}" \ --env-file "${{ parameters.envFileName }}" \
-e JIRA_CARD_NUMBER="$JIRA_CARD_NUMBER" \ -e JIRA_CARD_NUMBER="$JIRA_CARD_NUMBER" \
${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \ ${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \
export PLAYWRIGHT_PATH=${{ parameters.playwrightTestsPath }} bash -c " echo 'Moving Playwright reports out of subfolders...' \
echo 'Moving Playwright reports out of subfolders...' find ./playwright-reports/ -mindepth 2 -type f -exec mv {} ./playwright-reports/ \; \
find ./playwright-reports/ -mindepth 2 -type f -exec mv {} ./playwright-reports/ \; echo 'Merging reports...' \
echo 'Merging reports...' PLAYWRIGHT_JUNIT_OUTPUT_DIR='/app/test-results' PLAYWRIGHT_JUNIT_OUTPUT_NAME='junit_results.xml' npx --prefix $PLAYWRIGHT_PATH playwright merge-reports ./playwright-reports \
PLAYWRIGHT_JUNIT_OUTPUT_DIR='/app/test-results' PLAYWRIGHT_JUNIT_OUTPUT_NAME='junit_results.xml' npx --prefix $PLAYWRIGHT_PATH playwright merge-reports ./playwright-reports echo 'Contents of ortoni-report:' && ls ./ortoni-report \
echo 'Contents of ortoni-report:' && ls ./ortoni-report echo 'Current dir: ' && pwd \
echo 'Current dir: ' && pwd echo 'Contents of current dir: ' && ls \
echo 'Contents of current dir: ' && ls echo 'Contents of /app/test-results' && ls /app/test-results \
echo 'Contents of /app/test-results' && ls /app/test-results )
")
# Start container and stream logs # Start container and stream logs
echo "Starting merge" echo "Starting merge"
docker start -a $container_id docker start -a $container_id