Skip to content

Commit 571a2eb

Browse files
authored
Merge pull request #2290 from vprashar2929/ci-pr-comm
ci: refactor PR commenting to use dedicated workflow
2 parents a65dd68 + d0d72a9 commit 571a2eb

File tree

3 files changed

+64
-29
lines changed

3 files changed

+64
-29
lines changed

.github/workflows/config-change.yaml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
name: Check Config Changes
22

33
on: #yamllint disable-line rule:truthy
4-
pull_request_target:
5-
# Using `pull_request_target` event type to allow the workflow to comment on the PR.
6-
# Refer: https://github.com/thollander/actions-comment-pull-request?tab=readme-ov-file#permissions
7-
permissions:
8-
pull-requests: write
9-
contents: write
4+
pull_request:
105

116
jobs:
127
check-changes:
@@ -40,7 +35,7 @@ jobs:
4035
helm:
4136
- 'manifests/helm/kepler/values.yaml'
4237
43-
comment-on-pr:
38+
generate-comment-message:
4439
needs: check-changes
4540
if: >-
4641
needs.check-changes.outputs.changes == 'true' &&
@@ -54,10 +49,8 @@ jobs:
5449
runs-on: ubuntu-latest
5550
steps:
5651
- name: Generate comment message
57-
id: generate_message
5852
run: |
5953
{
60-
echo "message<<EOF"
6154
echo "⚠️ Config changes detected in this PR"
6255
echo "Please make sure that the config changes are updated in the following places as part of this PR:"
6356
if [[ "${{ needs.check-changes.outputs.doc_changes }}" != "true" ]]; then
@@ -76,8 +69,13 @@ jobs:
7669
echo "- manifests/helm/kepler/values.yaml"
7770
fi
7871
echo "EOF"
79-
} >> $GITHUB_OUTPUT
80-
- name: Comment on PR
81-
uses: thollander/actions-comment-pull-request@v3
72+
} > /tmp/message.txt
73+
74+
# NOTE: Uploading the message as an artifact so that PR Comment workflow can use it to
75+
# add comment on PR with the message.
76+
- name: Upload message
77+
uses: actions/upload-artifact@v4
8278
with:
83-
message: ${{ steps.generate_message.outputs.message }}
79+
name: message
80+
path: /tmp/message.txt
81+
retention-days: 1 # Keep artifact for 1 days

.github/workflows/pr-comment.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Automatically posts comments on pull requests with messages generated by other workflows
2+
# Triggered when specified workflows complete successfully
3+
name: PR Comment
4+
5+
on:
6+
workflow_run:
7+
# NOTE: Add any workflow that needs to comment on PRs to this list
8+
workflows:
9+
- Check Config Changes
10+
- Profiling Report
11+
types:
12+
- completed
13+
14+
permissions:
15+
pull-requests: write
16+
actions: read
17+
18+
jobs:
19+
comment-on-pr:
20+
runs-on: ubuntu-latest
21+
# Only run if the triggering workflow succeeded
22+
if: github.event.workflow_run.conclusion == 'success'
23+
steps:
24+
# Download the message artifact created by the triggering workflow
25+
- name: Download comment message
26+
id: download-artifact
27+
continue-on-error: true
28+
uses: actions/download-artifact@v4
29+
with:
30+
name: message
31+
path: /tmp/
32+
run-id: ${{ github.event.workflow_run.id }}
33+
github-token: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Comment on PR
36+
if: steps.download-artifact.outcome == 'success'
37+
uses: thollander/actions-comment-pull-request@v3
38+
with:
39+
file-path: /tmp/message.txt
40+
github-token: ${{ secrets.GITHUB_TOKEN }}
41+
pr-number: ${{ github.event.workflow_run.pull_requests[0].number }}
42+
reactions: eyes, rocket

.github/workflows/profiling.yaml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Profiling Report
22
on:
3-
pull_request_target:
4-
5-
permissions:
6-
contents: write
7-
pull-requests: write
3+
pull_request:
84

95
jobs:
106
profiling:
@@ -109,7 +105,7 @@ jobs:
109105
path: ./tmp/*
110106
retention-days: 5 # Keep artifact for 5 days
111107

112-
comment_on_pr:
108+
generate-comment-message:
113109
runs-on: ubuntu-latest
114110
needs: [profiling]
115111
steps:
@@ -132,11 +128,9 @@ jobs:
132128
path: ./tmp
133129

134130
- name: Generate comment messages
135-
id: generate_message
136131
run: |
137132
{
138-
echo "message<<EOF"
139-
./hack/reports/profiling.sh output
133+
./hack/reports/profiling.sh output | awk 'NR >4'
140134
echo ""
141135
echo "⬇️ Download the Profiling artifacts from the [Actions Summary page](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
142136
echo ""
@@ -147,11 +141,12 @@ jobs:
147141
echo "gh run download ${{ github.run_id }} -n profile-artifacts-${{ github.event.pull_request.number }}"
148142
echo "\`\`\`"
149143
echo ""
150-
echo "EOF"
151-
} >> $GITHUB_OUTPUT
152-
153-
- name: Create PR Comment with report links
154-
uses: thollander/actions-comment-pull-request@v3
144+
} > /tmp/message.txt
145+
# NOTE: Uploading the message as an artifact so that PR Comment workflow can use it to
146+
# add comment on PR with the message.
147+
- name: Upload message
148+
uses: actions/upload-artifact@v4
155149
with:
156-
message: ${{ steps.generate_message.outputs.message }}
157-
reactions: eyes, rocket
150+
name: message
151+
path: /tmp/message.txt
152+
retention-days: 1 # Keep artifact for 1 days

0 commit comments

Comments
 (0)