-
Notifications
You must be signed in to change notification settings - Fork 1.2k
56 lines (53 loc) · 2.39 KB
/
new_examples_links_in_table_of_content.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
name: All new examples are linked in the README
on:
pull_request:
branches: [ main ]
jobs:
new-example-links-in-examples-readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get added files
run: |
git fetch origin main
git diff --name-status origin/main HEAD | grep ^A | cut -f2- > new_files.txt
echo "Added Files:"
cat new_files.txt | sed 's/^/ - /'
- name: Check for new .ipynb files in the example folder
run: |
if grep "examples/.*\.ipynb$" new_files.txt; then
grep '^examples/.*\.ipynb$' new_files.txt > new_example_files.txt
echo "Found new .ipynb file(s) in examples/:"
cat new_example_files.txt | sed 's/^/ - /'
else
echo "No new .ipynb files found in examples/"
fi
- name: Check README links
run: |
if [[ -f new_example_files.txt ]]; then
all_linked=true
while IFS= read -r file; do
# Get the directory of the new example file
example_dir=$(dirname "$file")
# Get the filename without the directory path
filename=$(basename "$file")
# Check if link exists in examples/README.md
if ! grep -q "$file" examples/README.md && ! grep -q "${file/examples\//](}" examples/README.md; then
# Check if a README.md exists in the sub-folder, and if so, check for the link there
if [[ -f "$example_dir/README.md" ]]; then
if ! grep -q "$filename" "$example_dir/README.md" && ! grep -q "$filename" "$example_dir/README.md"; then
all_linked=false
echo "Link to '$file' not found in examples/README.md or $example_dir/README.md"
echo "::warning file=$file::Link to '$file' not found in a README.md, please add one"
fi
else
all_linked=false
echo "Link to '$file' not found in examples/README.md, and no README.md found in $example_dir"
echo "::warning file=$file::Link to '$file' not found in examples/README.md, please add one (or create a README.md in the sub-folder)"
fi
fi
done < new_example_files.txt
if ! $all_linked; then
exit 1
fi
fi