-
Notifications
You must be signed in to change notification settings - Fork 372
215 lines (189 loc) · 8.32 KB
/
run-samples.yml
File metadata and controls
215 lines (189 loc) · 8.32 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# .github/workflows/run-samples.yml
# -----------------------------------------------------------------
# Run the same end-to-end test-suite against multiple "setups".
# A setup represents one already-provisioned environment
# (e.g., SAI_UAI or UAI) that supplies its own PROJECT_CLIENT
# secret. MODEL_DEPLOYMENT_NAME is shared across all setups.
# The workflow can be started three ways:
# 1. Automatically on any PR that modifies docs-samples/agents/**
# 2. Manually from the Actions tab / GitHub CLI (workflow_dispatch)
# 3. Via a slash-command comment in a PR ("/e2e <setup list>")
# -----------------------------------------------------------------
# ────────────────────────────────────────────────────────────────
# 0️⃣ TRIGGERS
# ────────────────────────────────────────────────────────────────
on:
# Automatic validation on pull requests
pull_request_target:
# Only PRs whose base branch is main
branches:
- main
# Only when sample code changes
paths:
- docs-samples/agents/**
# Run-button or gh CLI trigger
workflow_dispatch:
inputs:
setups:
description: "Setups to test (SAI_UAI,UAI) or 'all'"
required: false
ref:
description: "Git ref to test (defaults to branch head)"
required: false
# Slash-command trigger inside pull-request comments
issue_comment:
types:
- created
# ────────────────────────────────────────────────────────────────
# 1️⃣ HELPER JOB – figure out which setups to test
# ────────────────────────────────────────────────────────────────
jobs:
resolve-setups:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build.outputs.matrix }}
steps:
# Build the matrix JSON that downstream job will consume
- id: build
uses: actions/github-script@v7
with:
result-encoding: string
script: |
// Define all possible setups that this workflow supports.
const ALL_SETUPS = ['SAI_UAI', 'UAI'];
// Helper function to parse user input (comma-separated or 'all') into a list of setups.
function parse(input) {
// If input is empty, null, or 'all', return the full list.
if (
!input ||
input.trim() === '' ||
input.trim().toLowerCase() === 'all'
) {
return ALL_SETUPS;
}
// Otherwise, split the comma-separated string, trim whitespace, and remove empty entries.
return input
.split(',')
.map((s) => s.trim())
.filter(Boolean);
}
// Array to hold the setups requested for this specific workflow run.
let requested = [];
// Determine the requested setups based on how the workflow was triggered.
switch (context.eventName) {
case 'workflow_dispatch': {
// Triggered manually via UI or API.
// Get the 'setups' input provided by the user.
const inp = core.getInput('setups');
// Parse the user input.
requested = parse(inp);
break;
}
case 'issue_comment': {
// Triggered by a comment on a pull request.
const body = context.payload.comment.body;
// Check if the comment starts with the slash command '/e2e'.
const match = body.match(/^\/e2e\s+(.+)$/i);
if (match) {
// If it matches, parse the arguments provided after '/e2e'.
requested = parse(match[1]);
} else {
// If the comment doesn't match the command format, do nothing.
core.notice('Comment does not contain /e2e command');
}
break;
}
case 'pull_request_target':
// Triggered automatically by a PR change matching the path filter.
// Default to running all defined setups.
requested = ALL_SETUPS;
break;
}
// Validate that at least one setup was selected or determined.
if (!requested.length) {
// If no setups are found (e.g., invalid comment), fail the workflow early.
core.setFailed('No setups selected – stopping workflow.');
}
// Construct the matrix object in the format required by the downstream job's strategy.
const matrix = {
// The 'include' key pairs with the 'setup' variable name used in the e2e job.
include: requested.map((s) => ({ setup: s }))
};
// Convert the JavaScript matrix object into a JSON string to be used as the step's output.
return JSON.stringify(matrix);
# ────────────────────────────────────────────────────────────────
# 2️⃣ MAIN TEST JOB – one copy per setup
# ────────────────────────────────────────────────────────────────
e2e:
needs: resolve-setups
if: ${{ needs.resolve-setups.result == 'success' }}
strategy:
# Use the matrix built by the helper job
matrix: ${{ fromJSON(needs.resolve-setups.outputs.matrix) }}
# Do not cancel other setups if one fails
fail-fast: false
# Human-readable name in the Actions UI
name: "E2E – ${{ matrix.setup }}"
# Virtual-machine image
runs-on: ubuntu-latest
permissions:
# Needed to read repo contents
contents: read
# Needed if you acquire a cloud token via OIDC
id-token: write
# Map to per-setup environment (for PROJECT_CLIENT secret)
environment: setup-${{ matrix.setup }}
steps:
# ── Check out the code at the desired ref
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.ref ||
github.event.pull_request.head.sha ||
github.ref }}
# ── Set up Node.js for JavaScript tests
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
# ── Install JavaScript dependencies
- name: Install npm packages
run: npm ci
# ── Run Vitest
- name: Run Vitest
env:
PROJECT_CLIENT: ${{ secrets.PROJECT_CLIENT }}
MODEL_DEPLOYMENT_NAME: ${{ secrets.MODEL_DEPLOYMENT_NAME }}
run: npx vitest run --coverage
# ── Set up .NET SDK
- name: Set up .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
# ── Restore .NET dependencies
- name: dotnet restore
run: dotnet restore
# ── Run .NET tests
- name: dotnet test
env:
PROJECT_CLIENT: ${{ secrets.PROJECT_CLIENT }}
MODEL_DEPLOYMENT_NAME: ${{ secrets.MODEL_DEPLOYMENT_NAME }}
run: dotnet test -c Release --verbosity normal
# ── Set up Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: pip
# ── Install Python requirements
- name: Install Python dependencies
run: |
pip install -r docs-samples/agents/python/requirements.txt
# ── Run PyTest
- name: Run PyTest
env:
PROJECT_CLIENT: ${{ secrets.PROJECT_CLIENT }}
MODEL_DEPLOYMENT_NAME: ${{ secrets.MODEL_DEPLOYMENT_NAME }}
run: |
pytest docs-samples/agents/python --maxfail=1 --disable-warnings