@@ -18,22 +18,14 @@ jobs:
1818 id : changes
1919 run : |
2020 if [ "${{ github.event_name }}" == "pull_request" ]; then
21- BASE_SHA="${{ github.event.pull_request.base.sha }}"
22- HEAD_SHA="${{ github.event.pull_request.head.sha }}"
21+ # For PRs, compare PR head against base
22+ git fetch origin ${{ github.event.pull_request.base.ref }}
23+ CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD)
2324 else
24- # For push events, compare with previous commit
25- BASE_SHA="${{ github.event.before }}"
26- HEAD_SHA="${{ github.sha }}"
27- # Handle initial push (no previous commit)
28- if [ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]; then
29- echo "functions=true" >> $GITHUB_OUTPUT
30- echo "ui=true" >> $GITHUB_OUTPUT
31- exit 0
32- fi
25+ # For push events, compare against default branch
26+ CHANGED_FILES=$(git diff --name-only origin/${{ github.event.repository.default_branch }}...HEAD)
3327 fi
3428
35- CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA)
36-
3729 if echo "$CHANGED_FILES" | grep -q '^functions/'; then
3830 echo "functions=true" >> $GITHUB_OUTPUT
3931 else
6759 - name : Install Python dependencies
6860 run : pip install -r requirements.txt
6961 working-directory : ${{ matrix.function }}
70- - name : Install HTTPie for API testing
71- run : pip install httpie
72- if : matrix.function == 'functions/csv-import'
7362 - name : Run tests if test_main.py exists
7463 run : |
7564 if [ -f "test_main.py" ]; then
@@ -79,108 +68,6 @@ jobs:
7968 echo "No test_main.py found, skipping tests"
8069 fi
8170 working-directory : ${{ matrix.function }}
82- - name : Run Python function and verify output
83- env :
84- FALCON_CLIENT_ID : ${{ secrets.FALCON_CLIENT_ID }}
85- FALCON_CLIENT_SECRET : ${{ secrets.FALCON_CLIENT_SECRET }}
86- FALCON_BASE_URL : ${{ secrets.FALCON_BASE_URL }}
87- APP_ID : ${{ secrets.APP_ID }}
88- run : |
89- # Start the function
90- python main.py > output.log 2>&1 &
91- PID=$!
92- timeout=30
93- elapsed=0
94- while [ $elapsed -lt $timeout ]; do
95- if grep -q "running at port 8081" output.log; then
96- echo "✅ Application started successfully"
97- break
98- fi
99- sleep 1
100- elapsed=$((elapsed+1))
101- done
102-
103- if [ $elapsed -ge $timeout ]; then
104- echo "❌ Application failed to start within $timeout seconds"
105- cat output.log
106- kill $PID 2>/dev/null || true
107- exit 1
108- fi
109-
110- TEST_FAILURES=0
111-
112- # Run CSV import tests
113- if [[ "${{ matrix.function }}" == "functions/csv-import" ]]; then
114- echo "Running CSV import tests..."
115- sleep 2
116-
117- # Create sample CSV if needed
118- if [ ! -f "security_events.csv" ]; then
119- echo "timestamp,event_type,severity,description,source_ip,destination_ip,user" > security_events.csv
120- echo "2025-07-11T14:14:08Z,login_failure,medium,Failed login from IP 192.168.1.100,192.168.1.100,192.168.1.1,test.user" >> security_events.csv
121- echo "2025-07-11T14:15:22Z,malware_detected,high,Malware detected on workstation,192.168.1.101,192.168.1.1,admin.user" >> security_events.csv
122- fi
123-
124- # Test 1: Import CSV with file path
125- echo "=== Test 1: Import file path ==="
126- set +e
127- http --ignore-stdin POST :8081 method=POST url=/import-csv "body[csv_file_path]=security_events.csv" > import_file_output.log 2>&1
128- IMPORT_FILE_EXIT_CODE=$?
129- set -e
130-
131- if [ $IMPORT_FILE_EXIT_CODE -eq 0 ] && grep -q '"success": true' import_file_output.log; then
132- echo "✅ Import file path test passed"
133- else
134- echo "❌ Import file path test failed"
135- cat import_file_output.log
136- TEST_FAILURES=$((TEST_FAILURES + 1))
137- fi
138-
139- # Test 2: Import CSV with inline data
140- echo "=== Test 2: Import inline data ==="
141- CSV_DATA=$(cat security_events.csv)
142- set +e
143- http --ignore-stdin POST :8081 method=POST url=/import-csv "body[csv_data]=$CSV_DATA" > import_data_output.log 2>&1
144- IMPORT_DATA_EXIT_CODE=$?
145- set -e
146-
147- if [ $IMPORT_DATA_EXIT_CODE -eq 0 ] && grep -q '"success": true' import_data_output.log; then
148- echo "✅ Import inline data test passed"
149- else
150- echo "❌ Import inline data test failed"
151- cat import_data_output.log
152- TEST_FAILURES=$((TEST_FAILURES + 1))
153- fi
154-
155- # Test 3: Execute import.py script
156- if [ -f "import.py" ]; then
157- echo "=== Test 3: Import script ==="
158- set +e
159- python import.py > import_script_output.log 2>&1
160- IMPORT_SCRIPT_EXIT_CODE=$?
161- set -e
162-
163- if [ $IMPORT_SCRIPT_EXIT_CODE -eq 0 ] && grep -q '"success": true' import_script_output.log; then
164- echo "✅ Import script test passed"
165- else
166- echo "❌ Import script test failed"
167- cat import_script_output.log
168- TEST_FAILURES=$((TEST_FAILURES + 1))
169- fi
170- fi
171- fi
172-
173- # Cleanup
174- kill $PID 2>/dev/null || true
175-
176- # Final result
177- if [ $TEST_FAILURES -gt 0 ]; then
178- echo "❌ $TEST_FAILURES test(s) failed"
179- exit 1
180- else
181- echo "✅ All tests passed"
182- fi
183- working-directory : ${{ matrix.function }}
18471
18572 test-ui :
18673 needs : check-changes
0 commit comments