-
Notifications
You must be signed in to change notification settings - Fork 56
174 lines (152 loc) · 6.15 KB
/
operator-test.yml
File metadata and controls
174 lines (152 loc) · 6.15 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Run Modified Operator Tests
on:
pull_request:
branches:
- main
- development
- hotfix
paths:
- 'operators/**'
- '.github/workflows/operator-tests.yml'
jobs:
test-operators:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Print uv version and cache dir
run: |
uv --version
uv cache dir
which python
- name: Detect changes in operators
id: check-changes
run: |
# Get the base branch (target branch of the PR)
BASE_BRANCH=${{ github.base_ref }}
echo "Base branch: $BASE_BRANCH"
# Find changed files in operators directory
CHANGED_FILES=$(git diff --name-only origin/$BASE_BRANCH...HEAD operators/)
echo "Changed files:"
echo "$CHANGED_FILES" | sed 's/^/ /' # This indents each file for better readability
# If no files changed, set output to false, otherwise true
if [ -z "$CHANGED_FILES" ]; then
echo "No files were changed in the operators directory"
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "changed_files=" >> $GITHUB_OUTPUT
else
echo "Changes detected in operators directory"
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Create and activate virtual environment and install Feluda
if: steps.check-changes.outputs.has_changes == 'true'
run: |
uv venv
source .venv/bin/activate
uv pip install .
uv pip install ".[dev]"
echo "Installing Operator system level packages"
echo "Installing ffmpeg..."
sudo apt-get update > /dev/null
sudo apt-get install -y ffmpeg > /dev/null
echo "ffmpeg version:"
ffmpeg -version
- name: Run tests for changed operators
if: steps.check-changes.outputs.has_changes == 'true'
run: |
# Get the changed files from previous step
CHANGED_FILES="${{ steps.check-changes.outputs.changed_files }}"
# Print current working directory for context
echo "Current working directory: $(pwd)"
# Initialize a variable to track if we found any operators to test
FOUND_TESTS=false
# Loop through each operator directory and check if it contains changes
for OPERATOR_DIR in operators/*/; do
echo "Checking operator directory: $OPERATOR_DIR"
if echo "$CHANGED_FILES" | grep -q "$(basename $OPERATOR_DIR)"; then
echo "✓ Changes detected in operator: $(basename $OPERATOR_DIR)"
# Check if test.py exists in this operator directory
if [ -f "${OPERATOR_DIR}test.py" ]; then
echo "✓ Found test.py in: ${OPERATOR_DIR}"
echo "→ Running tests for: $(basename $OPERATOR_DIR)"
echo "→ Current directory before running tests: $(pwd)"
uv pip install "$OPERATOR_DIR"
uv run -m unittest "$OPERATOR_DIR/test.py"
TEST_EXIT_CODE=$?
echo "→ Test exit code: $TEST_EXIT_CODE"
FOUND_TESTS=true
else
echo "✗ No test.py found in: ${OPERATOR_DIR}"
fi
else
echo "✗ No changes detected in: $(basename $OPERATOR_DIR)"
fi
done
# Final status report
echo "----------------------------------------"
echo "Final Status Report:"
if [ "$FOUND_TESTS" = false ]; then
echo "✗ No test.py files were found in changed operator directories"
else
echo "✓ Tests were executed for changed operators"
fi
echo "----------------------------------------"
# This ensures cleanup runs even if previous steps fail
- name: Cleanup
if: always()
run: |
echo "----------------------------------------"
echo "Starting cleanup process..."
echo "----------------------------------------"
# Check and print uv cache
echo "Cleaning UV cache..."
uv cache dir
uv cache prune
# uv cache clean
# Check and remove virtual environment
echo "----------------------------------------"
echo "Virtual Environment:"
if [ -d ".venv" ]; then
echo "Virtual environment exists!"
echo "Removing virtual environment..."
rm -rf .venv/
else
echo "No virtual environment found at .venv/"
fi
# Check and remove PyTorch cache
echo "----------------------------------------"
echo "PyTorch Cache:"
if [ -d ~/.cache/torch/hub ]; then
echo "PyTorch cache exists, contents:"
ls -la ~/.cache/torch/hub
echo "Removing PyTorch cache..."
rm -rf ~/.cache/torch/hub
else
echo "No PyTorch cache found at ~/.cache/torch/hub"
fi
# Check and remove Hugging Face cache
echo "----------------------------------------"
echo "Hugging Face Cache:"
if [ -d ~/.cache/huggingface/hub ]; then
echo "Hugging Face cache exists, contents:"
ls -la ~/.cache/huggingface/hub
echo "Removing Hugging Face cache..."
rm -rf ~/.cache/huggingface/hub
else
echo "No Hugging Face cache found at ~/.cache/huggingface/hub"
fi
# Remove ffmpeg
echo "----------------------------------------"
echo "Removing ffmpeg..."
sudo apt-get remove -y ffmpeg > /dev/null
sudo apt-get autoremove -y > /dev/null
echo "FFmpeg removed"
echo "----------------------------------------"
echo "Cleanup completed"
echo "----------------------------------------"