Skip to content

Commit 063f094

Browse files
authored
Add comment right after STs start and then update it after build finish (#12090)
Signed-off-by: Jakub Stejskal <[email protected]>
1 parent 8b00949 commit 063f094

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

.github/actions/utils/add-comment/action.yml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
name: Add Comment
2-
description: "Posts a comment on the pull-request"
2+
description: "Posts a comment on the pull-request or updates an existing one"
33

44
inputs:
55
commentMessage:
66
description: "Message that will be put as a comment"
77
required: true
8+
commentId:
9+
description: "Optional comment ID to update instead of creating new one"
10+
required: false
11+
12+
outputs:
13+
commentId:
14+
description: "The ID of the created or updated comment"
15+
value: ${{ steps.comment-and-check.outputs.comment-id }}
816

917
runs:
1018
using: composite
@@ -14,11 +22,13 @@ runs:
1422
uses: actions/github-script@v7
1523
env:
1624
MESSAGE: ${{ inputs.commentMessage }}
25+
COMMENT_ID: ${{ inputs.commentId }}
1726
with:
1827
script: |
1928
const {owner, repo} = context.repo;
2029
2130
const msg = process.env.MESSAGE
31+
const commentId = process.env.COMMENT_ID
2232
let sha = undefined
2333
let prNumber = undefined;
2434
@@ -38,14 +48,29 @@ runs:
3848
} else {
3949
sha ||= context.sha;
4050
}
41-
42-
core.info(`Going to put a comment to PR ${prNumber}” (“${sha}) - ${msg}`);
51+
52+
core.info(`Going to put a comment to PR "${prNumber}" ("${sha}") - "${msg}"`);
4353
4454
//------------------------------------------------------------------
4555
// 2) Add / update PR comment
4656
//------------------------------------------------------------------
4757
if (prNumber) {
48-
await github.rest.issues.createComment({
49-
owner, repo, issue_number: prNumber, body: msg
50-
});
58+
// Update existing comment if commentId provided
59+
if (commentId) {
60+
core.info(`Updating existing comment ${commentId}`);
61+
await github.rest.issues.updateComment({
62+
owner,
63+
repo,
64+
comment_id: commentId,
65+
body: msg
66+
});
67+
core.setOutput('comment-id', commentId);
68+
} else {
69+
// Create new comment
70+
core.info(`Creating new comment`);
71+
const comment = await github.rest.issues.createComment({
72+
owner, repo, issue_number: prNumber, body: msg
73+
});
74+
core.setOutput('comment-id', comment.data.id);
75+
}
5176
}

.github/workflows/system-tests.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,28 @@ jobs:
9191
if: |-
9292
${{ always() &&
9393
(needs.check-rights.result == 'success' || github.event_name == 'pull_request') &&
94-
needs.parse-params.outputs.shouldRun == 'true'
94+
needs.parse-params.outputs.shouldRun == 'true'
9595
}}
9696
runs-on: ubuntu-latest
9797
permissions:
9898
contents: read
99+
pull-requests: write
99100
outputs:
100101
buildRunId: ${{ steps.verify.outputs.buildRunId }}
101102
buildMetadataSha: ${{ steps.verify.outputs.buildMetadataSha }}
103+
commentId: ${{ steps.initial-comment.outputs.commentId }}
102104
steps:
103105
- uses: actions/checkout@v5
104106
with:
105107
ref: ${{ needs.parse-params.outputs.ref }}
108+
- name: Add initial comment
109+
id: initial-comment
110+
if: ${{ github.event_name == 'issue_comment' }}
111+
uses: ./.github/actions/utils/add-comment
112+
with:
113+
commentMessage: ':hourglass_flowing_sand: System test verification started: [link](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
114+
115+
Waiting for build to finish...'
106116
- name: Get merge commit SHA
107117
id: get-merge-sha
108118
run: |
@@ -170,6 +180,7 @@ jobs:
170180
if: ${{ github.event_name == 'issue_comment' && steps.validate.outputs.isValid == 'true' }}
171181
uses: ./.github/actions/utils/add-comment
172182
with:
183+
commentId: ${{ needs.check-build.outputs.commentId }}
173184
commentMessage: ':hourglass_flowing_sand: System test verification started: [link](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
174185
175186
${{ steps.validate.outputs.message }}'

0 commit comments

Comments
 (0)