forked from typesense/typesense
-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (203 loc) · 8.93 KB
/
tests.yml
File metadata and controls
245 lines (203 loc) · 8.93 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: tests
on: [push, pull_request]
# Cancel previous running if a new push is made
# Source: https://stackoverflow.com/a/72408109/123545
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y g++-10 make git zlib1g-dev m4
# Define the compiler
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 30
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 30
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
- name: Setup lld
run: |
sudo apt-get install -y lld
- name: Set up Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
disk-cache: ${{ vars.BAZEL_CACHE_KEY != '' && vars.BAZEL_CACHE_KEY || github.workflow }}
repository-cache: true
external-cache: true
- name: Build protobuf deps
run: |
bazel build @com_google_protobuf//:protobuf_headers
bazel build @com_google_protobuf//:protobuf_lite
bazel build @com_google_protobuf//:protobuf
bazel build @com_google_protobuf//:protoc
- name: Build Typesense
run: bazel build //:typesense-server
- name: Setup artifacts for tests
run: curl https://dl.typesense.org/ci/tyrec/tyrec-1-models.tar.gz > ./test/resources/models.tar.gz
- name: Run tests
run: bazel test --cache_test_results=no --test_output=all //:typesense-test --test_timeout=900
# Source: https://github.com/actions/upload-artifact/issues/92#issuecomment-1080347032
- name: Set BAZEL_BIN_FULL_PATH
run: echo "BAZEL_BIN_FULL_PATH=$(readlink -f bazel-bin)" >> $GITHUB_ENV
- name: Set BAZEL_TESTLOGS_FULL_PATH
run: echo "BAZEL_TESTLOGS_FULL_PATH=$(readlink -f bazel-testlogs)" >> $GITHUB_ENV
if: failure()
- name: Save build artifacts
uses: actions/upload-artifact@v4
with:
name: typesense-server
path: ${{ env.BAZEL_BIN_FULL_PATH }}/typesense-server
- name: Save test logs on failure
uses: actions/upload-artifact@v4
with:
name: test-logs
path: ${{ env.BAZEL_TESTLOGS_FULL_PATH }}/
if: failure()
api-tests:
needs: test
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Typesense Binary
uses: actions/download-artifact@v4
with:
name: typesense-server
path: ./typesense-server-binary
- name: Get previous successful run
id: get-previous-run
run: |
# First determine if we're on a fork
REPO_INFO=$(gh api /repos/${{ github.repository }})
IS_FORK=$(echo "$REPO_INFO" | jq -r '.fork')
PARENT_REPO=$(echo "$REPO_INFO" | jq -r '.parent.full_name // empty')
DEFAULT_BRANCH=$(echo "$REPO_INFO" | jq -r '.default_branch')
echo "Is fork: $IS_FORK"
if [ "$IS_FORK" = "true" ]; then
echo "This is a fork of $PARENT_REPO"
# For forks, get successful runs from the current repo
REPO_TO_CHECK="${{ github.repository }}"
else
echo "This is the main repo"
# For main repo, get successful runs from main branch
REPO_TO_CHECK="${{ github.repository }}"
BRANCH_FILTER="and .head_branch == \"$DEFAULT_BRANCH\""
fi
echo "Fetching workflow runs from $REPO_TO_CHECK..."
if [ "$IS_FORK" = "true" ]; then
RUNS_INFO=$(gh api -H "Accept: application/vnd.github+json" \
/repos/$REPO_TO_CHECK/actions/workflows/tests.yml/runs \
-q '.workflow_runs[] | select(.conclusion == "success") | {id: .id, sha: .head_sha, branch: .head_branch, conclusion: .conclusion}' \
--paginate | head -n 1)
else
RUNS_INFO=$(gh api -H "Accept: application/vnd.github+json" \
/repos/$REPO_TO_CHECK/actions/workflows/tests.yml/runs \
-q ".workflow_runs[] | select(.conclusion == \"success\" and .head_branch == \"$DEFAULT_BRANCH\") | {id: .id, sha: .head_sha, branch: .head_branch, conclusion: .conclusion}" \
--paginate | head -n 1)
fi
echo "Found runs info:"
echo "$RUNS_INFO"
if [ -z "$RUNS_INFO" ]; then
echo "No successful runs found"
echo "previous_run_id=" >> $GITHUB_OUTPUT
else
# Extract the latest run info
LATEST_RUN=$(echo "$RUNS_INFO" | head -n 1)
LATEST_ID=$(echo "$LATEST_RUN" | jq -r '.id')
echo "Latest successful run ID: $LATEST_ID"
echo "previous_run_id=$LATEST_ID" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ github.token }}
- name: Download cached model (if exists)
uses: actions/download-artifact@v5
with:
name: tei-model-cache
path: ./hf_cache
github-token: ${{ github.token }}
run-id: ${{ steps.get-previous-run.outputs.previous_run_id }}
continue-on-error: true
- name: Check cache contents
run: |
# Check what we actually downloaded
echo "Contents of hf_cache directory:"
ls -la ./hf_cache/ || echo "hf_cache directory is empty or doesn't exist"
# Create empty cache directory if none exists
if [ ! -d "./hf_cache" ]; then
echo "No cached model found, will download fresh"
mkdir -p ./hf_cache
fi
- name: Make binary executable
run: chmod +x ./typesense-server-binary/typesense-server
- name: Install bun
uses: oven-sh/setup-bun@v2
- name: Start TEI Container
run: |
docker run -d --name tei-container --runtime=runc -p 8080:80 \
-v ${{ github.workspace }}/hf_cache:/data \
ghcr.io/huggingface/text-embeddings-inference:cpu-latest \
--model-id sentence-transformers/all-MiniLM-L6-v2
- name: Wait for TEI Container to be ready
run: |
echo "Waiting for TEI Container to be ready..."
timeout 600 bash -c 'until curl -s http://localhost:8080/health > /dev/null; do sleep 5; done'
echo "TEI Container is ready!"
- name: Print TEI Container logs on failure
if: failure()
run: docker logs tei-container || echo "No logs found"
- name: Install dependencies
working-directory: api_tests
run: bun install
- name: Install typesense-api-tests
working-directory: api_tests
run: bun link
- name: Download test artifacts
working-directory: api_tests
run: |
sudo apt-get install -y tar
mkdir -p ./artifacts/v29
curl https://dl.typesense.org/releases/29.0/typesense-server-29.0-linux-amd64.tar.gz > ./artifacts/v29.tar.gz
tar -xzf ./artifacts/v29.tar.gz -C ./artifacts/v29/
- name: Run API tests with secrets
if: github.event.pull_request.head.repo.fork == false
working-directory: api_tests
env:
TYPESENSE_BINARY_PATH: ${{ github.workspace }}/typesense-server-binary/typesense-server
TYPESENSE_V29_BINARY_PATH: ${{ github.workspace }}/api_tests/artifacts/v29/typesense-server
TYPESENSE_DATA_DIR: ${{ github.workspace }}/tmp/test
OPEN_AI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_URL: ${{ secrets.AZURE_OPENAI_URL }}
run: typesense-api-tests
- name: Run API tests without secrets
if: github.event.pull_request.head.repo.fork == true
working-directory: api_tests
env:
TYPESENSE_BINARY_PATH: ${{ github.workspace }}/typesense-server-binary/typesense-server
TYPESENSE_V29_BINARY_PATH: ${{ github.workspace }}/api_tests/artifacts/v29/typesense-server
TYPESENSE_DATA_DIR: ${{ github.workspace }}/tmp/test
OPEN_AI_API_KEY: ""
run: typesense-api-tests --no-secrets
- name: Upload model cache for next run
if: always()
uses: actions/upload-artifact@v4
with:
name: tei-model-cache
path: ./hf_cache
if-no-files-found: warn
overwrite: false
retention-days: 7
- name: Cleanup TEI Container
if: always()
run: |
docker stop tei-container || true
docker rm tei-container || true