-
Notifications
You must be signed in to change notification settings - Fork 777
99 lines (83 loc) · 3.95 KB
/
list-changed-pages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Comment based on changed pages (Vercel Deploy URLs + Redirect Suggestions)
on:
pull_request:
jobs:
post-comment-with-links-to-changed-pages:
name: Create or Update
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get list of changed files
id: files
uses: Ana06/[email protected] # it's a fork of jitterbit/get-changed-files@v1 which works better with pull requests
- name: List Vercel Deploy URLs
id: links
# Note that this uses `%0A` instead of `\n` because of https://github.com/peter-evans/create-or-update-comment#setting-the-comment-body-from-a-file which I could not get to work here - but this brute force method does.
run: |
body="This PR changes the following pages (Vercel Preview Deploy links):%0A%0A"
no_changed_pages="%0A- This PR does not change any pages the [GH Actions workflow](https://github.com/prisma/docs/blob/main/.github/workflows/list-changed-pages.yml) could detect."
vercelLinks="Changed Vercel links"
body="$body%0A%0A$vercelLinks"
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ $changed_file == content/* ]]
then
no_changed_pages=""
cleaned_file=$(echo "$changed_file" | sed -E 's:content/:/:g' | sed -E 's:/index.mdx::g' | sed -e 's/.mdx//g' | sed -E 's:/[0-9]+-:/:g' )
branch_name=$(echo "${{github.event.pull_request.head.ref}}" | sed -e 's/\//-/g')
# TODO special case for images and similar non .mdx files
# Output inside the action
echo "- https://docs-git-${branch_name}-prisma.vercel.app$cleaned_file"
# Also collect into string
linksVercel="%0A- [/docs$cleaned_file](https://docs-git-${branch_name}-prisma.vercel.app$cleaned_file) ([currently](https://prisma.io/docs$cleaned_file))"
body="$body$linksVercel"
fi
done
body="$body$no_changed_pages"
body="$body%0A%0A(Note that links will only be valid after Vercel preview deploy succeeded)"
echo "::set-output name=body::$body"
- name: Find existing comment (links)
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: following pages
- name: Create comment (links)
if: steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.links.outputs.body }}
- name: Update comment (links)
if: steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body: ${{ steps.links.outputs.body }}
edit-mode: replace
### REDIRECTS ###
- name: Create suggested redirects
id: redirects
run: |
bash .github/workflows/scripts/generate-redirects.sh
- name: Find existing comment (redirects)
uses: peter-evans/find-comment@v1
id: fc2
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: following redirects
- name: Create comment (redirects)
if: steps.fc2.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.redirects.outputs.body }}
- name: Update comment (redirects)
if: steps.fc2.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc2.outputs.comment-id }}
body: ${{ steps.redirects.outputs.body }}
edit-mode: replace