Skip to content

Commit 3ddd9b8

Browse files
authored
Update test-responses-basic-aoai-v1.yml
1 parent f8ca610 commit 3ddd9b8

File tree

1 file changed

+49
-85
lines changed

1 file changed

+49
-85
lines changed
Lines changed: 49 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,67 @@
1-
name: Validate Azure OpenAI response
1+
name: Validate Azure OpenAI response
22

33
on:
4-
workflow_dispatch:
4+
workflow_dispatch: # run on demand from the Actions tab
55

66
jobs:
77
run-validation:
8-
name: Run AOAI basic response validation
98
runs-on: ubuntu-latest
10-
environment: responses
9+
environment: responses # 🔑 unlocks the environment‑scoped secrets
1110

11+
# Expose the environment secrets as real process env‑vars
1212
env:
13-
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
13+
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
1414
AZURE_OPENAI_V1_API_ENDPOINT: ${{ secrets.AZURE_OPENAI_V1_API_ENDPOINT }}
15-
AZURE_OPENAI_API_MODEL: ${{ secrets.AZURE_OPENAI_API_MODEL }}
15+
AZURE_OPENAI_API_MODEL: ${{ secrets.AZURE_OPENAI_API_MODEL }}
1616

1717
steps:
18-
- name: 📥 Checkout repository
19-
uses: actions/checkout@v4
18+
# 1 – check out the repo so the script is available
19+
- uses: actions/checkout@v4
2020

21-
- name: 🐍 Set up Python 3.11
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version: '3.11'
21+
# 2 – set up Python
22+
- uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.11"
2525

26-
- name: 📦 Install requirements
27-
run: |
28-
sudo apt-get update
29-
sudo apt-get install -y jq
30-
python -m pip install --upgrade pip
31-
pip install openai python-dotenv
26+
# 3 – install the script’s two lightweight deps
27+
- name: Install requirements
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install openai python-dotenv
3231
33-
- name: ▶️ Execute script and capture outcome
34-
id: test
35-
shell: bash
36-
run: |
37-
set +e
38-
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
32+
# 4 – run the script, grade the result, assemble a report
33+
- name: Execute script and capture outcome
34+
id: test
35+
shell: bash
36+
run: |
37+
set +e # we want to handle failures ourselves
38+
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
3939
40-
python responses-basic-aoai-v1.py > out.txt 2>&1
41-
EXIT_CODE=$?
40+
# === run the user script ===
41+
python responses-basic-aoai-v1.py > out.txt 2>&1
42+
EXIT_CODE=$?
4243
43-
if [[ $EXIT_CODE -eq 0 && -s out.txt ]]; then
44-
PASS_FAIL="PASS"
45-
else
46-
PASS_FAIL="FAIL"
47-
fi
44+
# === decide pass / fail ===
45+
if [[ $EXIT_CODE -eq 0 && -s out.txt ]]; then
46+
PASS_FAIL="PASS"
47+
else
48+
PASS_FAIL="FAIL"
49+
fi
4850
49-
jq -n \
50-
--arg date "$TIMESTAMP" \
51-
--arg output "$(cat out.txt | tr -d '\r')" \
52-
--arg pass_fail "$PASS_FAIL" \
53-
--argjson code "$EXIT_CODE" \
54-
'{test_run_date: $date,
55-
output: $output,
56-
pass_fail: $pass_fail,
57-
error_code: $code}' \
58-
> aoai-test-result.json
51+
# === build JSON report ===
52+
jq -n \
53+
--arg date "$TIMESTAMP" \
54+
--arg output "$(cat out.txt | tr -d '\r')" \
55+
--arg pass_fail "$PASS_FAIL" \
56+
--argjson code "$EXIT_CODE" \
57+
'{test_run_date: $date,
58+
output: $output,
59+
pass_fail: $pass_fail,
60+
error_code: $code}' > aoai-test-result.json
5961
60-
- name: 📤 Upload result artifact
61-
if: always()
62-
uses: actions/upload-artifact@v4
63-
with:
64-
name: aoai-response-test
65-
path: aoai-test-result.json
66-
67-
- name: 📝 Parse results and update README
68-
if: always()
69-
shell: bash
70-
env:
71-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72-
run: |
73-
PASS=$(jq -r .pass_fail aoai-test-result.json)
74-
CODE=$(jq -r .error_code aoai-test-result.json)
75-
DATE=$(jq -r .test_run_date aoai-test-result.json)
76-
77-
read -r -d '' SNIPPET <<EOF
78-
<!-- AOAI-RESULTS-START -->
79-
## ⚙️ Last Azure OpenAI Test
80-
- **Date:** $DATE
81-
- **Result:** $PASS
82-
- **Exit code:** $CODE
83-
<!-- AOAI-RESULTS-END -->
84-
EOF
85-
86-
awk -v new="$SNIPPET" '
87-
/<!-- AOAI-RESULTS-START -->/ { print new; skip=1; next }
88-
/<!-- AOAI-RESULTS-END -->/ { print; skip=0; next }
89-
skip { next }
90-
{ print }
91-
' README.md > README.tmp && mv README.tmp README.md
92-
93-
- name: 🔀 Commit updated README
94-
if: >
95-
github.event_name == 'workflow_dispatch' &&
96-
github.actor != 'github-actions[bot]'
97-
uses: stefanzweifel/git-auto-commit-action@v4
98-
with:
99-
commit_message: 'chore: update README with latest AOAI test results'
100-
file_pattern: README.md
101-
author_name: GitHub Actions
102-
author_email: [email protected]
103-
branch: ${{ github.ref_name }}
62+
# 5 – make the report downloadable from the run summary
63+
- name: Upload result artifact
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: aoai-response-test # folder name visible in the UI
67+
path: aoai-test-result.json

0 commit comments

Comments
 (0)