-
Notifications
You must be signed in to change notification settings - Fork 1.1k
55 lines (52 loc) · 2.18 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
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:
- name: Checkout Code
uses: actions/checkout@v3
- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
examples/**/*.ipynb
- name: Check README links
env:
# We only want the added file so that if we do an exception we dop not have to make an exception again each time qu're editing the file
NEW_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
README: examples/README.md
run: |
all_linked=true
for file in ${NEW_FILES}; do
echo "$file was added"
# Get the directory of the new notebook file
notebook_dir=$(dirname "$file")
# Get the filename without the directory path
filename=$(basename "$file")
# Check if link exists in $README
if ! grep -q "$file" "$README" && ! grep -q "${file/examples\//](}" "$README"; then
# Check if a README.md exists in the sub-folder, and if so, check for the link there
if [[ -f "$notebook_dir/README.md" ]]; then
if ! grep -q "$filename" "$notebook_dir/README.md"; then
all_linked=false
echo " Link to '$file' not found in "$README".md or $notebook_dir/README.md"
echo "::warning file=$file::Link to '$file' not found in a README.md, please add one"
else
echo " Link to '$file' found in $notebook_dir/README.md"
fi
else
all_linked=false
echo " Link to '$file' not found in $README, and no README.md found in $notebook_dir"
echo "::warning file=$file::Link to '$file' not found in $README, please add one (or create a README.md in the sub-folder)"
fi
else
echo " Link to '$file' found in $README"
fi
done
if ! $all_linked; then
exit 1
fi