Skip to content

Commit ced842c

Browse files
committed
fix: use step output to prevent duplicate comments
Add should_comment flag that's set based on whether a release is created (not updated). Only comment when creating new releases.
1 parent 73fbb2d commit ced842c

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

.github/workflows/pr-preview-release.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
run-id: ${{ github.event.workflow_run.id }}
3838

3939
- name: Create or Update PR Release
40+
id: release
4041
env:
4142
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4243
RELEASE_TAG: "agentapi_${{ steps.pr.outputs.number }}"
@@ -46,6 +47,7 @@ jobs:
4647
if gh release view "$RELEASE_TAG" --repo ${{ github.repository }} &>/dev/null; then
4748
echo "Updating release $RELEASE_TAG"
4849
gh release upload "$RELEASE_TAG" ./out/* --clobber --repo ${{ github.repository }}
50+
echo "should_comment=false" >> "${GITHUB_OUTPUT}"
4951
else
5052
echo "Creating release $RELEASE_TAG"
5153
gh release create "$RELEASE_TAG" ./out/* \
@@ -54,24 +56,17 @@ jobs:
5456
--repo ${{ github.repository }} \
5557
--latest=false \
5658
--prerelease
59+
echo "should_comment=true" >> "${GITHUB_OUTPUT}"
5760
fi
5861
5962
- name: Comment on PR
63+
if: steps.release.outputs.should_comment == 'true'
6064
uses: actions/github-script@v7
6165
with:
6266
script: |
6367
const prNumber = ${{ steps.pr.outputs.number }};
6468
const releaseTag = `agentapi_${prNumber}`;
6569
const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`;
66-
67-
const comments = await github.rest.issues.listComments({
68-
issue_number: prNumber,
69-
owner: context.repo.owner,
70-
repo: context.repo.repo
71-
});
72-
// test
73-
if (comments.data.some(c => c.body.includes('✅ Preview binaries are ready!'))) return;
74-
7570
github.rest.issues.createComment({
7671
issue_number: prNumber,
7772
owner: context.repo.owner,

0 commit comments

Comments
 (0)