|
1 | | -name: Test Azure OpenAI response |
2 | | - |
3 | | -on: |
4 | | - workflow_dispatch: # run only when you click “Run workflow” |
5 | | - |
6 | | -jobs: |
7 | | - response-test: |
8 | | - runs-on: ubuntu-latest |
9 | | - environment: responses # pulls in the secrets already in that env |
10 | | - |
11 | | - steps: |
12 | | - - name: ⬇️ Check out repo |
13 | | - uses: actions/checkout@v4 |
14 | | - |
15 | | - - name: 🐍 Set up Python |
16 | | - uses: actions/setup-python@v5 |
17 | | - with: |
18 | | - python-version: '3.11' |
19 | | - |
20 | | - - name: 📦 Install dependencies |
21 | | - run: | |
22 | | - python -m pip install --upgrade pip |
23 | | - pip install openai python-dotenv |
24 | | -
|
25 | | - # ───────────── CORE TEST STEP ───────────── |
26 | 1 | - name: 🧪 Run script & build report |
27 | 2 | id: test |
28 | | - shell: python # <<< everything below is pure Python |
29 | 3 | env: |
30 | 4 | AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} |
31 | 5 | AZURE_OPENAI_V1_API_ENDPOINT: ${{ secrets.AZURE_OPENAI_V1_API_ENDPOINT }} |
32 | 6 | AZURE_OPENAI_API_MODEL: ${{ secrets.AZURE_OPENAI_API_MODEL }} |
33 | 7 | run: | |
| 8 | + python - <<'PY' |
34 | 9 | import datetime, json, pathlib, subprocess, sys |
35 | 10 |
|
36 | | - # run the existing file and capture its stdout / exit code |
| 11 | + # Execute your existing script and capture its stdout / exit code |
37 | 12 | proc = subprocess.run( |
38 | 13 | [sys.executable, "responses-basic-aoai-v1.py"], |
39 | 14 | capture_output=True, text=True |
40 | 15 | ) |
41 | | - output = proc.stdout.strip() |
42 | | - error_code = proc.returncode |
43 | | - passed = bool(output) and error_code == 0 # tweak if you need stricter logic |
| 16 | + output = proc.stdout.strip() |
| 17 | + error_code = proc.returncode |
| 18 | + passed = bool(output) and error_code == 0 # customise as needed |
44 | 19 |
|
45 | 20 | result = { |
46 | 21 | "run_timestamp_utc": datetime.datetime.utcnow() |
47 | | - .isoformat(timespec="seconds") + "Z", |
| 22 | + .isoformat(timespec="seconds") + "Z", |
48 | 23 | "output": output, |
49 | 24 | "pass": passed, |
50 | 25 | "error_code": error_code, |
|
54 | 29 | json.dumps(result, indent=2), encoding="utf-8" |
55 | 30 | ) |
56 | 31 |
|
57 | | - # Fail the job if the test failed |
58 | 32 | if not passed: |
59 | 33 | sys.exit(error_code or 1) |
60 | | -
|
61 | | - # ───────────── UPLOAD REPORT ───────────── |
62 | | - - name: 📤 Upload test artifact |
63 | | - if: always() # still run even if the step above failed |
64 | | - uses: actions/upload-artifact@v4 |
65 | | - with: |
66 | | - name: aoai-response-test |
67 | | - path: aoai_test_result.json |
| 34 | + PY |
0 commit comments