Skip to content

Commit 4fc7eea

Browse files
committed
Enhance GitHub Actions workflow to update or create Docker image comments on PRs. The script now checks for existing comments and updates them if found, ensuring only one comment is present for the Docker image availability.
1 parent c152d01 commit 4fc7eea

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

.github/workflows/preview.yml

+31-7
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,44 @@ jobs:
4949
with:
5050
script: |
5151
const imageName = `ghcr.io/${{ steps.repo-name.outputs.REPO_NAME }}/pr-${context.issue.number}:latest`;
52-
53-
github.rest.issues.createComment({
54-
issue_number: context.issue.number,
55-
owner: context.repo.owner,
56-
repo: context.repo.repo,
57-
body: `📦 Docker image for this PR is available at: \`${imageName}\`
52+
const commentBody = `📦 Docker image for this PR is available at: \`${imageName}\`
5853
5954
You can pull it with:
6055
\`\`\`
6156
docker pull ${imageName}
6257
docker run ${imageName}
63-
\`\`\``
58+
\`\`\``;
59+
60+
// Get all comments on the PR
61+
const comments = await github.rest.issues.listComments({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
issue_number: context.issue.number
6465
});
6566
67+
// Look for an existing Docker image comment
68+
const dockerComment = comments.data.find(comment =>
69+
comment.body.includes('📦 Docker image for this PR is available at:')
70+
);
71+
72+
if (dockerComment) {
73+
// Update existing comment
74+
await github.rest.issues.updateComment({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
comment_id: dockerComment.id,
78+
body: commentBody
79+
});
80+
} else {
81+
// Create new comment
82+
await github.rest.issues.createComment({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
issue_number: context.issue.number,
86+
body: commentBody
87+
});
88+
}
89+
6690
# Delete Docker image when PR is closed/merged
6791
delete-image:
6892
if: github.event.action == 'closed'

0 commit comments

Comments
 (0)