Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions nf_core/pipeline-template/.github/workflows/nf-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ jobs:
echo ""
echo "See the [full run](${RUN_URL}) for details."
} > pr-comment/comment.md
else
# Clear the comment a previous failing run left on this PR.
touch pr-comment/delete
fi

- name: Upload PR comment artifact
Expand Down
28 changes: 22 additions & 6 deletions nf_core/pipeline-template/.github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ name: Post PR comment
# pr_number.txt - the pull request number
# header.txt - sticky-comment identifier (keeps comment types separate)
# comment.md - the Markdown body (omit the file to post nothing)
# delete - optional marker; delete this header's existing comment

on:
workflow_run:
Expand Down Expand Up @@ -50,14 +51,18 @@ jobs:
exit 0
fi

if [ ! -f pr-comment/comment.md ]; then
echo "Artifact present but no comment.md; nothing to post."
if [ -f pr-comment/comment.md ]; then
action=post
elif [ -f pr-comment/delete ]; then
action=delete
else
echo "Artifact present but no comment.md or delete marker; nothing to do."
exit 0
fi

pr_number=$(cat pr-comment/pr_number.txt)
header=$(cat pr-comment/header.txt)
echo "Found comment.md (header='$header', pr_number='$pr_number')."
echo "Requested action: $action (header='$header', pr_number='$pr_number')."

# Guard against anything unexpected ending up in the PR number.
case "$pr_number" in
Expand All @@ -69,8 +74,8 @@ jobs:

echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
echo "header=$header" >> "$GITHUB_OUTPUT"
echo "post=true" >> "$GITHUB_OUTPUT"
echo "Will post comment to PR #${pr_number}."
echo "$action=true" >> "$GITHUB_OUTPUT"
echo "Will $action comment on PR #${pr_number}."

- name: Post PR comment
if: steps.meta.outputs.post == 'true'
Expand All @@ -79,4 +84,15 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.meta.outputs.pr_number }}
header: ${{ steps.meta.outputs.header }}
path: pr-comment/comment.md{%- endraw %}
path: pr-comment/comment.md

# Producers request this once their failure clears, so a fixed PR does not keep
# showing the previous run's failure comment.
- name: Delete stale PR comment
if: steps.meta.outputs.delete == 'true'
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.meta.outputs.pr_number }}
header: ${{ steps.meta.outputs.header }}
delete: "true"{%- endraw %}
Loading