-
Notifications
You must be signed in to change notification settings - Fork 41
138 lines (118 loc) · 4.36 KB
/
pr-check.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
137
138
name: Test Changed Jupyter Notebooks
on:
pull_request:
branches:
- main
jobs:
test-notebooks:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Find changed notebooks
id: find_notebooks
run: |
git fetch origin ${{ github.event.pull_request.base.ref }} ${{ github.event.pull_request.head.ref }}
git diff --name-only origin/${{ github.event.pull_request.base.ref }}...origin/${{ github.event.pull_request.head.ref }} > changed_files.txt
grep '\.ipynb$' changed_files.txt > changed_notebooks.txt || echo "No notebooks changed" > changed_notebooks.txt
- name: Check if any notebooks changed
id: check_notebooks
run: |
if grep -q '\.ipynb$' changed_notebooks.txt; then
echo "notebooks_changed=true" >> GITHUB_ENV
else
echo "notebooks_changed=false" >> GITHUB_ENV
fi
- name: No notebooks changed
if: env.notebooks_changed == 'false'
run: |
echo "No Jupyter notebooks changed in this PR."
exit 0
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10' # Use Python 3.10
- name: Install flake8
run: |
python -m pip install --upgrade pip
pip install flake8 flake8-nb
shell: bash
- name: Run Flake8 linting on changed notebooks
if: env.notebooks_changed == 'true'
id: lint
run: |
mkdir -p linting_logs
flake8_errors=0
while IFS= read -r notebook; do
[ "$(basename "$notebook")" = "python-dosearch.ipynb" ] && continue
echo "Linting $notebook"
flake8-nb --config=.flake8 "$notebook" > "linting_logs/$(basename "$notebook" .ipynb)_linting.txt" 2>&1 || flake8_errors=$((flake8_errors+1))
cat "linting_logs/$(basename "$notebook" .ipynb)_linting.txt"
done < changed_notebooks.txt
echo "flake8_errors=$flake8_errors" >> $GITHUB_ENV
shell: bash
- name: Upload linting logs
uses: actions/upload-artifact@v2
with:
name: linting-logs
path: linting_logs
- name: Check for linting errors
if: "(env.flake8_errors != '0')"
run: exit 1
- name: Install git
run: |
sudo apt-get update
sudo apt-get install -y git
shell: bash
- name: Install libgraphviz-dev if folder is CM3
run: sudo apt-get install -y libgraphviz-dev
shell: bash
- name: Install R if folder is CM3
run: |
sudo apt-get update
sudo apt-get install -y r-base
shell: bash
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install jupyter nbconvert ipython
shell: bash
- name: Convert changed Jupyter notebooks to Python scripts
id: convert
run: |
mkdir -p converted_scripts
while IFS= read -r notebook; do
echo "Processing $notebook"
[ -e "$notebook" ] || continue
[ "$(basename "$notebook")" = "DoubleML_and_Feature_Engineering_with_BERT.ipynb" ] && continue
jupyter nbconvert --to script "$notebook" --output-dir converted_scripts
done < changed_notebooks.txt
shell: bash
- name: Run converted Python scripts with IPython
id: execute
run: |
mkdir -p logs
script_errors=0
for script in converted_scripts/*.py; do
[ -e "$script" ] || continue
echo "Running $script"
ipython "$script" > "logs/$(basename "$script" .py).txt" 2>&1 || script_errors=$((script_errors+1))
done
echo "script_errors=$script_errors" >> $GITHUB_ENV
shell: bash
- name: Aggregate and report errors and warnings
run: |
echo "Aggregating errors and warnings..."
grep -E "Traceback|Error:|Exception:|ModuleNotFoundError|FutureWarning|TypeError" logs/*.txt linting_logs/*.txt > logs/errors_and_warnings.txt || true
echo "Errors and Warnings:"
cat logs/errors_and_warnings.txt
shell: bash
- name: Upload execution logs
uses: actions/upload-artifact@v2
with:
name: execution-logs
path: logs
- name: Check for errors
if: "(env.flake8_errors != '0' || env.script_errors != '0')"
run: exit 1