Skip to content

Commit 332d07d

Browse files
authored
pr commenting: use native github CLI (#432)
* test github cli * remove test branch
1 parent d766af2 commit 332d07d

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

.github/workflows/analyze.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,29 @@ jobs:
5656
path: ./results
5757
- name: Copy files to results bucket
5858
run: aws s3 cp ./results s3://cellpack-results/${{ github.ref_name }}/ --recursive --acl public-read
59-
- uses: iterative/setup-cml@v2
60-
with:
61-
vega: false # we only use CML to post markdown reports, so disable vega to skip extra npm installs
6259
- name: Update comment for dependabot
6360
if: ${{ github.actor == 'dependabot[bot]' }}
6461
env:
65-
REPO_TOKEN: ${{ secrets.DEPENDABOT_TOKEN }}
62+
GH_TOKEN: ${{ secrets.DEPENDABOT_TOKEN }}
6663
run: |
67-
cml comment update --watermark-title="{workflow} report" ./results/analysis_report.md --target=pr
64+
MARKER="<!-- Analyze workflow report -->"
65+
COMMENT_BODY="${MARKER}\n$(cat ./results/analysis_report.md)"
66+
EXISTING_COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq ".comments[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1)
67+
if [ ! -z "$EXISTING_COMMENT_ID" ]; then
68+
gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID
69+
fi
70+
echo -e "$COMMENT_BODY" | gh pr comment ${{ github.event.pull_request.number }} --body-file -
6871
cat ./results/analysis_report.md
6972
- name: Update comment for PR
7073
if: ${{ github.actor != 'dependabot[bot]' }}
7174
env:
72-
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7376
run: |
74-
cml comment update --watermark-title="{workflow} report" ./results/analysis_report.md --target=pr
77+
MARKER="<!-- Analyze workflow report -->"
78+
COMMENT_BODY="${MARKER}\n$(cat ./results/analysis_report.md)"
79+
EXISTING_COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq ".comments[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1)
80+
if [ ! -z "$EXISTING_COMMENT_ID" ]; then
81+
gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID
82+
fi
83+
echo -e "$COMMENT_BODY" | gh pr comment ${{ github.event.pull_request.number }} --body-file -
7584
cat ./results/analysis_report.md

0 commit comments

Comments
 (0)