-
Notifications
You must be signed in to change notification settings - Fork 5.3k
101 lines (98 loc) · 3.46 KB
/
ci.yaml
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
# Pass/fail checks for continuous integration testing.
# Webhook events: Pull requests
name: CI
on:
pull_request:
paths:
- "site/en/**"
jobs:
nbfmt:
name: Notebook format
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
- uses: actions/checkout@v2
- name: Fetch master branch
run: git fetch -u origin master:master
- name: Install tensorflow-docs
run: python3 -m pip install -U git+https://github.com/tensorflow/docs
- name: Check notebook formatting
run: |
# Only check notebooks modified in this pull request.
readarray -t changed_notebooks < <(git diff --name-only master | grep '\.ipynb$' || true)
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/setup-python@v1
- uses: actions/checkout@v2
- name: Fetch master branch
run: git fetch -u origin master:master
- name: Install tensorflow-docs
run: python3 -m pip install -U git+https://github.com/tensorflow/docs
- name: Lint notebooks
run: |
# Only check notebooks modified in this pull request.
readarray -t changed_notebooks < <(git diff --name-only master | grep '\.ipynb$' || true)
if [[ ${#changed_notebooks[@]} == 0 ]]; then
echo "No notebooks modified in this pull request."
exit 0
else
echo "Lint check with nblint:"
python3 -m tensorflow_docs.tools.nblint \
--arg=repo:tensorflow/docs "${changed_notebooks[@]}"
fi
outputs-removed:
name: Notebook outputs removed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Fetch master branch
run: git fetch -u origin master:master
- name: Check for output cells
run: |
# Notebooks that are allowed to save outputs and excluded from test.
EXCLUDED_PATHS=(
site/en/guide/gpu.ipynb
)
# Only check notebooks modified in this pull request.
readarray -t changed_notebooks < <(git diff --name-only master | grep '\.ipynb$' || true)
if [[ ${#changed_notebooks[@]} == 0 ]]; then
echo "No notebooks modified in this pull request."
exit 0
fi
# Remove notebooks excluded from test.
declare -a tested_notebooks
for fp in "${changed_notebooks[@]}"; do
is_excluded=0
for excluded_fp in "${EXCLUDED_PATHS[@]}"; do
if [[ "$fp" == "$excluded_fp" ]]; then
is_excluded=1
break
fi
done
if [[ $is_excluded == 0 ]]; then
tested_notebooks+=("$fp")
fi
done
# Test notebooks for output cells.
status_code=0
for fp in "${tested_notebooks[@]}"; do
# Output cells use the "output_type" property.
if grep --quiet "\"output_type\":" "$fp"; then
echo "[${GITHUB_WORKFLOW}] Remove output cells from: $fp" >&2
status_code=1
fi
done
if [[ "$status_code" != 0 ]]; then
echo "To remove notebook outputs:" >&2
echo "$ python3 -m tensorflow_docs.tools.nbfmt --remove_outputs notebook.ipynb" >&2
fi
exit "$status_code"