Skip to content

Commit 7e15ba3

Browse files
feat: Add GITHUB_STEP_SUMMARY output to PR comments (#17)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent ab193b7 commit 7e15ba3

File tree

4 files changed

+166
-8
lines changed

4 files changed

+166
-8
lines changed

.github/workflows/ci-tests.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CI Tests
2+
3+
on:
4+
pull_request:
5+
types: [synchronize, opened, reopened, ready_for_review]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
issues: write
11+
12+
jobs:
13+
test-success:
14+
runs-on: ubuntu-latest
15+
if: github.event.pull_request.draft == false
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
22+
- name: Run `poe test-success` [Poe Command Processor]
23+
uses: ./
24+
with:
25+
pr: ${{ github.event.pull_request.number }}
26+
github-token: ${{ secrets.GITHUB_TOKEN }}
27+
command: test-success
28+
29+
test-success-with-summary:
30+
runs-on: ubuntu-latest
31+
if: github.event.pull_request.draft == false
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 1
37+
38+
- name: Run `poe test-success-with-summary` [Poe Command Processor]
39+
uses: ./
40+
with:
41+
pr: ${{ github.event.pull_request.number }}
42+
github-token: ${{ secrets.GITHUB_TOKEN }}
43+
command: test-success-with-summary
44+
45+
test-fail-with-summary:
46+
runs-on: ubuntu-latest
47+
if: github.event.pull_request.draft == false
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 1
53+
54+
- name: Run `poe test-fail-with-summary` [Poe Command Processor]
55+
uses: ./
56+
continue-on-error: true
57+
with:
58+
pr: ${{ github.event.pull_request.number }}
59+
github-token: ${{ secrets.GITHUB_TOKEN }}
60+
command: test-fail-with-summary

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,37 @@ If a `.tool-versions` file does not exist, or doesn't have versions specified, w
7272
- `poetry` - Default to latest version.
7373
- `python` - Default to version 3.11.
7474

75+
## Publishing Task Output
76+
77+
Tasks can optionally publish markdown output that will appear in both the GitHub job summary and as an expandable section in PR comments. This is useful for displaying test results, coverage reports, or other structured output.
78+
79+
### How It Works
80+
81+
To publish output, your poe task should check for the `GITHUB_STEP_SUMMARY` environment variable and write markdown content to it:
82+
83+
```shell
84+
# In your poe task (pyproject.toml or poe_tasks.toml)
85+
[tasks.my-task]
86+
shell = """
87+
if [ -n "$GITHUB_STEP_SUMMARY" ]; then
88+
echo '## Task Results' >> $GITHUB_STEP_SUMMARY
89+
echo '' >> $GITHUB_STEP_SUMMARY
90+
echo '- ✅ Step 1: Success' >> $GITHUB_STEP_SUMMARY
91+
echo '- ✅ Step 2: Success' >> $GITHUB_STEP_SUMMARY
92+
echo '' >> $GITHUB_STEP_SUMMARY
93+
echo '**Status**: All steps completed! 🎉' >> $GITHUB_STEP_SUMMARY
94+
fi
95+
# Your actual task logic here
96+
echo 'Task completed'
97+
"""
98+
```
99+
100+
The output will appear:
101+
- In the GitHub Actions job summary (visible in the workflow run page)
102+
- In PR comments as an expandable section with ✳️ "Show/Hide Summary Output" (on success) or ✴️ (on failure)
103+
104+
**Note:** Always check if `GITHUB_STEP_SUMMARY` is defined before writing to it, as this variable is only available in GitHub Actions environments.
105+
75106
## Sample Workflows
76107

77108
### Sample Poe Slash Command (Generic)

action.yml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,40 @@ runs:
179179
180180
- name: Run `poe ${{ steps.resolve-command.outputs.command }}`
181181
shell: bash
182+
id: run-poe-task
182183
run: |
184+
set -euo pipefail
185+
186+
set +e # Temporarily disable exit on error to capture exit code
187+
183188
poe ${{ steps.resolve-command.outputs.command }}
184189
185-
- name: Print Post-Run Marker
186-
if: always()
187-
shell: bash
188-
run: |
190+
EXIT_CODE=$?
191+
set -e # Re-enable exit on error
192+
189193
# Printing Post-Run Marker
190194
echo "------------------------------------"
191195
echo "------------------------------------"
192196
echo "-- Execution Completed: 'poe ${{ steps.resolve-command.outputs.command }}' --"
193197
echo "------------------------------------"
194198
echo "------------------------------------"
195199
200+
if [ -s "$GITHUB_STEP_SUMMARY" ]; then
201+
echo "Step summary file exists and is non-empty: $GITHUB_STEP_SUMMARY"
202+
# Use multiline output syntax for GitHub Actions
203+
{
204+
echo "has-summary=true"
205+
echo "summary-text<<__POE_EOF__"
206+
cat "$GITHUB_STEP_SUMMARY"
207+
echo "__POE_EOF__"
208+
} >> "$GITHUB_OUTPUT"
209+
else
210+
echo "No step summary content found."
211+
echo "has-summary=false" >> $GITHUB_OUTPUT
212+
echo "summary-text=" >> $GITHUB_OUTPUT
213+
fi
214+
exit "$EXIT_CODE"
215+
196216
- name: Auto commit changes
197217
id: auto-commit
198218
uses: stefanzweifel/git-auto-commit-action@v5
@@ -215,7 +235,7 @@ runs:
215235
body: >
216236
🤖 Auto-commit successful: ${{ steps.auto-commit.outputs.commit_hash }}
217237
218-
- name: Append no-op comment
238+
- name: Append success comment with output
219239
if: >
220240
steps.comment-start.outputs.comment-id
221241
uses: peter-evans/create-or-update-comment@v4
@@ -224,15 +244,29 @@ runs:
224244
reactions: "+1"
225245
body: |
226246
> ${{ inputs.success-message || format(' 🟦 Poe command `{0}` completed successfully.', steps.resolve-command.outputs.command) }}
247+
${{ steps.run-poe-task.outputs.has-summary == 'true' && format('
248+
249+
<details><summary>✳️ Show/Hide Summary Output</summary>
250+
251+
{0}
252+
253+
</details>', steps.run-poe-task.outputs.summary-text) || '' }}
227254
228255
- name: Append failure comment
229256
if: failure() && steps.comment-start.outputs.comment-id
230257
uses: peter-evans/create-or-update-comment@v4
231258
with:
232259
comment-id: ${{ steps.comment-start.outputs.comment-id }}
233260
reactions: confused
234-
body: >
235-
${{ inputs.failure-message || format('❌ Poe command `{0}` failed. Please inspect the logs.', steps.resolve-command.outputs.command) }}
261+
body: |
262+
> ${{ inputs.failure-message || format('❌ Poe command `{0}` failed. Please inspect the logs.', steps.resolve-command.outputs.command) }}
263+
${{ steps.run-poe-task.outputs.has-summary == 'true' && format('
264+
265+
<details><summary>✴️ Show/Hide Summary Output</summary>
266+
267+
{0}
268+
269+
</details>', steps.run-poe-task.outputs.summary-text) || '' }}
236270
237271
# Create a new PR if no PR was provided
238272

poe_tasks.toml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
[tasks]
2-
test = "echo 'Dummy tests...'"
2+
test-success = "echo 'Dummy tests...'"
33
test-fail = "exit 1"
4+
5+
[tasks.test-success-with-summary]
6+
shell = """
7+
if [ -n "$GITHUB_STEP_SUMMARY" ]; then
8+
echo '## Test Results' >> "$GITHUB_STEP_SUMMARY"
9+
echo '' >> "$GITHUB_STEP_SUMMARY"
10+
echo 'This is a test of the GITHUB_STEP_SUMMARY feature.' >> "$GITHUB_STEP_SUMMARY"
11+
echo '' >> "$GITHUB_STEP_SUMMARY"
12+
echo '- ✅ Item 1: Success' >> "$GITHUB_STEP_SUMMARY"
13+
echo '- ✅ Item 2: Success' >> "$GITHUB_STEP_SUMMARY"
14+
echo '- ✅ Item 3: Success' >> "$GITHUB_STEP_SUMMARY"
15+
echo '' >> "$GITHUB_STEP_SUMMARY"
16+
echo '**Status**: All tests passed! 🎉' >> "$GITHUB_STEP_SUMMARY"
17+
fi
18+
echo 'Test with summary completed'
19+
"""
20+
21+
[tasks.test-fail-with-summary]
22+
shell = """
23+
if [ -n "$GITHUB_STEP_SUMMARY" ]; then
24+
echo '## Test Results' >> "$GITHUB_STEP_SUMMARY"
25+
echo '' >> "$GITHUB_STEP_SUMMARY"
26+
echo 'This is a test of the GITHUB_STEP_SUMMARY feature.' >> "$GITHUB_STEP_SUMMARY"
27+
echo '' >> "$GITHUB_STEP_SUMMARY"
28+
echo '- ✅ Item 1: Success' >> "$GITHUB_STEP_SUMMARY"
29+
echo '- ✅ Item 2: Success' >> "$GITHUB_STEP_SUMMARY"
30+
echo '- 😵 Item 3: Failure!!' >> "$GITHUB_STEP_SUMMARY"
31+
echo '' >> "$GITHUB_STEP_SUMMARY"
32+
echo '**ERROR**: Something bad happened ☠️' >> "$GITHUB_STEP_SUMMARY"
33+
fi
34+
echo 'Test fail with summary completed'
35+
exit 1
36+
"""

0 commit comments

Comments
 (0)