-
Notifications
You must be signed in to change notification settings - Fork 459
117 lines (107 loc) · 4.23 KB
/
changed_files.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: List files changed as GitHub comment
on:
pull_request
jobs:
list-files-changed:
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Format list of changed files
id: format
env:
GH_TOKEN: ${{ github.token }}
run: |
declare -a output
pr_num=${{ github.event.pull_request.number }}
files=`gh pr view ${pr_num} --json files -q '.files[].path'`
SAVEIFS=$IFS
IFS=$'\n'
files=($files)
IFS=$SAVEIFS
function generateMainFiles() {
html_file=`echo "${1%.md}.html" | sed -E 's/src\/[^\/]*\///g'`
file="<li><a href=\"https://deploy-preview-$pr_num--cockroachdb-docs.netlify.app/docs/$html_file\" target=\"_blank\" rel=\"noopener\">$1</a></li>"
output+="$file"
}
function generateIncludes() {
output+="<li>$1:</li><ul>"
OLDIFS=$IFS
IFS='/'
read -ra path <<< "$1"
IFS=$OLDIFS
if [[ $1 == src/*/_includes* ]]
then
major_version=${path[3]}
elif $1 == src/*/v* || $1 == src/*/cockroachcloud*
then
major_version=${path[2]}
fi
file_name=${path[-1]}
mainRefs=($(grep -irl /${file_name} src/*/${major_version} | sed -e 's/^\.\///g'))
includeRefs=($(grep -irl /${file_name} src/*/_includes/${major_version} | sed -e 's/^\.\///g'))
if [[ ${#mainRefs[@]} > 0 ]]
then
for ref in ${mainRefs[@]}; do
generateMainFiles ${ref}
done
fi
if [[ ${#includeRefs[@]} > 0 ]]
then
for ref in ${includeRefs[@]}; do
if [[ "$2" == *"$ref"* ]]
then
output+="<li>$ref (Error: Circular reference found. Your build will fail.)</li>"
else
chain=$2:${ref}
generateIncludes ${ref} ${chain}
fi
done
fi
if [[ ${#includeRefs[@]} == 0 && ${#mainRefs[@]} == 0 ]]
then
output+="<li>Warning: include not used in any ${major_version} file or include</li>"
fi
output+="</ul>"
}
for file in ${files[@]}; do
# only create links for Markdown files that are not includes
if [[ $file == src/**/*.md ]] && [[ $file != src/*/_* ]]
then
generateMainFiles ${file/src\/.*?\//}
elif [[ $file == src/**/*.md ]] && [[ $file == src/*/_includes/releases/* ]]
then
OLDIFS=$IFS
IFS='/'
read -ra path <<< "$file"
IFS=$OLDIFS
major_version=${path[-2]}
file="<li>${file}:<ul><li><a href=\"https://deploy-preview-$pr_num--cockroachdb-docs.netlify.app/docs/releases/${major_version}.html\" target=\"_blank\" rel=\"noopener\">releases/${major_version}.md</a></li></ul></li>"
output+="$file"
elif [[ $file == src/*/_includes/v* || $file == src/*/_includes/cockroachcloud* || $file == src/*/images/* ]] && [[ $file != src/**/*.json ]] && [[ $file != *.gitignore* ]]
then
# file=$(echo ${file} | sed -E 's/src\/[^\/]*\///g')
generateIncludes ${file}
else
output+="<li>$file</li>"
fi
done;
body="${output[@]}"
echo "body=$body" >> $GITHUB_ENV
- name: Find Comment
uses: peter-evans/[email protected]
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Files changed
- name: Create comment
uses: peter-evans/[email protected]
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
<h3>Files changed:</h3><ul>${{ env.body }}</ul>