Skip to content

Commit 50e6c8d

Browse files
fix: parse test results in separate step (#17)
Move parsing of all test results out of the run_tests step, and into a separate step that is always run even if test commands fail. This will ensure that whatever test results were generated are always made available to users of this action
1 parent da99757 commit 50e6c8d

1 file changed

Lines changed: 45 additions & 32 deletions

File tree

action.yml

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ inputs:
3030
outputs:
3131
testExecutionLinks:
3232
description: 'Outputs a comma-separated list of Orchestrator links for viewing test results'
33-
value: ${{ steps.run_tests.outputs.testExecutionLinks }}
33+
value: ${{ steps.parse_test_results.outputs.testExecutionLinks }}
3434
testResults:
3535
description: 'Markdown formatted table listing the tests that have been run and whether they passed or failed'
36-
value: ${{ steps.run_tests.outputs.testResults }}
36+
value: ${{ steps.parse_test_results.outputs.testResults }}
3737
containsPublishableTestCases:
3838
description: 'Boolean value indicating whether any test cases set as publishable were found in the repository'
3939
value: ${{ steps.run_tests.outputs.containsPublishableTestCases }}
@@ -84,6 +84,7 @@ runs:
8484
run: |
8585
testsFailed=0
8686
testResultsFolder="${{ github.workspace }}/test-results"
87+
echo "testResultsFolder=$testResultsFolder" >> $GITHUB_OUTPUT
8788
mkdir -p "$testResultsFolder"
8889
testResults=""
8990
testExecutionBaseURL="${{ inputs.orchestratorUrl }}${{ inputs.orchestratorLogicalName }}/${{ inputs.orchestratorTenant }}/orchestrator_/test/executions/"
@@ -107,6 +108,7 @@ runs:
107108
publishableTests=$(echo "$fileInfoCollection" | jq '[.[] | select(.editingStatus == "Publishable")] | length')
108109
if [ "$publishableTests" -gt 0 ]; then
109110
repositoryContainsTests=1
111+
echo "containsPublishableTestCases=true" >> $GITHUB_OUTPUT
110112
testResultFilePath="$testResultsFolder/$(echo "$projectInfo" | jq -r '.name')-testresults.json"
111113
112114
echo "Running tests for project $(echo "$projectInfo" | jq -r '.name')"
@@ -121,28 +123,6 @@ runs:
121123
--result_path "$testResultFilePath" \
122124
--language en-US
123125
124-
testResultData=$(cat "$testResultFilePath" | jq '.')
125-
testCaseExecutions=$(echo "$testResultData" | jq -c '.TestSetExecutions[] | .TestCaseExecutions')
126-
folderId="${{ steps.get_folder_id.outputs.folderId }}"
127-
testSetExecutionLink="$testExecutionBaseURL$(echo "$testResultData" | jq -r '.TestSetExecutions[0].Id')?fid=$folderId"
128-
129-
echo "Test execution can be viewed in Orchestrator by clicking this link: $testSetExecutionLink"
130-
131-
testResultsTable="| Test case | Result |\n| :-- | :-- |"
132-
while IFS= read -r testCase; do
133-
testName=$(echo "$testCase" | jq -r '.Name')
134-
testStatus=$(echo "$testCase" | jq -r '.Status')
135-
testResultsTable+="\n| $testName | $(if [ "$testStatus" == "Passed" ]; then echo ":white_check_mark: Passed"; else echo ":x: Failed"; fi) |"
136-
done < <(echo "$testCaseExecutions" | jq -c '.[]')
137-
138-
testResults+="\n### [Test results for $(echo "$testResultData" | jq -r '.TestSetExecutions[0].Name')]($testSetExecutionLink)\n$testResultsTable"
139-
140-
if [ -z "$testExecutionURLs" ]; then
141-
testExecutionURLs="$testSetExecutionLink"
142-
else
143-
testExecutionURLs+=", $testSetExecutionLink"
144-
fi
145-
146126
if [ $? -ne 0 ]; then
147127
testsFailed=1
148128
fi
@@ -156,27 +136,60 @@ runs:
156136
fi
157137
done <<< "$projectJsonFiles"
158138
159-
echo "testExecutionLinks=$testExecutionURLs" >> $GITHUB_OUTPUT
160-
echo -e "testResults<<EOF\n$testResults\nEOF" >> $GITHUB_OUTPUT
161139
140+
# Output that no tests were found
162141
if [ "$repositoryContainsTests" -eq 0 ]; then
163-
echo "No publishable UiPath test cases were found in this repository. Testing has been skipped." > "$testResultsFolder/test.txt"
142+
echo "No publishable UiPath test cases were found in this repository. Testing has been skipped."
164143
echo "containsPublishableTestCases=false" >> $GITHUB_OUTPUT
165-
else
166-
echo "containsPublishableTestCases=true" >> $GITHUB_OUTPUT
167144
fi
168145
169-
echo -e "$testResults" >> $GITHUB_STEP_SUMMARY
146+
echo -e "testResults<<EOF\n$testResults\nEOF" >> $GITHUB_OUTPUT
170147
171148
if [ "$testsFailed" -ne 0 ]; then
172149
echo "Tests failed"
173150
exit 1
174151
fi
175152
176-
- id: print_outputs
177-
name: Print outputs
153+
- id: parse_test_results
154+
name: Parse test results
178155
if: always()
179156
shell: bash
180157
run: |
158+
testResults="${{ steps.run_tests.outputs.testResults }}"
159+
testExecutionUrls=""
160+
testResultsFolder="${{ steps.run_tests.outputs.testResultsFolder }}"
161+
testExecutionBaseURL="${{ inputs.orchestratorUrl }}${{ inputs.orchestratorLogicalName }}/${{ inputs.orchestratorTenant }}/orchestrator_/test/executions/"
162+
163+
# Loop through all JSON files in the test results folder
164+
while IFS= read -r testResultFilePath; do
165+
echo "Processing test result file: $testResultFilePath"
166+
testResultData=$(cat "$testResultFilePath" | jq '.')
167+
testCaseExecutions=$(echo "$testResultData" | jq -c '.TestSetExecutions[] | .TestCaseExecutions')
168+
folderId="${{ steps.get_folder_id.outputs.folderId }}"
169+
testSetExecutionLink="$testExecutionBaseURL$(echo "$testResultData" | jq -r '.TestSetExecutions[0].Id')?fid=$folderId"
170+
171+
echo "Test execution can be viewed in Orchestrator by clicking this link: $testSetExecutionLink"
172+
173+
testResultsTable="| Test case | Result |\n| :-- | :-- |"
174+
while IFS= read -r testCase; do
175+
testName=$(echo "$testCase" | jq -r '.Name')
176+
testStatus=$(echo "$testCase" | jq -r '.Status')
177+
testResultsTable+="\n| $testName | $(if [ "$testStatus" == "Passed" ]; then echo ":white_check_mark: Passed"; else echo ":x: Failed"; fi) |"
178+
done <<< $(echo "$testCaseExecutions" | jq -c '.[]')
179+
180+
testResults+="\n### [Test results for $(echo "$testResultData" | jq -r '.TestSetExecutions[0].Name')]($testSetExecutionLink)\n$testResultsTable"
181+
182+
if [ -z "$testExecutionURLs" ]; then
183+
testExecutionURLs="$testSetExecutionLink"
184+
else
185+
testExecutionURLs+=", $testSetExecutionLink"
186+
fi
187+
done < <(find "$testResultsFolder" -type f -name "*.json")
188+
189+
echo "testExecutionLinks=$testExecutionURLs" >> $GITHUB_OUTPUT
190+
echo -e "testResults<<EOF\n$testResults\nEOF" >> $GITHUB_OUTPUT
191+
192+
echo -e "$testResults" >> $GITHUB_STEP_SUMMARY
193+
181194
echo "${{ steps.run_tests.outputs.testExecutionLinks }}"
182195
echo "${{ steps.run_tests.outputs.testResults }}"

0 commit comments

Comments
 (0)