|  | 
| 6 | 6 |       - master | 
| 7 | 7 |   pull_request: | 
| 8 | 8 |     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 | 
| 9 | 19 | 
 | 
| 10 | 20 | concurrency: | 
| 11 | 21 |   group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }} | 
| 12 | 22 |   cancel-in-progress: true | 
| 13 | 23 | 
 | 
|  | 24 | +permissions: | 
|  | 25 | +  contents: write  # for creating release | 
|  | 26 | + | 
| 14 | 27 | env: | 
| 15 | 28 |   ubuntu_image: "ubuntu:22.04" | 
| 16 | 29 |   VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" | 
| 17 | 30 | 
 | 
| 18 | 31 | 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 | +
 | 
| 19 | 73 |   ubuntu-22: | 
| 20 | 74 |     runs-on: ubuntu-22.04 | 
| 21 | 75 | 
 | 
| @@ -665,6 +719,7 @@ jobs: | 
| 665 | 719 | 
 | 
| 666 | 720 |   ios-xcode-build: | 
| 667 | 721 |     runs-on: macos-latest | 
|  | 722 | +    needs: determine-tag | 
| 668 | 723 | 
 | 
| 669 | 724 |     strategy: | 
| 670 | 725 |       matrix: | 
| @@ -707,6 +762,19 @@ jobs: | 
| 707 | 762 |       - name: Build swiftui example | 
| 708 | 763 |         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 | 
| 709 | 764 | 
 | 
|  | 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 | + | 
| 710 | 778 |   android: | 
| 711 | 779 |     runs-on: ubuntu-22.04 | 
| 712 | 780 | 
 | 
| @@ -819,3 +887,67 @@ jobs: | 
| 819 | 887 |           cmake -B build | 
| 820 | 888 |           cmake --build build --config Release | 
| 821 | 889 |           ./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