Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
086d381
organized test cases for clear reporting.
aguilita1 Oct 25, 2025
6ea2b75
corrected final-result to test for skipped steps
aguilita1 Oct 25, 2025
14ff134
added missing checkout step
aguilita1 Oct 25, 2025
2ba1ce3
corrected final result logic
aguilita1 Oct 25, 2025
d61f981
reverted to testing
aguilita1 Oct 25, 2025
fb5ffa9
added outcome step
aguilita1 Oct 25, 2025
21e4ea8
switched to test outcomes
aguilita1 Oct 25, 2025
2817f69
Debugging test case logic
aguilita1 Oct 25, 2025
9224e48
adjusted test outcome logic
aguilita1 Oct 25, 2025
d86b2ac
corrected invalid Bash script
aguilita1 Oct 25, 2025
233ffea
removed debugging; Adjust output to be more readable
aguilita1 Oct 25, 2025
45015aa
change test summary icon; write negative test outcome to GITHUB_STEP_…
aguilita1 Oct 25, 2025
1acd72d
debugging failure of positive test
aguilita1 Oct 25, 2025
ad0a209
Added more grainular results
aguilita1 Oct 25, 2025
7dcc454
corrected ouputs assignments
aguilita1 Oct 25, 2025
af04859
corrected ouputs assignments use
aguilita1 Oct 25, 2025
a602b56
added exit fail
aguilita1 Oct 25, 2025
af1acfe
added body type validation check
aguilita1 Oct 25, 2025
7f382df
fixed linting errors
aguilita1 Oct 25, 2025
4952c34
adjust exception handling for new exception; added clear messages
aguilita1 Oct 25, 2025
c4d337c
removed redundant message; incremented version
aguilita1 Oct 25, 2025
c89b554
reverted debugging; added dependabot
aguilita1 Oct 25, 2025
df866ea
Merge branch 'main' into ci_reporting
aguilita1 Oct 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 107 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ permissions:

jobs:
lint-and-test:
name: Linting and Positive Tests
runs-on: ubuntu-latest
outputs:
test_result: ${{ steps.positive-test-outcome.outcome }}
lint_result: ${{ steps.lint-outcome.outcome }}
steps:
- uses: actions/checkout@v4
- name: Checkout Code
uses: actions/checkout@v4

- name: Validate action.yml Metadata
id: validate-action-yml
run: |
yq eval '.' action.yml > /dev/null

Expand All @@ -27,7 +33,7 @@ jobs:
label: "test-success-path-defaults"
script: |
console.log("✅ github-script-post-comment action executed in CI.");
return "Self-test successful.";
return "✅ Test Case 1 - Composite Action - Success Path with Defaults.";

- name: Upload Embedded JavaScript
uses: actions/upload-artifact@v4
Expand All @@ -37,47 +43,129 @@ jobs:
path: 'final_script.js'

- name: Lint Embedded JavaScript and project files
id: lint-check
env:
NODE_ENV: development
run: |
npm ci
npx eslint .

- name: Test Case 2 - Composite Action - No Return
- name: Test Case 2 - Composite Action - Success Path with github-step-summary
uses: ./
id: test-success-path-github-step-summary
with:
label: "test-success-path-github-step-summary"
post-target: github-step-summary
script: |
console.log("✅ github-script-post-comment action executed in CI.");
return "✅ Test Case 2 - Composite Action - Success Path with github-step-summary.";

- name: Test Case 3 - Composite Action - Success Path with pull-request
uses: ./
id: test-success-path-pull-request
with:
label: "test-success-path-pull-request"
post-target: pull-request
script: |
console.log("✅ github-script-post-comment action executed in CI.");
return "✅ Test Case 3 - Composite Action - Success Path with pull-request.";
- name: Lint Outcome
id: lint-outcome
if: always()
run: |
echo "steps.validate-action-yml.outcome = ${{ steps.validate-action-yml.outcome }}"
echo "steps.lint-check.outcome = ${{ steps.lint-check.outcome }}"

if [[ "${{ steps.validate-action-yml.outcome }}" == "success" && "${{ steps.lint-check.outcome }}" == "success" ]]; then
echo "✅ Linting passed."
echo "✅ Linting passed." >> $GITHUB_STEP_SUMMARY
else
echo "❌ One or more lint rules failed."
echo "❌ One or more lint rules failed." >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Job Outcome
id: positive-test-outcome
if: always()
run: |
echo "steps.test-success-path-defaults.outcome = ${{ steps.test-success-path-defaults.outcome }}"
echo "steps.test-success-path-github-step-summary.outcome = ${{ steps.test-success-path-github-step-summary.outcome }}"
echo "steps.test-success-path-pull-request.outcome = ${{ steps.test-success-path-pull-request.outcome }}"

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
echo "✅ All positive tests passed."
echo "✅ All positive tests passed." >> $GITHUB_STEP_SUMMARY
else
echo "❌ One or more positive tests failed or did not run."
echo "❌ One or more positive tests failed or did not run." >> $GITHUB_STEP_SUMMARY
exit 1
fi

negative-tests:
name: Negative Tests - Expected to Fail
runs-on: ubuntu-latest
outputs:
test_result: ${{ steps.negative-tests-outcome.outcome }}
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Test Case 4 - Composite Action - No Return
uses: ./
id: test-no-return
continue-on-error: true
with:
label: "test-no-return"
script: |
console.log("Test Case 2 - Composite Action - No Return");
console.log("Expect error: script does not return string.");

- name: Test Case 3 - Composite Action - Return Non-String
- name: Test Case 5 - Composite Action - Return Non-String
uses: ./
id: test-return-non-string
continue-on-error: true
with:
label: "test-return-non-string"
script: |
console.log("Test Case 3 - Composite Action - Return Non-String");
console.log("Expect error: script returns non-string.");
return {title: "Test Case 3", message: "test case return non-string", score: 50};

- name: Test Case 4 - Composite Action - Success Path with github-step-summary
uses: ./
id: test-success-path-github-step-summary
with:
label: "test-success-path-github-step-summary"
post-target: github-step-summary
script: |
console.log("✅ github-script-post-comment action executed in CI.");
return "Self-test successful.";
- name: Job Outcome
id: negative-tests-outcome
if: always()
run: |
echo "steps.test-no-return.outcome = ${{ steps.test-no-return.outcome }}"
echo "steps.test-return-non-string.outcome = ${{ steps.test-return-non-string.outcome }}"

if [[ "${{ steps.test-no-return.outcome }}" == "failure" && "${{ steps.test-return-non-string.outcome }}" == "failure" ]]; then
echo "✅ All negative tests failed as expected."
echo "✅ All negative tests failed as expected." >> $GITHUB_STEP_SUMMARY
else
echo "❌ One or more negative tests did not fail as expected."
echo "❌ One or more negative tests did not fail as expected." >> $GITHUB_STEP_SUMMARY
exit 1
fi

- name: Test Case 5 - Composite Action - Success Path with pull-request
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [lint-and-test, negative-tests]
if: always()

steps:
- name: Checkout Code
uses: actions/checkout@v5
- name: Add Test Summary
uses: ./
id: test-success-path-pull-request
with:
label: "test-success-path-pull-request"
post-target: pull-request
label: "Test Summary"
script: |
console.log("✅ github-script-post-comment action executed in CI.");
return "Self-test successful.";
let body = "## 🧪 Test Summary\n\n"
+ "| Check | Status |\n"
+ "|-------|--------|\n"
+ "| Lint Rules | ${{ needs.lint-and-test.outputs.lint_result == 'success' && '✅ Passed' || '❌ Failed' }} |\n"
+ "| Positive Tests | ${{ needs.lint-and-test.outputs.test_result == 'success' && '✅ Passed' || '❌ Failed' }} |\n"
+ "| Negative Tests | ${{ needs.negative-tests.outputs.test_result == 'success' && '✅ Passed' || '❌ Failed' }} |\n\n";

return body;
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ runs:
// Store the result as an output for downstream steps
core.setOutput('result', JSON.stringify(body));

// Validate that the returned body is a string
if (typeof body !== 'string') {
throw new TypeError(`Returned value from user script must be a string. Received type '${typeof body}'. `);
}

// Output to GITHUB_STEP_SUMMARY
if (postTarget === 'both' || postTarget === 'github-step-summary') {
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
Expand Down Expand Up @@ -143,7 +148,7 @@ runs:
console.error(`❌ Error processing ${{ inputs.label }} results:`, error);

// Detect when user forgot to return a value (causing body = undefined)
if (error.status === 'ERR_INVALID_ARG_TYPE' && /The "data" argument must be of type string/i.test(error.message)) {
if (error instanceof TypeError && /Returned value from user script must be a string/i.test(error.message)) {
console.error(`💡 Hint: Your script returned a non-string value (e.g., object, array, or undefined) — or nothing at all.\n`
+ `Please return a string, or serialize your result using JSON.stringify.\n\n`
+ `For example:\n\n`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aguilita1/github-script-post-comment",
"version": "1.1.2",
"version": "1.1.3",
"description": "GitHub Action to run custom JavaScript and post results to GitHub summary and Pull Request",
"author": "Daniel I. Kelley",
"license": "MIT",
Expand Down