@@ -73,42 +73,64 @@ jobs:
73
73
restore-keys : |
74
74
${{ runner.os }}-gradle-
75
75
76
- - name : Download Build Artifacts
77
- uses : actions/download-artifact@v2
78
- with :
79
- name : app-build
80
- path : app/build/outputs/apk/
81
-
82
- - name : Run Unit Tests
83
- run : ./gradlew test | tee test-results.txt
84
-
85
- - name : Parse Unit Test Results
86
- id : parse_test_results
76
+ - name : Run Unit Tests and Capture Results
77
+ id : run_tests
87
78
run : |
88
- TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +0)
89
- echo "::set-output name=test_results::${TEST_RESULTS}"
90
- shell : bash
91
-
92
- comment-in-pr :
93
- runs-on : ubuntu-latest
94
- needs : test
95
- permissions :
96
- contents : write
97
- pull-requests : write
98
- repository-projects : write
99
- id-token : write
100
-
101
- steps :
102
- - name : Checkout
103
- uses : actions/checkout@v2
104
- - name : Comment on PR
105
- uses : actions/github-script@v6
106
- with :
107
- script : |
108
- const testResults = `{{ steps.parse_test_results.outputs.test_results }}`;
109
- github.rest.issues.createComment({
110
- issue_number: context.issue.number,
111
- owner: context.repo.owner,
112
- repo: context.repo.repo,
113
- body: `### Test Results\n${testResults}`
114
- });
79
+ ./gradlew test | tee test-results.txt
80
+ TEST_RESULTS=$(grep -A 7 "Test Summary" test-results.txt | tail -n +2 | sed 's/\x1B\[[0-9;]*[JKmsu]//g' | tr -d '[:space:]')
81
+ echo "$TEST_RESULTS" > test-summary.txt
82
+
83
+ # - name: Format Test Results for Two-Row Markdown Table with Emojis
84
+ # run: |
85
+ # echo "### Test Results" > formatted-summary.txt
86
+ # echo "" >> formatted-summary.txt
87
+ # echo "| Total Tests | Passed | Failed | Skipped | Result |" >> formatted-summary.txt
88
+ # echo "|-------------|--------|--------|---------|--------|" >> formatted-summary.txt
89
+
90
+ # echo "Raw Test Summary Content:"
91
+ # cat test-summary.txt
92
+
93
+ # # Extracting values using awk
94
+ # TOTAL=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/TotalTests/ {print $2}')
95
+ # PASSED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Passed/ {print $2}')
96
+ # FAILED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Failed/ {print $2}')
97
+ # SKIPPED=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Skipped/ {print $2}')
98
+ # RESULT=$(echo "$TEST_RESULTS" | awk -F'[: ]+' '/Result/ {print $2}')
99
+
100
+ # # Detailed debugging
101
+ # echo "Debug: Extracted Values:"
102
+ # echo " TOTAL: '$TOTAL'"
103
+ # echo " PASSED: '$PASSED'"
104
+ # echo " FAILED: '$FAILED'"
105
+ # echo " SKIPPED: '$SKIPPED'"
106
+ # echo " RESULT (Raw): '$RESULT'"
107
+
108
+ # if [[ "$RESULT" == "SUCCESS" ]]; then
109
+ # EMOJI="✅"
110
+ # elif [[ "$RESULT" == "FAILURE" ]]; then
111
+ # EMOJI="❌"
112
+ # else
113
+ # EMOJI="⚠️"
114
+ # fi
115
+
116
+ # echo "Debug: Final RESULT after processing: '$RESULT $EMOJI'"
117
+
118
+ # echo "| $TOTAL | $PASSED | $FAILED | $SKIPPED | $RESULT $EMOJI |" >> formatted-summary.txt
119
+
120
+ # # Show the final output for debugging
121
+ # echo "Final formatted-summary.txt content:"
122
+ # cat formatted-summary.txt
123
+
124
+ # - name: Comment on PR
125
+ # if: github.event_name == 'pull_request'
126
+ # uses: actions/github-script@v6
127
+ # with:
128
+ # script: |
129
+ # const fs = require('fs');
130
+ # const testResults = fs.readFileSync('formatted-summary.txt', 'utf8');
131
+ # github.rest.issues.createComment({
132
+ # issue_number: context.issue.number,
133
+ # owner: context.repo.owner,
134
+ # repo: context.repo.repo,
135
+ # body: testResults
136
+ # });
0 commit comments