1+ name : Add Netlify Links To Changed Pages
2+ on :
3+ workflow_call :
4+ pull_request_target :
5+ jobs :
6+ get-pr-changes :
7+ name : Get Changed Files & Update PR Description
8+ runs-on : ubuntu-latest
9+ permissions :
10+ issues : write
11+ contents : write
12+ pull-requests : write
13+ repository-projects : write
14+ steps :
15+ - uses : actions/checkout@v4
16+ - name : Get Changed Files
17+ id : changed-files
18+ # pin to a specific commit to ensure stability
19+ uses : tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c
20+ with :
21+ separator : " ,"
22+ files : source/**
23+ - name : Build Netlify Links for Changed Pages
24+ id : build_page_links
25+ env :
26+ CHANGED_FILES : ${{ steps.changed-files.outputs.all_changed_files }}
27+ run : |
28+ new_links=""
29+ base_link='https://deploy-preview-${{ github.event.number }}--docs-scala.netlify.app'
30+ files=$(echo "$CHANGED_FILES" | tr "," "\n")
31+ for file in $files; do
32+ echo "processing ${file}"
33+ if (! grep -s "includes/" <<< "$file") &&
34+ (! grep -s "images/" <<< "$file") &&
35+ (! grep -s "examples/" <<< "$file"); then
36+ file="${file#source}"
37+ file="${file%.txt}"
38+ filenoslash="${file:1}"
39+ echo "${base_link}${file}"
40+ new_links+="<li><a href=${base_link}${file}>${filenoslash}</a></li>"
41+ else
42+ echo "(file skipped)"
43+ fi
44+ done
45+ if [ "$new_links" == "" ]; then
46+ new_links="No pages to preview"
47+ fi
48+ echo "Final new_links string: "
49+ echo "${new_links}"
50+ echo "staging_links=${new_links}" >> "$GITHUB_OUTPUT"
51+ - name : Update the PR Description
52+ uses : MongoCaleb/pr-description-action@master
53+ with :
54+ regex : " <!-- start insert-links -->.*<!-- end insert-links -->"
55+ appendContentOnMatchOnly : true
56+ regexFlags : is
57+ content : " <!-- start insert-links -->\n ${{ steps.build_page_links.outputs.staging_links }}\n <!-- end insert-links -->"
58+ token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments