Skip to content

Commit c271bac

Browse files
committed
Applied review suggestion
1 parent c636be4 commit c271bac

File tree

1 file changed

+61
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)