-
Notifications
You must be signed in to change notification settings - Fork 0
203 lines (167 loc) · 5.24 KB
/
Copy pathci.yml
File metadata and controls
203 lines (167 loc) · 5.24 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
name: Integration CI
# Main integration CI that runs when both Rust and Go code changes
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
permissions:
contents: read
jobs:
rust-test:
name: Rust Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
components: rustfmt, clippy
- name: Check formatting
run: cargo fmt -- --check
- name: Run clippy
run: cargo clippy -- -D warnings
- name: Run Rust tests
run: cargo test --verbose
- name: Build library
run: cargo build --release
go-test:
name: Go Tests
runs-on: ${{ matrix.os }}
needs: rust-test
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ['1.24']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Setup Rust
uses: ./.github/actions/setup-rust
- name: Install cargo-zigbuild (Linux/macOS)
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
run: cargo install cargo-zigbuild
- name: Build library (macOS)
if: matrix.os == 'macos-latest'
shell: bash
run: |
set -euo pipefail
LIB_PATH="$(
cargo build --release --message-format=json |
jq -r 'select(.reason=="compiler-artifact")
| select(.target.kind[]=="cdylib")
| .filenames[]
| select(endswith(".dylib"))' | head -n1
)"
echo "TOKENIZERS_LIB_PATH=$LIB_PATH" >> "$GITHUB_ENV"
echo "Using $LIB_PATH"
- name: Build library (Linux)
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
set -euo pipefail
ARGS=(--release --message-format=json)
LIB_PATH="$(
cargo zigbuild "${ARGS[@]}" |
jq -r 'select(.reason=="compiler-artifact")
| select(.target.kind[]=="cdylib")
| .filenames[]
| select(endswith(".so"))' | head -n1
)"
echo "TOKENIZERS_LIB_PATH=$LIB_PATH" >> "$GITHUB_ENV"
echo "Using $LIB_PATH"
- name: Build library (Windows)
if: matrix.os == 'windows-latest'
run: |
$ErrorActionPreference = "Stop"
# Build and capture output
$buildOutput = cargo build --release --message-format=json
if ($LASTEXITCODE -ne 0) {
throw "Cargo build failed with exit code $LASTEXITCODE"
}
# Parse and find DLL
$dll = $buildOutput `
| % {
try {
$_ | ConvertFrom-Json
} catch {
Write-Warning "Failed to parse JSON: $_"
$null
}
} `
| ? { $_.reason -eq "compiler-artifact" -and $_.target.kind -contains "cdylib" } `
| % { $_.filenames } | ? { $_ -like "*.dll" } `
| Get-Item | Sort-Object LastWriteTime -Descending `
| Select-Object -ExpandProperty FullName -First 1
# Validate result
if (-not $dll) {
throw "No DLL found in build output"
}
if (-not (Test-Path $dll)) {
throw "DLL path does not exist: $dll"
}
"TOKENIZERS_LIB_PATH=$dll" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Host "Using DLL: $dll"
- name: Check Library Path (Linux/macOS)
if: matrix.os != 'windows-latest'
shell: bash
run: |
if [ -z "$TOKENIZERS_LIB_PATH" ]; then
echo "TOKENIZERS_LIB_PATH is not set. Ensure the build step succeeded."
exit 1
fi
file "$TOKENIZERS_LIB_PATH" || true
- name: Check Library Path (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
if (-not $env:TOKENIZERS_LIB_PATH) {
Write-Error "TOKENIZERS_LIB_PATH is not set. Ensure the build step succeeded."
exit 1
}
Get-Item $env:TOKENIZERS_LIB_PATH
- name: Run Go linting
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m
- name: Run Go tests
run: |
go mod tidy
make test-ci
env:
GITHUB_TOKEN: ${{ github.token }}
go-security:
uses: ./.github/workflows/go-security.yml
with:
go-version: '1.24'
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
needs: [rust-test, go-test, go-security]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Setup Rust
uses: ./.github/actions/setup-rust
- name: Build library
run: cargo build --release
- name: Test download functionality (mock)
run: |
export TOKENIZERS_LIB_PATH="$(pwd)/target/release/libtokenizers.so"
go test -v -run "TestDownloadFunctionality|TestGetLibraryInfo"
- name: Test library loading
run: |
export TOKENIZERS_LIB_PATH="$(pwd)/target/release/libtokenizers.so"
go test -v -run "TestGetCachedLibraryPath|TestCacheDirectory"