-
Notifications
You must be signed in to change notification settings - Fork 609
137 lines (129 loc) · 4.97 KB
/
notebooks.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Notebook-related checks
name: Notebooks
on:
# Relevant PRs
pull_request:
paths:
- "**.ipynb"
# Allow manual runs
workflow_dispatch:
jobs:
# Format all notebooks.
nbfmt:
name: Notebook format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Install tensorflow-docs
run: python3 -m pip install -U git+https://github.com/tensorflow/docs
- name: Fetch master branch
run: git fetch -u origin main:main
- name: Check notebook formatting
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# Only check notebooks modified in this pull request
readarray -t changed_notebooks < <(git diff --name-only main | grep '\.ipynb$' || true)
else
# Manual run, check everything
readarray -t changed_notebooks < <(find -name '*.ipynb')
fi
if [[ ${#changed_notebooks[@]} == 0 ]]; then
echo "No notebooks modified in this pull request."
exit 0
else
echo "Check formatting with nbfmt:"
python3 -m tensorflow_docs.tools.nbfmt --test "${changed_notebooks[@]}"
fi
nblint:
name: Notebook lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
website:
- 'site/en/**/**.ipynb'
github_docs:
- 'examples/**/**.ipynb'
- 'demos/**/**.ipynb'
templates:
- 'templates/**/**.ipynb'
- name: Install tensorflow-docs
run: python3 -m pip install -U git+https://github.com/tensorflow/docs
- name: Fetch main branch
run: git fetch -u origin main:main
# Full lint for website notebooks (incl. website button)
- name: Lint website notebooks
if: steps.filter.outputs.website == 'true'
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# Only check notebooks modified in this pull request
readarray -t changed_notebooks < <(git diff --name-only main site/en/ |grep '\.ipynb$' || true)
else
# Manual run, check everything
readarray -t changed_notebooks < <(find site/en/ -name '*.ipynb')
fi
if [[ ${#changed_notebooks[@]} == 0 ]]; then
echo "No website notebooks modified in this pull request."
exit 0
else
echo "Lint check with nblint:"
python3 -m tensorflow_docs.tools.nblint \
--styles=google,tensorflow \
--arg=repo:google/generative-ai-docs --arg=branch:main \
--arg=base_url:https://ai.google.dev/ \
--exclude_lint=tensorflow::button_download \
"${changed_notebooks[@]}"
fi
# Reduced lint for notebooks hosted in GitHub
- name: Lint documentation notebooks
if: steps.filter.outputs.github_docs == 'true'
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# Only check notebooks modified in this pull request
readarray -t changed_notebooks < <(git diff --name-only main demos/ examples/ |grep '\.ipynb$' || true)
else
# Manual run, check everything
readarray -t changed_notebooks < <(find demos/ examples/ -name '*.ipynb')
fi
if [[ ${#changed_notebooks[@]} == 0 ]]; then
echo "No GitHub doc notebooks modified in this pull request."
exit 0
else
echo "Lint check with nblint:"
python3 -m tensorflow_docs.tools.nblint \
--styles=google,tensorflow \
--arg=repo:google/generative-ai-docs --arg=branch:main \
--exclude_lint=tensorflow::button_download \
--exclude_lint=tensorflow::button_website \
"${changed_notebooks[@]}"
fi
# Basic lint for template notebooks
- name: Lint template notebooks
if: steps.filter.outputs.templates == 'true'
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# Only check notebooks modified in this pull request
readarray -t changed_notebooks < <(git diff --name-only main templates/ |grep '\.ipynb$' || true)
else
# Manual run, check everything
readarray -t changed_notebooks < <(find templates/ -name '*.ipynb')
fi
if [[ ${#changed_notebooks[@]} == 0 ]]; then
echo "No template notebooks modified in this pull request."
exit 0
else
echo "Lint check with nblint:"
python3 -m tensorflow_docs.tools.nblint \
--styles=google,tensorflow \
--arg=repo:google/generative-ai-docs --arg=branch:main \
--exclude_lint=tensorflow::button_download \
--exclude_lint=tensorflow::button_website \
--exclude_lint=tensorflow::button_colab \
--exclude_lint=tensorflow::button_github \
"${changed_notebooks[@]}"
fi