Skip to content

Commit 08bd367

Browse files
Header diff as PR comment
Signed-off-by: Lisanna Dettwyler <[email protected]>
1 parent 6921ead commit 08bd367

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

.github/workflows/loader-integration.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,46 @@ jobs:
5353
-e TZ=UTC \
5454
ghcr.io/oneapi-src/spec-build:latest \
5555
python3 ./run.py --debug '--!build' --ver $VER
56+
- name: Determine if there is a diff between header files
57+
id: include-diff
58+
run: | #bash
59+
if git diff --quiet --exit-code -- spec-head/include spec-base/include; then
60+
echo "diff=0" >> $GITHUB_OUTPUT
61+
else
62+
echo "diff=1" >> $GITHUB_OUTPUT
63+
fi
64+
- name: Get header diff
65+
if: steps.include-diff.outputs.diff == '1'
66+
run: git diff --no-index spec-base/include spec-head/include > header-diff.patch || true
67+
- name: Write comment with formatting to DIFF_COMMENT
68+
if: steps.include-diff.outputs.diff == '1'
69+
shell: python3 {0}
70+
run: |
71+
import os
72+
with open('header-diff.patch', 'r') as f:
73+
diff_content = f.read()
74+
diff_comment = f"```diff\n{diff_content}\n```"
75+
# https://trstringer.com/github-actions-multiline-strings/#option-2---environment-variable
76+
with open(os.environ['GITHUB_ENV'], 'a') as env:
77+
print('RESULTS_COMMENT<<EOF', file = env)
78+
print(diff_comment, file = env)
79+
print('EOF', file = env)
80+
- name: Write comment to PR
81+
uses: actions/github-script@v6
82+
if: steps.include-diff.outputs.diff == '1'
83+
with:
84+
github-token: ${{ secrets.GITHUB_TOKEN }}
85+
script: |
86+
[, pullRequestId] = /refs\/pull\/(\d+)\/merge/g.exec(context.ref);
87+
github.rest.issues.createComment({
88+
issue_number: pullRequestId,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
body: process.env.RESULTS_COMMENT
92+
});
93+
- name: Write job summary
94+
if: steps.include-diff.outputs.diff == '1'
95+
run: echo "${RESULTS_COMMENT}" >> ${GITHUB_STEP_SUMMARY}
5696
- name: Checkout loader-head
5797
uses: actions/checkout@v4
5898
with:

0 commit comments

Comments
 (0)