@@ -42,24 +42,20 @@ jobs:
4242 COMMENT_AUTHOR="github-actions[bot]"
4343 PR_NUMBER="$(grep -o '^[0-9]\+$' pr_number.txt)"
4444
45- # comment_id.txt may be empty if there is no existing comment
46- if [ -s comment_id.txt ]
47- then
48- COMMENT_ID="$(grep -o '^[0-9]\+$' comment_id.txt)"
49- fi
45+ # If there is no existing comment, comment_id.txt will contain just a
46+ # newline (due to jq & gh behaviour). This will cause grep to fail, so
47+ # we catch that.
48+ COMMENT_ID=$(grep -o '^[0-9]\+$' comment_id.txt || true)
5049
51- if [ -z " $COMMENT_ID" ]
50+ if [ $COMMENT_ID ]
5251 then
53- # Create new comment
54- jq --rawfile body comment_body.txt '{"body":$body}' -n | gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -X POST --input -
55- else
5652 # Fetch existing comment, and validate:
5753 # - comment belongs to the PR with number $PR_NUMBER
5854 # - comment starts with the expected prefix ("QHelp previews")
5955 # - comment author is github-actions[bot]
6056 FILTER="select(.issue_url | test(\"${GITHUB_REPOSITORY}/issues/${PR_NUMBER}$\")) \
6157 | select(.body | test(\"^${COMMENT_PREFIX}\")) \
62- | select(.user.login == \"${COMMENT_AUTHOR}\") \
58+ | select(.user.login == \"${COMMENT_AUTHOR}\") \
6359 | .id"
6460 COMMENT_ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" | jq "${FILTER}")
6561 if [ $COMMENT_ID ]
6965 else
7066 echo "Comment ${COMMENT_ID} did not pass validations: not editing."
7167 fi
68+ else
69+ # Create new comment
70+ jq --rawfile body comment_body.txt '{"body":$body}' -n | gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -X POST --input -
7271 fi
7372 env :
7473 GITHUB_TOKEN : ${{ github.token }}
0 commit comments