-
Notifications
You must be signed in to change notification settings - Fork 2
153 lines (130 loc) · 5.41 KB
/
Copy pathbuild.yml
File metadata and controls
153 lines (130 loc) · 5.41 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
name: build
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
asset_suffix: linux-x86_64
archive_ext: tar.gz
- os: macos-latest
asset_suffix: macos-aarch64
archive_ext: tar.gz
- os: windows-latest
asset_suffix: windows-x86_64
archive_ext: zip
steps:
- uses: actions/checkout@v6
- run: rustup update
- name: Build debug version
run: cargo build --verbose
- name: Test debug version
run: cargo test --verbose
- name: Run C integration tests (Unix)
if: runner.os != 'Windows'
run: cd test && ./test.sh
- name: Set up MSVC
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
- name: Run C integration tests (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
cl /nologo test\run_tests.c /Fe:test\run_tests.exe /link /LIBPATH:target\debug tiktoken_c.dll.lib
set PATH=%CD%\target\debug;%PATH%
test\run_tests.exe
- name: Build default release version
run: cargo build --release --target-dir target/default --verbose
- name: Build logging release version
run: cargo build --release --features logging --target-dir target/logging --verbose
- name: Set asset names
id: asset_names
shell: bash
run: |
version_name="${GITHUB_REF_NAME}"
if [[ "${GITHUB_REF}" != refs/tags/v* ]]; then
version_name="${GITHUB_SHA::7}"
fi
echo "archive_name=tiktoken-c-${version_name}-${{ matrix.asset_suffix }}.${{ matrix.archive_ext }}" >> "$GITHUB_OUTPUT"
echo "header_name=tiktoken-c-${version_name}.h" >> "$GITHUB_OUTPUT"
- name: Create package
shell: bash
run: |
mkdir -p release_package
cp tiktoken.h release_package/
cp README.md release_package/
cp LICENSE.txt release_package/
if [[ "${{ runner.os }}" == "Windows" ]]; then
cp target/default/release/tiktoken_c.dll release_package/
cp target/default/release/tiktoken_c.dll.lib release_package/
cp target/logging/release/tiktoken_c.dll release_package/tiktoken_c_debug.dll
cp target/logging/release/tiktoken_c.dll.lib release_package/tiktoken_c_debug.dll.lib
else
for ext in a so dylib; do
if [[ -f "target/default/release/libtiktoken_c.$ext" ]]; then
cp "target/default/release/libtiktoken_c.$ext" release_package/
fi
if [[ -f "target/logging/release/libtiktoken_c.$ext" ]]; then
cp "target/logging/release/libtiktoken_c.$ext" "release_package/libtiktoken_c_debug.$ext"
fi
done
fi
- name: Create archive (Unix)
if: runner.os != 'Windows'
run: tar -czf ${{ steps.asset_names.outputs.archive_name }} -C release_package .
- name: Create archive (Windows)
if: runner.os == 'Windows'
run: |
cd release_package
7z a ../${{ steps.asset_names.outputs.archive_name }} *
- name: Upload build artifact
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.asset_names.outputs.archive_name }}
path: ${{ steps.asset_names.outputs.archive_name }}
- name: Prepare header artifact
if: ${{ !startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' }}
shell: bash
run: cp tiktoken.h "${{ steps.asset_names.outputs.header_name }}"
- name: Upload header artifact
if: ${{ !startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.asset_names.outputs.header_name }}
path: ${{ steps.asset_names.outputs.header_name }}
- name: Ensure GitHub release exists
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
if ! gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --generate-notes >/dev/null 2>&1 || true
fi
for _ in 1 2 3 4 5; do
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
exit 0
fi
sleep 2
done
echo "Release for $GITHUB_REF_NAME is not discoverable yet" >&2
exit 1
- name: Upload release archive
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "$GITHUB_REF_NAME" "${{ steps.asset_names.outputs.archive_name }}" --clobber
- name: Prepare release header
if: ${{ startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' }}
shell: bash
run: cp tiktoken.h "${{ steps.asset_names.outputs.header_name }}"
- name: Upload release header
if: ${{ startsWith(github.ref, 'refs/tags/v') && matrix.os == 'ubuntu-latest' }}
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: gh release upload "$GITHUB_REF_NAME" "${{ steps.asset_names.outputs.header_name }}" --clobber