-
Notifications
You must be signed in to change notification settings - Fork 3
183 lines (160 loc) · 5.61 KB
/
Copy pathpr-test.yml
File metadata and controls
183 lines (160 loc) · 5.61 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
name: PR Example Tests
# Runs the example folders changed in this PR.
# - lint + dry-run are secrets-free and run on every PR, including forks.
# - live-run uses real Opik credentials and runs only when secrets are available
# (same-repo PRs); it confirms the example executes and logs traces to the
# opik-examples workspace.
# Any job failure blocks the PR.
on:
pull_request:
paths:
- "examples/**"
- "integrations/**"
- "scripts/**"
- "use-cases/**"
- "guides/**"
permissions:
contents: read
concurrency:
group: pr-test-${{ github.ref }}
cancel-in-progress: true
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
folders: ${{ steps.detect.outputs.folders }}
has_changes: ${{ steps.detect.outputs.has_changes }}
has_secrets: ${{ steps.secrets.outputs.has_secrets }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Detect changed runnable example folders
id: detect
run: |
changed_files=$(git diff --name-only "origin/${{ github.base_ref }}...HEAD")
seen=()
folders_json="["
while IFS= read -r file; do
top=$(echo "$file" | cut -d'/' -f1)
case "$top" in
integrations)
folder=$(echo "$file" | cut -d'/' -f1,2,3)
;;
examples|scripts|use-cases|guides)
folder=$(echo "$file" | cut -d'/' -f1,2)
;;
*)
continue
;;
esac
if [[ -z "$folder" ]] || [[ ! -d "$folder" ]] || [[ ! -f "$folder/run.sh" ]]; then
continue
fi
already_seen=false
for s in "${seen[@]}"; do
[[ "$s" == "$folder" ]] && already_seen=true && break
done
if [[ "$already_seen" == false ]]; then
seen+=("$folder")
[[ "${#seen[@]}" -gt 1 ]] && folders_json="$folders_json,"
folders_json="$folders_json\"$folder\""
fi
done <<< "$changed_files"
folders_json="$folders_json]"
if [[ "${#seen[@]}" -eq 0 ]]; then
echo "folders=[]" >> "$GITHUB_OUTPUT"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "No runnable example folders changed."
else
echo "folders=$folders_json" >> "$GITHUB_OUTPUT"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
echo "Runnable folders to test: ${seen[*]}"
fi
- name: Check whether Opik secrets are available
id: secrets
# secrets.* is not available in job-level `if:`, so resolve it here and
# expose a boolean output the live-run job can gate on. Fork PRs get no
# secrets, so this is false and only lint + dry-run run.
env:
OPIK_API_KEY: ${{ secrets.OPIK_API_KEY }}
run: |
if [[ -n "$OPIK_API_KEY" ]]; then
echo "has_secrets=true" >> "$GITHUB_OUTPUT"
echo "Opik secrets available — live run will execute."
else
echo "has_secrets=false" >> "$GITHUB_OUTPUT"
echo "No Opik secrets (fork PR) — lint + dry-run only."
fi
lint:
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
folder: ${{ fromJson(needs.detect-changes.outputs.folders) }}
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
with:
version: "latest"
enable-cache: true
python-version: "3.12"
- name: Ruff check + format
run: |
cd "${{ matrix.folder }}"
uv sync
uv run ruff check .
uv run ruff format --check .
dry-run:
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
folder: ${{ fromJson(needs.detect-changes.outputs.folders) }}
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
with:
version: "latest"
enable-cache: true
python-version: "3.12"
- name: Run example (dry-run, no credentials)
# No Opik/LLM secrets in env: the example must detect missing credentials,
# fall back to DRY_RUN, and exit 0. This is the only execution signal fork
# PRs receive, and it enforces that every example's dry-run path works.
run: |
cd "${{ matrix.folder }}"
bash run.sh
live-run:
needs: detect-changes
if: needs.detect-changes.outputs.has_changes == 'true' && needs.detect-changes.outputs.has_secrets == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
folder: ${{ fromJson(needs.detect-changes.outputs.folders) }}
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
with:
version: "latest"
enable-cache: true
python-version: "3.12"
- name: Run example (live, real Opik credentials)
env:
OPIK_API_KEY: ${{ secrets.OPIK_API_KEY }}
OPIK_WORKSPACE: ${{ vars.OPIK_WORKSPACE }}
OPIK_ENVIRONMENT: ${{ vars.OPIK_ENVIRONMENT }}
OPIK_EXAMPLES_MODEL: ${{ vars.OPIK_EXAMPLES_MODEL }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
cd "${{ matrix.folder }}"
bash run.sh