Repository navigation
164 lines (146 loc) · 5.42 KB
/
Copy pathtest-code-samples.yml
File metadata and controls
164 lines (146 loc) · 5.42 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
---
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
timeout-minutes: 15
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" ]]; then
echo "run_all=true" >> "$GITHUB_OUTPUT"
echo "Weekly 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)$' \
| 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, or .kt 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: 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 }}
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
# Creates a Linear issue when the weekly scheduled test fails.
# Required setup: Add LINEAR_API_KEY (repo secret) and LINEAR_TEAM_KEY (repo variable)
create-linear-ticket:
needs: test-code-samples
if: failure() && github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Create Linear issue
uses: ctriolo/action-create-linear-issue@v1.3
with:
linear-api-key: ${{ secrets.LINEAR_API_KEY }}
linear-team-key: ${{ vars.LINEAR_TEAM_KEY }}
linear-issue-title: "Weekly code samples test failed"
linear-issue-description: |
The scheduled weekly test of all code samples in `src/code-samples/` failed.
**Workflow run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Please investigate and fix the failing samples.
linear-attachment-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
linear-attachment-title: "Failed workflow run"