Skip to content

Commit fc6cbaa

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 fc6cbaa

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

.github/workflows/build.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,70 @@ 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+
custom_tag:
16+
description: 'Pre-release tag name'
17+
required: false
18+
type: string
919

1020
concurrency:
1121
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
1222
cancel-in-progress: true
1323

24+
permissions:
25+
contents: write # for creating release
26+
1427
env:
1528
ubuntu_image: "ubuntu:22.04"
1629
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
1730

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

@@ -665,6 +719,7 @@ jobs:
665719
666720
ios-xcode-build:
667721
runs-on: macos-latest
722+
needs: determine-tag
668723

669724
strategy:
670725
matrix:
@@ -707,6 +762,19 @@ jobs:
707762
- name: Build swiftui example
708763
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
709764

765+
- name: Pack artifacts
766+
id: pack_artifacts
767+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
768+
run: |
769+
zip --symlinks -r llama-${{ needs.determine-tag.outputs.tag_name }}-xcframework.zip build-apple/llama.xcframework
770+
771+
- name: Upload artifacts
772+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
773+
uses: actions/upload-artifact@v4
774+
with:
775+
path: llama-${{ needs.determine-tag.outputs.tag_name }}-xcframework.zip
776+
name: llama-${{ needs.determine-tag.outputs.tag_name }}-xcframework
777+
710778
android:
711779
runs-on: ubuntu-22.04
712780

@@ -819,3 +887,67 @@ jobs:
819887
cmake -B build
820888
cmake --build build --config Release
821889
./build/bin/quantize models/ggml-tiny.en.bin models/ggml-tiny.en-q4_0.bin q4_0
890+
891+
release:
892+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
893+
894+
runs-on: ubuntu-latest
895+
896+
needs:
897+
- determine-tag
898+
- ios-xcode-build
899+
900+
steps:
901+
- name: Clone
902+
id: checkout
903+
uses: actions/checkout@v4
904+
with:
905+
fetch-depth: 0
906+
907+
- name: ccache
908+
uses: hendrikmuhs/[email protected]
909+
with:
910+
key: release
911+
evict-old-files: 1d
912+
913+
# Downloads all the artifacts from the previous jobs
914+
- name: Download artifacts
915+
id: download-artifact
916+
uses: actions/download-artifact@v4
917+
with:
918+
path: ./artifact
919+
920+
- name: Move artifacts
921+
id: move_artifacts
922+
run: mkdir -p ./artifact/release && mv ./artifact/*/*.zip ./artifact/release
923+
924+
- name: Create release
925+
id: create_release
926+
uses: ggml-org/action-create-release@v1
927+
env:
928+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
929+
with:
930+
tag_name: ${{ needs.determine-tag.outputs.tag_name }}
931+
prerelease: ${{ github.event.inputs.custom_tag != '' }}
932+
933+
- name: Upload release
934+
id: upload_release
935+
uses: actions/github-script@v3
936+
with:
937+
github-token: ${{secrets.GITHUB_TOKEN}}
938+
script: |
939+
const path = require('path');
940+
const fs = require('fs');
941+
const release_id = '${{ steps.create_release.outputs.id }}';
942+
for (let file of await fs.readdirSync('./artifact/release')) {
943+
if (path.extname(file) === '.zip') {
944+
console.log('uploadReleaseAsset', file);
945+
await github.repos.uploadReleaseAsset({
946+
owner: context.repo.owner,
947+
repo: context.repo.repo,
948+
release_id: release_id,
949+
name: file,
950+
data: await fs.readFileSync(`./artifact/release/${file}`)
951+
});
952+
}
953+
}

0 commit comments

Comments
 (0)