This repository was archived by the owner on Aug 10, 2026. It is now read-only.
Repository navigation
151 lines (135 loc) Β· 4.96 KB
/
Copy pathtest-code-samples.yml
File metadata and controls
151 lines (135 loc) Β· 4.96 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
---
name: Test Code Samples
permissions:
contents: read
on:
pull_request:
paths:
- "src/code-samples/**"
- ".github/workflows/test-code-samples.yml"
workflow_dispatch:
schedule:
# Run every Sunday at 00:00 UTC
- cron: "0 0 * * 0"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-code-samples:
# GitHub does not expose repository secrets to workflows triggered from fork PRs.
# These tests require provider API keys for some samples, so skip on forks.
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false)
runs-on: ubuntu-latest
# Scheduled and manual runs test all samples; PR runs may touch many files in large refactors.
timeout-minutes: ${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && 90 || 60 }}
services:
postgres:
image: pgvector/pgvector:pg17
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get modified code sample paths
id: files
run: |
if [[ "${{ github.event_name }}" == "schedule" || "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "run_all=true" >> "$GITHUB_OUTPUT"
echo "Full run: testing all code samples"
else
echo "run_all=false" >> "$GITHUB_OUTPUT"
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
git fetch origin "${{ github.event.pull_request.base.ref }}"
BASE=$(git merge-base HEAD origin/${{ github.event.pull_request.base.ref }})
else
BASE="${{ github.event.before }}"
fi
FILES=$(git diff --name-only "$BASE" HEAD -- src/code-samples/ \
| grep -E '\.(py|ts|java|kt|go|sh)$' \
| tr '\n' ' ' || true)
{ echo "files<<FILESEND"; echo "$FILES"; echo "FILESEND"; } >> "$GITHUB_OUTPUT"
if [[ -n "$FILES" ]]; then
echo "Modified code samples: $FILES"
else
echo "No modified .py, .ts, .java, .kt, .go, or .sh files in src/code-samples/"
fi
fi
- name: Set up Python and uv
uses: ./.github/actions/uv_setup
with:
python-version: "3.13"
- name: Install project dependencies
run: uv sync
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Set up Java (for JBang)
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21"
- name: Install JBang
uses: jbangdev/setup-jbang@v0.1.1
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: src/code-samples/go.mod
- name: Wait for PostgreSQL
run: |
for i in $(seq 1 30); do
if python3 -c "
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(2)
try:
s.connect(('127.0.0.1', 5432))
s.close()
except OSError:
exit(1)
"; then
echo "PostgreSQL is ready"
exit 0
fi
echo "Waiting for PostgreSQL... ($i/30)"
sleep 2
done
echo "PostgreSQL did not become ready"
exit 1
- name: Test code samples
id: test
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
ANTHROPIC_CUSTOM_HEADERS: ${{ secrets.ANTHROPIC_CUSTOM_HEADERS }}
LS_GATEWAY_KEY: ${{ secrets.LS_GATEWAY_KEY }}
LANGSMITH_API_KEY: ${{ secrets.LANGSMITH_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
POSTGRES_URI: postgresql://postgres:postgres@127.0.0.1:5432/postgres?sslmode=disable
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
DAYTONA_API_KEY: ${{ secrets.DAYTONA_API_KEY }}
DAYTONA_API_URL: ${{ secrets.DAYTONA_API_URL }}
run: |
if [[ "${{ steps.files.outputs.run_all }}" == "true" ]]; then
echo "Running all code samples..."
make test-code-samples
else
FILES="${{ steps.files.outputs.files }}"
FILES=$(echo "$FILES" | tr -d '\n' | xargs)
if [[ -z "$FILES" ]]; then
echo "No code samples to test"
exit 0
fi
make test-code-samples FILES="$FILES"
fi