Skip to content

Commit 63b4cb9

Browse files
committed
ci : add release job and include xcframework
This commit adds a release job that uploads the xcframework as an artifact and creates a release with the xcframework as an asset. This job can be triggered manually and enables a pre-release tag name to be specified to that these releases can be distinguished from the regular releases more easily. Resolves: #2886
1 parent 60b481d commit 63b4cb9

File tree

1 file changed

+163
-5
lines changed

1 file changed

+163
-5
lines changed

.github/workflows/build.yml

Lines changed: 163 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,79 @@ on:
66
- master
77
pull_request:
88
types: [opened, synchronize, reopened]
9+
workflow_dispatch:
10+
inputs:
11+
create_release:
12+
description: 'Create new release'
13+
required: true
14+
type: boolean
15+
pre_release_tag:
16+
description: 'Pre-release tag name'
17+
required: false
18+
type: string
19+
run_type:
20+
description: 'Workflow type to run'
21+
required: true
22+
type: choice
23+
options:
24+
- full-ci
25+
- release-only
926

1027
concurrency:
1128
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
1229
cancel-in-progress: true
1330

31+
permissions:
32+
contents: write # for creating release
33+
1434
env:
1535
ubuntu_image: "ubuntu:22.04"
1636
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
1737

1838
jobs:
39+
determine-tag:
40+
runs-on: ubuntu-latest
41+
outputs:
42+
tag_name: ${{ steps.tag.outputs.name }}
43+
44+
steps:
45+
- name: Checkout with full history
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Determine tag name
51+
id: tag
52+
shell: bash
53+
run: |
54+
BUILD_NUMBER=$(git rev-list --count HEAD)
55+
SHORT_HASH=$(git rev-parse --short=7 HEAD)
56+
CUSTOM_TAG="${{ github.event.inputs.pre_release_tag }}"
57+
58+
echo "Raw values:"
59+
echo "BUILD_NUMBER: $BUILD_NUMBER"
60+
echo "SHORT_HASH: $SHORT_HASH"
61+
echo "BRANCH_NAME: ${{ env.BRANCH_NAME }}"
62+
echo "CUSTOM_TAG: $CUSTOM_TAG"
63+
64+
# Use custom tag if provided
65+
if [[ -n "$CUSTOM_TAG" ]]; then
66+
echo "Using custom tag"
67+
TAG_NAME="${CUSTOM_TAG}"
68+
elif [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
69+
echo "Using master branch format"
70+
TAG_NAME="b${BUILD_NUMBER}"
71+
else
72+
echo "Using non-master branch format"
73+
SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
74+
TAG_NAME="${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}"
75+
fi
76+
77+
echo "Final tag name: $TAG_NAME"
78+
echo "name=$TAG_NAME" >> $GITHUB_OUTPUT
79+
1980
ubuntu-22:
81+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
2082
runs-on: ubuntu-22.04
2183

2284
strategy:
@@ -43,6 +105,7 @@ jobs:
43105
cmake --build build --config Release -j $(nproc)'
44106
45107
ubuntu-22-arm64:
108+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
46109
runs-on: ubuntu-22.04
47110

48111
strategy:
@@ -69,6 +132,7 @@ jobs:
69132
cmake --build build --config Release -j $(nproc)'
70133
71134
ubuntu-22-arm-v7:
135+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
72136
runs-on: ubuntu-22.04
73137

74138
strategy:
@@ -95,6 +159,7 @@ jobs:
95159
cmake --build build --config Release -j $(nproc)'
96160
97161
macOS-latest:
162+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
98163
runs-on: macOS-latest
99164

100165
strategy:
@@ -129,11 +194,6 @@ jobs:
129194
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
130195
cmake --build build --config Release -j $(sysctl -n hw.logicalcpu)
131196
132-
- name: xcodebuild for swift package
133-
id: xcodebuild
134-
run: |
135-
./build-xcframework.sh
136-
137197
138198
# freeBSD-latest:
139199
# runs-on: macos-12
@@ -154,6 +214,7 @@ jobs:
154214
# cmake --build build --config Release
155215

156216
ubuntu-22-gcc:
217+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
157218
runs-on: ubuntu-22.04
158219

159220
strategy:
@@ -182,6 +243,7 @@ jobs:
182243
ctest -L gh --output-on-failure'
183244
184245
ubuntu-22-gcc-arm64:
246+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
185247
runs-on: ubuntu-22.04
186248

187249
strategy:
@@ -210,6 +272,7 @@ jobs:
210272
ctest -L gh --output-on-failure'
211273
212274
ubuntu-22-gcc-arm-v7:
275+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
213276
runs-on: ubuntu-22.04
214277

215278
strategy:
@@ -238,6 +301,7 @@ jobs:
238301
ctest -L gh --output-on-failure'
239302
240303
ubuntu-22-clang:
304+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
241305
runs-on: ubuntu-22.04
242306

243307
strategy:
@@ -269,6 +333,7 @@ jobs:
269333
ctest -L gh --output-on-failure'
270334
271335
ubuntu-22-gcc-sanitized:
336+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
272337
runs-on: ubuntu-22.04
273338

274339
strategy:
@@ -297,6 +362,7 @@ jobs:
297362
ctest -L gh --output-on-failure'
298363
299364
ubuntu-22-cmake-sycl:
365+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
300366
runs-on: ubuntu-22.04
301367

302368
strategy:
@@ -347,6 +413,7 @@ jobs:
347413
cmake --build . --config Release -j $(nproc)
348414
349415
ubuntu-22-cmake-sycl-fp16:
416+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
350417
runs-on: ubuntu-22.04
351418

352419
strategy:
@@ -397,6 +464,7 @@ jobs:
397464
cmake --build . --config Release -j $(nproc)
398465
399466
windows-msys2:
467+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
400468
runs-on: windows-latest
401469

402470
strategy:
@@ -441,6 +509,7 @@ jobs:
441509
cmake --build build --config ${{ matrix.build }} -j $(nproc)
442510
443511
windows:
512+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
444513
runs-on: windows-latest
445514

446515
strategy:
@@ -501,6 +570,7 @@ jobs:
501570
path: build/bin/${{ matrix.build }}
502571

503572
windows-blas:
573+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
504574
runs-on: windows-latest
505575

506576
strategy:
@@ -574,6 +644,7 @@ jobs:
574644
path: build/bin/${{ matrix.build }}
575645

576646
windows-cublas:
647+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
577648
runs-on: windows-2019
578649
strategy:
579650
matrix:
@@ -642,6 +713,7 @@ jobs:
642713
path: build/bin/${{ matrix.build }}
643714

644715
emscripten:
716+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
645717
runs-on: ubuntu-22.04
646718

647719
strategy:
@@ -665,6 +737,7 @@ jobs:
665737
666738
ios-xcode-build:
667739
runs-on: macos-latest
740+
needs: determine-tag
668741

669742
strategy:
670743
matrix:
@@ -707,7 +780,25 @@ jobs:
707780
- name: Build swiftui example
708781
run: xcodebuild -project examples/whisper.swiftui/whisper.swiftui.xcodeproj -scheme WhisperCppDemo -configuration ${{ matrix.build }} -sdk iphoneos CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= -destination 'generic/platform=iOS' FRAMEWORK_FOLDER_PATH=./build-ios build
709782

783+
- name: Pack artifacts
784+
id: pack_artifacts
785+
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/master') ||
786+
github.event.inputs.create_release == 'true' ||
787+
github.event.inputs.pre_release_tag != '' }}
788+
run: |
789+
zip --symlinks -r whisper-${{ needs.determine-tag.outputs.tag_name }}-xcframework.zip build-apple/whisper.xcframework
790+
791+
- name: Upload artifacts
792+
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/master') ||
793+
github.event.inputs.create_release == 'true' ||
794+
github.event.inputs.pre_release_tag != '' }}
795+
uses: actions/upload-artifact@v4
796+
with:
797+
path: whisper-${{ needs.determine-tag.outputs.tag_name }}-xcframework.zip
798+
name: whisper-${{ needs.determine-tag.outputs.tag_name }}-xcframework
799+
710800
android:
801+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
711802
runs-on: ubuntu-22.04
712803

713804
steps:
@@ -807,6 +898,7 @@ jobs:
807898
# PGP_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
808899

809900
quantize:
901+
if: ${{ github.event_name == 'push' || github.event.inputs.run_type == 'full-ci' }}
810902
runs-on: ubuntu-22.04
811903

812904
steps:
@@ -819,3 +911,69 @@ jobs:
819911
cmake -B build
820912
cmake --build build --config Release
821913
./build/bin/quantize models/ggml-tiny.en.bin models/ggml-tiny.en-q4_0.bin q4_0
914+
915+
release:
916+
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/master') ||
917+
github.event.inputs.create_release == 'true' ||
918+
github.event.inputs.pre_release_tag != '' }}
919+
920+
runs-on: ubuntu-latest
921+
922+
needs:
923+
- determine-tag
924+
- ios-xcode-build
925+
926+
steps:
927+
- name: Clone
928+
id: checkout
929+
uses: actions/checkout@v4
930+
with:
931+
fetch-depth: 0
932+
933+
- name: ccache
934+
uses: hendrikmuhs/[email protected]
935+
with:
936+
key: release
937+
evict-old-files: 1d
938+
939+
# Downloads all the artifacts from the previous jobs
940+
- name: Download artifacts
941+
id: download-artifact
942+
uses: actions/download-artifact@v4
943+
with:
944+
path: ./artifact
945+
946+
- name: Move artifacts
947+
id: move_artifacts
948+
run: mkdir -p ./artifact/release && mv ./artifact/*/*.zip ./artifact/release
949+
950+
- name: Create release
951+
id: create_release
952+
uses: ggml-org/action-create-release@v1
953+
env:
954+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
955+
with:
956+
tag_name: ${{ needs.determine-tag.outputs.tag_name }}
957+
prerelease: ${{ github.event.inputs.pre_release_tag != '' }}
958+
959+
- name: Upload release
960+
id: upload_release
961+
uses: actions/github-script@v3
962+
with:
963+
github-token: ${{secrets.GITHUB_TOKEN}}
964+
script: |
965+
const path = require('path');
966+
const fs = require('fs');
967+
const release_id = '${{ steps.create_release.outputs.id }}';
968+
for (let file of await fs.readdirSync('./artifact/release')) {
969+
if (path.extname(file) === '.zip') {
970+
console.log('uploadReleaseAsset', file);
971+
await github.repos.uploadReleaseAsset({
972+
owner: context.repo.owner,
973+
repo: context.repo.repo,
974+
release_id: release_id,
975+
name: file,
976+
data: await fs.readFileSync(`./artifact/release/${file}`)
977+
});
978+
}
979+
}

0 commit comments

Comments
 (0)