Skip to content

Commit 8b2d5de

Browse files
mnoconadriendupuis
andcommitted
[CI] Added job adding preview links (#2561)
* Applied review suggestion * [TMP] Add change * [TMP] Random change 2 * Fixed hardcoded master * Fix? * Fix? * Removed newline * Refactoring * Revert "[TMP] Add change" This reverts commit d9f9ffd. * Revert "[TMP] Random change 2" This reverts commit baa535d. * Removed file filter from the job * Refined message * Applied review wording suggestion Co-authored-by: Adrien Dupuis <[email protected]> --------- Co-authored-by: Adrien Dupuis <[email protected]>
1 parent 87c44bc commit 8b2d5de

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "Post preview links for changed files"
2+
3+
on:
4+
pull_request: ~
5+
workflow_call:
6+
inputs:
7+
project:
8+
description: 'The project to build (dev doc, user doc)'
9+
default: ''
10+
required: false
11+
type: string
12+
13+
jobs:
14+
post-preview-links:
15+
name: Post preview links for changed files
16+
runs-on: ubuntu-latest
17+
permissions:
18+
# Needed to manage the comment
19+
pull-requests: write
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Create comment for changed files
27+
run: |
28+
file_limit=100
29+
build_url="https://ez-systems-developer-documentation--${{ github.event.pull_request.number }}.com.readthedocs.build/${{inputs.project}}en/${{ github.event.pull_request.number }}/"
30+
31+
change_list=$(git diff --name-only HEAD "origin/$GITHUB_BASE_REF" | grep -E "^docs\/.*\.md$" | sed -E "s|^docs/(.*)\.md$|- [docs/\1.md](${build_url}\1/)|")
32+
change_count=$(echo "$change_list" | wc -l)
33+
34+
if [[ $change_list -eq '' ]] ; then
35+
comment="Preview of modified Markdown: no Markdown change to preview."
36+
elif [[ $change_count -gt $file_limit ]] ; then
37+
comment="Preview of modified Markdown: Too many files modified in a single PR, preview link list is skipped. ($change_count files &gth; $file_limit)"
38+
else
39+
comment="Preview of modified Markdown:\n\n$change_list"
40+
fi
41+
42+
echo -e "$comment" > comment.md
43+
44+
- name: Find comment
45+
id: find-comment
46+
uses: peter-evans/find-comment@v3
47+
with:
48+
issue-number: ${{ github.event.pull_request.number }}
49+
comment-author: 'github-actions[bot]'
50+
body-includes: 'Preview of modified Markdown'
51+
52+
- name: Create or update comment
53+
uses: peter-evans/create-or-update-comment@v4
54+
with:
55+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
56+
issue-number: ${{ github.event.pull_request.number }}
57+
body-path: comment.md
58+
edit-mode: replace

0 commit comments

Comments
 (0)