@@ -20,15 +20,13 @@ jobs:
20
20
fetch-depth : 0
21
21
ref : refs/pull/${{ github.event.issue.number }}/head
22
22
23
- # Verify we're on the correct branch
24
23
- name : Verify branch
25
24
run : |
26
25
echo "Current branch:"
27
26
git branch --show-current
28
27
echo "Current commit:"
29
28
git rev-parse HEAD
30
29
31
- # Get PR SHA
32
30
- name : Get PR SHA
33
31
id : get-pr-info
34
32
run : |
@@ -65,38 +63,44 @@ jobs:
65
63
pnpm test 2>&1 | tee test_output.txt
66
64
TEST_EXIT_CODE=${PIPESTATUS[0]}
67
65
68
- # Prepare the output
69
- echo "output<<EOF" >> $GITHUB_OUTPUT
70
- cat test_output.txt >> $GITHUB_OUTPUT
71
- echo "EOF" >> $GITHUB_OUTPUT
72
-
73
- # Set the status based on exit code
74
- if [ $TEST_EXIT_CODE -eq 0 ]; then
75
- echo "status=success" >> $GITHUB_OUTPUT
76
- else
77
- echo "status=failure" >> $GITHUB_OUTPUT
78
- fi
79
-
80
- echo "exit_code=$TEST_EXIT_CODE" >> $GITHUB_OUTPUT
81
- exit $TEST_EXIT_CODE # This is important - make the step fail if tests fail
66
+ # Prepare the output, ensuring proper escaping
67
+ {
68
+ echo "output<<EOF"
69
+ cat test_output.txt
70
+ echo "EOF"
71
+
72
+ if [ $TEST_EXIT_CODE -eq 0 ]; then
73
+ echo "status=success"
74
+ else
75
+ echo "status=failure"
76
+ fi
77
+
78
+ echo "exit_code=$TEST_EXIT_CODE"
79
+ } >> $GITHUB_OUTPUT
82
80
83
81
- name : Create Status Check
84
- if : always() # Run even if tests fail
82
+ if : always()
85
83
uses : actions/github-script@v6
86
84
with :
87
85
script : |
88
- const testStatus = '${{ steps.run-tests.outputs.status }}';
89
- const testOutput = `${{ steps.run-tests.outputs.output }}`;
90
- const exitCode = '${{ steps.run-tests.outputs.exit_code }}';
91
-
92
- await github.rest.repos.createCommitStatus({
93
- owner: context.repo.owner,
94
- repo: context.repo.repo,
95
- sha: '${{ steps.get-pr-info.outputs.sha }}',
96
- state: testStatus === 'success' ? 'success' : 'failure',
97
- target_url: `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
98
- description: testStatus === 'success'
99
- ? 'Tests passed successfully!'
100
- : `Tests failed with exit code ${exitCode}`,
101
- context: 'PR Tests'
102
- });
86
+ try {
87
+ const testStatus = '${{ steps.run-tests.outputs.status }}';
88
+ const exitCode = '${{ steps.run-tests.outputs.exit_code }}';
89
+
90
+ const statusData = {
91
+ owner: context.repo.owner,
92
+ repo: context.repo.repo,
93
+ sha: '${{ steps.get-pr-info.outputs.sha }}',
94
+ state: testStatus === 'success' ? 'success' : 'failure',
95
+ target_url: `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
96
+ description: testStatus === 'success'
97
+ ? 'Tests passed successfully!'
98
+ : `Tests failed with exit code ${exitCode}`,
99
+ context: 'PR Tests'
100
+ };
101
+
102
+ await github.rest.repos.createCommitStatus(statusData);
103
+ } catch (error) {
104
+ console.error('Error creating status check:', error);
105
+ core.setFailed(error.message);
106
+ }
0 commit comments