@@ -12,11 +12,17 @@ permissions:
1212
1313jobs :
1414 lint-and-test :
15+ name : Linting and Positive Tests
1516 runs-on : ubuntu-latest
17+ outputs :
18+ test_result : ${{ steps.positive-test-outcome.outcome }}
19+ lint_result : ${{ steps.lint-outcome.outcome }}
1620 steps :
17- - uses : actions/checkout@v4
21+ - name : Checkout Code
22+ uses : actions/checkout@v4
1823
1924 - name : Validate action.yml Metadata
25+ id : validate-action-yml
2026 run : |
2127 yq eval '.' action.yml > /dev/null
2228
2733 label : " test-success-path-defaults"
2834 script : |
2935 console.log("✅ github-script-post-comment action executed in CI.");
30- return "Self-test successful .";
36+ return "✅ Test Case 1 - Composite Action - Success Path with Defaults .";
3137
3238 - name : Upload Embedded JavaScript
3339 uses : actions/upload-artifact@v4
@@ -37,47 +43,129 @@ jobs:
3743 path : ' final_script.js'
3844
3945 - name : Lint Embedded JavaScript and project files
46+ id : lint-check
4047 env :
4148 NODE_ENV : development
4249 run : |
4350 npm ci
4451 npx eslint .
4552
46- - name : Test Case 2 - Composite Action - No Return
53+ - name : Test Case 2 - Composite Action - Success Path with github-step-summary
54+ uses : ./
55+ id : test-success-path-github-step-summary
56+ with :
57+ label : " test-success-path-github-step-summary"
58+ post-target : github-step-summary
59+ script : |
60+ console.log("✅ github-script-post-comment action executed in CI.");
61+ return "✅ Test Case 2 - Composite Action - Success Path with github-step-summary.";
62+
63+ - name : Test Case 3 - Composite Action - Success Path with pull-request
64+ uses : ./
65+ id : test-success-path-pull-request
66+ with :
67+ label : " test-success-path-pull-request"
68+ post-target : pull-request
69+ script : |
70+ console.log("✅ github-script-post-comment action executed in CI.");
71+ return "✅ Test Case 3 - Composite Action - Success Path with pull-request.";
72+ - name : Lint Outcome
73+ id : lint-outcome
74+ if : always()
75+ run : |
76+ echo "steps.validate-action-yml.outcome = ${{ steps.validate-action-yml.outcome }}"
77+ echo "steps.lint-check.outcome = ${{ steps.lint-check.outcome }}"
78+
79+ if [[ "${{ steps.validate-action-yml.outcome }}" == "success" && "${{ steps.lint-check.outcome }}" == "success" ]]; then
80+ echo "✅ Linting passed."
81+ echo "✅ Linting passed." >> $GITHUB_STEP_SUMMARY
82+ else
83+ echo "❌ One or more lint rules failed."
84+ echo "❌ One or more lint rules failed." >> $GITHUB_STEP_SUMMARY
85+ exit 1
86+ fi
87+ - name : Job Outcome
88+ id : positive-test-outcome
89+ if : always()
90+ run : |
91+ echo "steps.test-success-path-defaults.outcome = ${{ steps.test-success-path-defaults.outcome }}"
92+ echo "steps.test-success-path-github-step-summary.outcome = ${{ steps.test-success-path-github-step-summary.outcome }}"
93+ echo "steps.test-success-path-pull-request.outcome = ${{ steps.test-success-path-pull-request.outcome }}"
94+
95+ if [[ "${{ steps.test-success-path-defaults.outcome }}" == "success" && "${{ steps.test-success-path-github-step-summary.outcome }}" == "success" && "${{ steps.test-success-path-pull-request.outcome }}" == "success" ]]; then
96+ echo "✅ All positive tests passed."
97+ echo "✅ All positive tests passed." >> $GITHUB_STEP_SUMMARY
98+ else
99+ echo "❌ One or more positive tests failed or did not run."
100+ echo "❌ One or more positive tests failed or did not run." >> $GITHUB_STEP_SUMMARY
101+ exit 1
102+ fi
103+
104+ negative-tests :
105+ name : Negative Tests - Expected to Fail
106+ runs-on : ubuntu-latest
107+ outputs :
108+ test_result : ${{ steps.negative-tests-outcome.outcome }}
109+ steps :
110+ - name : Checkout Code
111+ uses : actions/checkout@v4
112+
113+ - name : Test Case 4 - Composite Action - No Return
47114 uses : ./
48115 id : test-no-return
49116 continue-on-error : true
50117 with :
51118 label : " test-no-return"
52119 script : |
120+ console.log("Test Case 2 - Composite Action - No Return");
53121 console.log("Expect error: script does not return string.");
54122
55- - name : Test Case 3 - Composite Action - Return Non-String
123+ - name : Test Case 5 - Composite Action - Return Non-String
56124 uses : ./
57125 id : test-return-non-string
58126 continue-on-error : true
59127 with :
60128 label : " test-return-non-string"
61129 script : |
130+ console.log("Test Case 3 - Composite Action - Return Non-String");
62131 console.log("Expect error: script returns non-string.");
63132 return {title: "Test Case 3", message: "test case return non-string", score: 50};
64133
65- - name : Test Case 4 - Composite Action - Success Path with github-step-summary
66- uses : ./
67- id : test-success-path-github-step-summary
68- with :
69- label : " test-success-path-github-step-summary"
70- post-target : github-step-summary
71- script : |
72- console.log("✅ github-script-post-comment action executed in CI.");
73- return "Self-test successful.";
134+ - name : Job Outcome
135+ id : negative-tests-outcome
136+ if : always()
137+ run : |
138+ echo "steps.test-no-return.outcome = ${{ steps.test-no-return.outcome }}"
139+ echo "steps.test-return-non-string.outcome = ${{ steps.test-return-non-string.outcome }}"
140+
141+ if [[ "${{ steps.test-no-return.outcome }}" == "failure" && "${{ steps.test-return-non-string.outcome }}" == "failure" ]]; then
142+ echo "✅ All negative tests failed as expected."
143+ echo "✅ All negative tests failed as expected." >> $GITHUB_STEP_SUMMARY
144+ else
145+ echo "❌ One or more negative tests did not fail as expected."
146+ echo "❌ One or more negative tests did not fail as expected." >> $GITHUB_STEP_SUMMARY
147+ exit 1
148+ fi
74149
75- - name : Test Case 5 - Composite Action - Success Path with pull-request
150+ test-summary :
151+ name : Test Summary
152+ runs-on : ubuntu-latest
153+ needs : [lint-and-test, negative-tests]
154+ if : always()
155+
156+ steps :
157+ - name : Checkout Code
158+ uses : actions/checkout@v5
159+ - name : Add Test Summary
76160 uses : ./
77- id : test-success-path-pull-request
78161 with :
79- label : " test-success-path-pull-request"
80- post-target : pull-request
162+ label : " Test Summary"
81163 script : |
82- console.log("✅ github-script-post-comment action executed in CI.");
83- return "Self-test successful.";
164+ let body = "## 🧪 Test Summary\n\n"
165+ + "| Check | Status |\n"
166+ + "|-------|--------|\n"
167+ + "| Lint Rules | ${{ needs.lint-and-test.outputs.lint_result == 'success' && '✅ Passed' || '❌ Failed' }} |\n"
168+ + "| Positive Tests | ${{ needs.lint-and-test.outputs.test_result == 'success' && '✅ Passed' || '❌ Failed' }} |\n"
169+ + "| Negative Tests | ${{ needs.negative-tests.outputs.test_result == 'success' && '✅ Passed' || '❌ Failed' }} |\n\n";
170+
171+ return body;
0 commit comments