Skip to content

Commit 4cde6a8

Browse files
authored
Merge pull request #4 from guygregory/copilot/fix-3
Add GitHub Action to test Azure OpenAI Responses API script
2 parents 4d42d48 + 06e9da9 commit 4cde6a8

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Test Azure OpenAI Responses API
2+
3+
on:
4+
workflow_dispatch: # Allows manual triggering of the workflow
5+
6+
jobs:
7+
test-responses-api:
8+
runs-on: ubuntu-latest
9+
environment: responses # Use the 'responses' environment for secrets
10+
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements.txt
24+
25+
- name: Test Azure OpenAI Responses API
26+
env:
27+
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
28+
AZURE_OPENAI_V1_API_ENDPOINT: ${{ secrets.AZURE_OPENAI_V1_API_ENDPOINT }}
29+
AZURE_OPENAI_API_MODEL: ${{ secrets.AZURE_OPENAI_API_MODEL }}
30+
run: |
31+
echo "Testing responses-basic-aoai-v1.py script..."
32+
33+
# Create test results directory
34+
mkdir -p test-results
35+
36+
# Get current timestamp
37+
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
38+
echo "Test run timestamp: $timestamp"
39+
40+
# Run the script and capture output
41+
python responses-basic-aoai-v1.py > output.txt 2>&1
42+
exit_code=$?
43+
44+
# Initialize test result variables
45+
pass_fail="PASS"
46+
error_code=""
47+
output_text=""
48+
49+
# Check if script executed successfully
50+
if [ $exit_code -eq 0 ]; then
51+
echo "✅ Script executed successfully"
52+
53+
# Check if output was generated and capture it
54+
if [ -s output.txt ]; then
55+
output_text=$(cat output.txt)
56+
echo "✅ Script produced output:"
57+
echo "$output_text"
58+
59+
# Test whether response.output_text contains a valid string
60+
# Valid means: non-empty, no error indicators, and actual content
61+
if [ -n "$output_text" ] && ! echo "$output_text" | grep -qi "error\|exception\|traceback\|failed\|none\|null"; then
62+
echo "✅ Output contains valid string content"
63+
pass_fail="PASS"
64+
else
65+
echo "❌ Output does not contain valid string content"
66+
pass_fail="FAIL"
67+
error_code="INVALID_OUTPUT"
68+
fi
69+
else
70+
echo "❌ Script produced no output"
71+
pass_fail="FAIL"
72+
error_code="NO_OUTPUT"
73+
fi
74+
else
75+
echo "❌ Script failed with exit code: $exit_code"
76+
echo "Error output:"
77+
cat output.txt
78+
output_text=$(cat output.txt)
79+
pass_fail="FAIL"
80+
error_code="SCRIPT_ERROR_$exit_code"
81+
fi
82+
83+
# Create test results JSON (using jq for proper JSON formatting)
84+
jq -n \
85+
--arg timestamp "$timestamp" \
86+
--arg output "$output_text" \
87+
--arg pass_fail "$pass_fail" \
88+
--arg error_code "$error_code" \
89+
'{
90+
test_last_run_date: $timestamp,
91+
output: $output,
92+
pass_fail: $pass_fail,
93+
error_code: $error_code
94+
}' > test-results/test-results.json
95+
96+
# Display final results
97+
echo "=== Test Results ==="
98+
echo "Timestamp: $timestamp"
99+
echo "Pass/Fail: $pass_fail"
100+
echo "Error Code: $error_code"
101+
echo "Output: $output_text"
102+
103+
# Exit with error if test failed
104+
if [ "$pass_fail" = "FAIL" ]; then
105+
echo "❌ Test failed"
106+
exit 1
107+
else
108+
echo "🎉 Test completed successfully!"
109+
fi
110+
111+
- name: Upload test results artifact
112+
uses: actions/upload-artifact@v4
113+
if: always() # Upload artifact even if the test fails
114+
with:
115+
name: azure-openai-test-results
116+
path: test-results/
117+
retention-days: 30

0 commit comments

Comments
 (0)