-
Notifications
You must be signed in to change notification settings - Fork 1
300 lines (282 loc) · 11.4 KB
/
release.yaml
File metadata and controls
300 lines (282 loc) · 11.4 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
name: release
on:
workflow_dispatch:
schedule:
- cron: '0 20 * * *'
env:
APP_NAME: ollama
REPO_NAME: ollama/ollama
CGO_CFLAGS: '-O3'
CGO_CXXFLAGS: '-O3'
jobs:
check:
runs-on: ubuntu-latest
environment: release
outputs:
APP_BUILD: ${{ steps.check-release.outputs.build }}
APP_VERSION: ${{ steps.get-version.outputs.APP_VERSION }}
steps:
- uses: actions/checkout@v6
- name: Get Version
id: get-version
run: |
APP_VERSION=$(curl -s "https://api.github.com/repos/${{ env.REPO_NAME }}/releases/latest" | jq -r .tag_name)
GO_VERSION=$(curl -sSL https://github.com/${{ env.REPO_NAME }}/raw/${APP_VERSION}/go.mod | awk '/^go/ { print $2 }')
if [ -z "${APP_VERSION}" ] || [ "${APP_VERSION}" == "null" ] || [ -z "${GO_VERSION}" ] || [ "${GO_VERSION}" == "null" ]; then
echo "Failed to get version"
exit 1
fi
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_OUTPUT
echo ""
echo "========== Build Args =========="
echo "APP_VERSION=${APP_VERSION}"
echo "GO_VERSION=${GO_VERSION}"
- name: Check Release
id: check-release
run: |
gh release view ${APP_VERSION} -R ${{ github.repository }} >/dev/null 2>&1 || echo "create=1" >> $GITHUB_OUTPUT
gh release view ${APP_VERSION} -R ${{ github.repository }} | grep ${{ env.APP_NAME }}-linux-loong64.tgz >/dev/null 2>&1 || echo "build=1" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Tag
if : steps.check-release.outputs.create == '1'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Release ${APP_VERSION}" || true
git tag ${APP_VERSION} || true
git push origin ${APP_VERSION} || true
git push origin HEAD:main || true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
setup-environment:
runs-on: ubuntu-latest
environment: release
needs: check
if: needs.check.outputs.APP_BUILD == '1'
env:
APP_VERSION: ${{ needs.check.outputs.APP_VERSION }}
outputs:
GOFLAGS: ${{ steps.goflags.outputs.GOFLAGS }}
VERSION: ${{ steps.goflags.outputs.VERSION }}
steps:
- uses: actions/checkout@v6
- name: Set environment
id: goflags
run: |
GITHUB_REF_NAME=${{ env.APP_VERSION }}
echo GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=${GITHUB_REF_NAME#v}\" \"-X=github.com/ollama/ollama/server.mode=release\"'" | tee -a $GITHUB_OUTPUT
echo VERSION="${GITHUB_REF_NAME#v}" | tee -a $GITHUB_OUTPUT
linux-build:
strategy:
matrix:
include:
- os: linux
arch: loong64
target: archive
runs-on: ubuntu-latest
environment: release
needs:
- setup-environment
env:
REPO_TAG: v${{ needs.setup-environment.outputs.VERSION }}
VERSION: ${{ needs.setup-environment.outputs.VERSION }}
GOFLAGS: ${{ needs.setup-environment.outputs.GOFLAGS }}
steps:
- uses: actions/checkout@v6
with:
repository: ${{ env.REPO_NAME }}
ref: ${{ env.REPO_TAG }}
- name: Prepare
run: |
wget -qO - https://github.com/${{ github.repository }}/raw/refs/heads/main/ggml-rsync-filter-loong64.patch | git apply
make -f Makefile.sync clean checkout apply-patches sync
wget -qO - https://github.com/${{ github.repository }}/raw/refs/heads/main/loong64.patch | git apply
rm -f Dockerfile
wget https://github.com/${{ github.repository }}/raw/refs/heads/main/Dockerfile
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.os }}/${{ matrix.arch }}
target: ${{ matrix.target }}
build-args: |
GOFLAGS=${{ env.GOFLAGS }}
CGO_CFLAGS=${{ env.CGO_CFLAGS }}
CGO_CXXFLAGS=${{ env.CGO_CXXFLAGS }}
outputs: type=local,dest=dist/${{ matrix.os }}-${{ matrix.arch }}
cache-from: type=registry,ref=${{ vars.DOCKER_REPO }}:latest
cache-to: type=inline
- run: |
for COMPONENT in bin/* lib/ollama/*; do
case "$COMPONENT" in
bin/ollama) echo $COMPONENT >>ollama-${{ matrix.os }}-${{ matrix.arch }}.tar.in ;;
lib/ollama/*.so*) echo $COMPONENT >>ollama-${{ matrix.os }}-${{ matrix.arch }}.tar.in ;;
lib/ollama/cuda_v*) echo $COMPONENT >>ollama-${{ matrix.os }}-${{ matrix.arch }}.tar.in ;;
lib/ollama/vulkan*) echo $COMPONENT >>ollama-${{ matrix.os }}-${{ matrix.arch }}.tar.in ;;
lib/ollama/cuda_jetpack5) echo $COMPONENT >>ollama-${{ matrix.os }}-${{ matrix.arch }}-jetpack5.tar.in ;;
lib/ollama/cuda_jetpack6) echo $COMPONENT >>ollama-${{ matrix.os }}-${{ matrix.arch }}-jetpack6.tar.in ;;
lib/ollama/rocm) echo $COMPONENT >>ollama-${{ matrix.os }}-${{ matrix.arch }}-rocm.tar.in ;;
esac
done
working-directory: dist/${{ matrix.os }}-${{ matrix.arch }}
- run: |
echo "Manifests"
for ARCHIVE in dist/${{ matrix.os }}-${{ matrix.arch }}/*.tar.in ; do
echo $ARCHIVE
cat $ARCHIVE
done
- run: |
for ARCHIVE in dist/${{ matrix.os }}-${{ matrix.arch }}/*.tar.in; do
tar c -C dist/${{ matrix.os }}-${{ matrix.arch }} -T $ARCHIVE --owner 0 --group 0 | pigz -9vc >$(basename ${ARCHIVE//.*/}.tgz);
done
- uses: actions/upload-artifact@v4
with:
name: bundles-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.target }}
path: |
*.tgz
docker-build-push:
strategy:
matrix:
include:
- os: linux
arch: loong64
build-args: |
CGO_CFLAGS
CGO_CXXFLAGS
GOFLAGS
runs-on: ubuntu-latest
environment: release
needs: setup-environment
env:
REPO_TAG: v${{ needs.setup-environment.outputs.VERSION }}
GOFLAGS: ${{ needs.setup-environment.outputs.GOFLAGS }}
steps:
- uses: actions/checkout@v6
with:
repository: ${{ env.REPO_NAME }}
ref: ${{ env.REPO_TAG }}
- name: Prepare
run: |
wget -qO - https://github.com/${{ github.repository }}/raw/refs/heads/main/ggml-rsync-filter-loong64.patch | git apply
make -f Makefile.sync clean checkout apply-patches sync
wget -qO - https://github.com/${{ github.repository }}/raw/refs/heads/main/loong64.patch | git apply
rm -f Dockerfile
wget https://github.com/${{ github.repository }}/raw/refs/heads/main/Dockerfile
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: build-push
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.os }}/${{ matrix.arch }}
build-args: ${{ matrix.build-args }}
outputs: type=image,name=${{ vars.DOCKER_REPO }},push-by-digest=true,name-canonical=true,push=true
cache-from: type=registry,ref=${{ vars.DOCKER_REPO }}:latest
cache-to: type=inline
- run: |
mkdir -p ${{ matrix.os }}-${{ matrix.arch }}
echo "${{ steps.build-push.outputs.digest }}" >${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.suffix }}.txt
working-directory: ${{ runner.temp }}
- uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.suffix }}
path: |
${{ runner.temp }}/${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.suffix }}.txt
docker-merge-push:
strategy:
matrix:
suffix: ['']
runs-on: ubuntu-latest
environment: release
needs: [setup-environment, docker-build-push]
env:
version: v${{ needs.setup-environment.outputs.VERSION }}
steps:
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: metadata
uses: docker/metadata-action@v4
with:
flavor: |
latest=false
suffix=${{ matrix.suffix }}
images: |
${{ vars.DOCKER_REPO }}
tags: |
type=raw,value=${{ env.version }}
type=raw,value=latest
- uses: actions/download-artifact@v4
with:
pattern: digest-*
path: ${{ runner.temp }}
merge-multiple: true
- run: |
docker buildx imagetools create $(echo '${{ steps.metadata.outputs.json }}' | jq -cr '.tags | map("-t", .) | join(" ")') $(cat *-${{ matrix.suffix }}.txt | xargs printf '${{ vars.DOCKER_REPO }}@%s ')
docker buildx imagetools inspect ${{ vars.DOCKER_REPO }}:${{ steps.metadata.outputs.version }}
working-directory: ${{ runner.temp }}
# Final release process
release:
runs-on: ubuntu-latest
environment: release
needs: [setup-environment, linux-build]
permissions:
contents: write
env:
REPO_TAG: v${{ needs.setup-environment.outputs.VERSION }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v6
- uses: actions/download-artifact@v4
with:
pattern: bundles-*
path: dist
merge-multiple: true
- name: Log dist contents
run: |
ls -l dist/
- name: Generate checksum file
run: find . -type f -not -name 'sha256sum.txt' | xargs sha256sum | tee sha256sum.txt
working-directory: dist
- name: Create or update Release for tag
run: |
GITHUB_REF_NAME=${{ env.REPO_TAG }}
RELEASE_VERSION="$(echo ${GITHUB_REF_NAME} | cut -f1 -d-)"
echo "Looking for existing release for ${RELEASE_VERSION}"
OLD_TAG=$(gh release ls --json name,tagName | jq -r ".[] | select(.name == \"${RELEASE_VERSION}\") | .tagName")
if [ -n "$OLD_TAG" ]; then
echo "Updating release ${RELEASE_VERSION} to point to new tag ${GITHUB_REF_NAME}"
gh release edit ${OLD_TAG} --tag ${GITHUB_REF_NAME}
else
echo "Creating new release ${RELEASE_VERSION} pointing to tag ${GITHUB_REF_NAME}"
gh release create ${GITHUB_REF_NAME} \
--title ${RELEASE_VERSION} \
--generate-notes
fi
- name: Upload release artifacts
run: |
GITHUB_REF_NAME=${{ env.REPO_TAG }}
pids=()
# for payload in dist/*.txt dist/*.zip dist/*.tgz dist/*.exe dist/*.dmg ; do
for payload in dist/*.txt dist/*.zip dist/*.tgz ; do
echo "Uploading $payload"
gh release upload ${GITHUB_REF_NAME} $payload --clobber &
pids[$!]=$!
sleep 1
done
echo "Waiting for uploads to complete"
for pid in "${pids[*]}"; do
wait $pid
done
echo "done"