Skip to content

Commit f57e0fb

Browse files
committed
GH workflow: add step to post a comment on PR when failed
1 parent e229f49 commit f57e0fb

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

.github/workflows/check-ocaml-refs.yaml

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
name: Check OCaml References
1212

1313
on:
14+
pull_request:
15+
branches:
16+
- develop
17+
- main
1418
schedule:
1519
# Run every Monday at 9:00 AM UTC
1620
- cron: '0 9 * * 1'
@@ -46,17 +50,68 @@ jobs:
4650
OCAML_BRANCH: ${{ github.event.inputs.branch || 'compatible' }}
4751
run: |
4852
set +e
53+
# Capture output to file
4954
./.github/scripts/check-ocaml-refs.sh \
5055
--repo "$OCAML_REPO" \
51-
--branch "$OCAML_BRANCH"
56+
--branch "$OCAML_BRANCH" 2>&1 | tee validation_output.txt
5257
exit_code=$?
5358
if [ $exit_code -ne 0 ]; then
5459
echo "has_issues=true" >> $GITHUB_OUTPUT
55-
exit 0
60+
else
61+
echo "has_issues=false" >> $GITHUB_OUTPUT
5662
fi
63+
# Store output for PR comment
64+
echo "output_file=validation_output.txt" >> $GITHUB_OUTPUT
65+
exit 0
66+
67+
- name: Prepare PR comment
68+
if: github.event_name == 'pull_request'
69+
id: prepare-comment
70+
env:
71+
HAS_ISSUES: ${{ steps.check.outputs.has_issues }}
72+
OCAML_REPO: ${{ github.event.inputs.repo || 'https://github.com/MinaProtocol/mina.git' }}
73+
OCAML_BRANCH: ${{ github.event.inputs.branch || 'compatible' }}
74+
run: |
75+
# Determine status message
76+
if [ "$HAS_ISSUES" = "true" ]; then
77+
STATUS_MSG="❌ Validation failed"
78+
else
79+
STATUS_MSG="✓ Validation passed"
80+
fi
81+
82+
# Create comment body
83+
cat > comment.md <<COMMENT_EOF
84+
## OCaml Reference Validation Results
85+
86+
**Repository**: ${OCAML_REPO}
87+
**Branch**: ${OCAML_BRANCH}
88+
**Status**: ${STATUS_MSG}
89+
90+
<details>
91+
<summary>Click to see full validation output</summary>
92+
93+
\`\`\`
94+
COMMENT_EOF
95+
96+
# Append validation output
97+
cat validation_output.txt >> comment.md
98+
99+
# Close the code block and details
100+
cat >> comment.md <<'COMMENT_EOF'
101+
```
102+
103+
</details>
104+
COMMENT_EOF
105+
106+
- name: Post PR comment with validation results
107+
if: github.event_name == 'pull_request'
108+
uses: peter-evans/create-or-update-comment@v4
109+
with:
110+
issue-number: ${{ github.event.pull_request.number }}
111+
body-path: comment.md
57112

58113
- name: Update references if stale
59-
if: steps.check.outputs.has_issues != 'true'
114+
if: steps.check.outputs.has_issues != 'true' && github.event_name != 'pull_request'
60115
env:
61116
OCAML_REPO: ${{ github.event.inputs.repo || 'https://github.com/MinaProtocol/mina.git' }}
62117
OCAML_BRANCH: ${{ github.event.inputs.branch || 'compatible' }}
@@ -67,6 +122,7 @@ jobs:
67122
--update
68123
69124
- name: Check for changes
125+
if: github.event_name != 'pull_request'
70126
id: changes
71127
run: |
72128
if git diff --quiet; then
@@ -76,7 +132,7 @@ jobs:
76132
fi
77133
78134
- name: Create Pull Request
79-
if: steps.changes.outputs.has_changes == 'true'
135+
if: steps.changes.outputs.has_changes == 'true' && github.event_name != 'pull_request'
80136
uses: peter-evans/create-pull-request@v6
81137
with:
82138
token: ${{ secrets.GITHUB_TOKEN }}
@@ -118,6 +174,8 @@ jobs:
118174
echo "" >> $GITHUB_STEP_SUMMARY
119175
if [ "${{ steps.check.outputs.has_issues }}" == "true" ]; then
120176
echo "❌ Validation failed - some OCaml references are invalid" >> $GITHUB_STEP_SUMMARY
177+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
178+
echo "✓ Validation completed - results posted as PR comment" >> $GITHUB_STEP_SUMMARY
121179
elif [ "${{ steps.changes.outputs.has_changes }}" == "true" ]; then
122180
echo "✓ Validation passed - created PR to update stale references" >> $GITHUB_STEP_SUMMARY
123181
else

0 commit comments

Comments
 (0)