Skip to content

Commit 85db69b

Browse files
ci: pr diff comment
1 parent 34d0956 commit 85db69b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/workflows/pr-diff.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Comment about the difference on PR
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- ready_for_review
8+
9+
jobs:
10+
comment:
11+
runs-on: ubuntu-latest
12+
env:
13+
GH_TOKEN: ${{ github.token }}
14+
permissions:
15+
pull-requests: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Generate the comment
20+
shell: python
21+
run: |
22+
from pathlib import Path
23+
from urllib.parse import urlencode
24+
25+
pr_number = "${{ github.event.pull_request.number }}"
26+
27+
ref = "https://typst-doc-cn.github.io/clreq/"
28+
pr = f"https://deploy-preview-{pr_number}--clreq-gap-typst.netlify.app/"
29+
30+
base_text = "https://services.w3.org/htmldiff?"
31+
base_pixel = "https://pianomister.github.io/diffsite/?"
32+
33+
diff_text = base_text + urlencode({"doc1": ref, "doc2": pr})
34+
diff_pixel = base_pixel + urlencode({"url1": ref, "url2": pr})
35+
36+
comment = f"""
37+
### Diff between [#{pr_number}]({pr}) and [main]({ref})
38+
39+
- [text diff]({diff_text})
40+
- [pixel diff]({diff_pixel})
41+
42+
[Feedback](https://github.com/typst-doc-cn/clreq/discussions/9)
43+
""".strip()
44+
45+
Path("comment.md").write_text(comment, encoding="utf-8")
46+
47+
- name: Write the summary
48+
run: |
49+
cat comment.md >> "$GITHUB_STEP_SUMMARY"
50+
51+
- name: Comment on the pull request
52+
run: gh pr comment ${{ github.event.pull_request.number }} --body-file comment.md
53+
env:
54+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)