|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + name: Build ${{ matrix.name }} |
| 11 | + runs-on: ${{ matrix.os }} |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + include: |
| 16 | + - name: macOS arm64 (Metal) |
| 17 | + os: macos-latest |
| 18 | + artifact: sam3-darwin-arm64 |
| 19 | + cmake_args: "-DBUILD_SHARED_LIBS=OFF" |
| 20 | + build_args: "" |
| 21 | + ext: tar.gz |
| 22 | + |
| 23 | + - name: macOS x86_64 |
| 24 | + os: macos-13 |
| 25 | + artifact: sam3-darwin-x86_64 |
| 26 | + cmake_args: "-DGGML_METAL=OFF -DSAM3_METAL=OFF -DBUILD_SHARED_LIBS=OFF" |
| 27 | + build_args: "" |
| 28 | + ext: tar.gz |
| 29 | + |
| 30 | + - name: Linux x86_64 |
| 31 | + os: ubuntu-latest |
| 32 | + artifact: sam3-linux-x86_64 |
| 33 | + cmake_args: "-DGGML_METAL=OFF -DSAM3_METAL=OFF -DBUILD_SHARED_LIBS=OFF" |
| 34 | + build_args: "" |
| 35 | + ext: tar.gz |
| 36 | + |
| 37 | + - name: Linux arm64 |
| 38 | + os: ubuntu-24.04-arm |
| 39 | + artifact: sam3-linux-arm64 |
| 40 | + cmake_args: "-DGGML_METAL=OFF -DSAM3_METAL=OFF -DBUILD_SHARED_LIBS=OFF" |
| 41 | + build_args: "" |
| 42 | + ext: tar.gz |
| 43 | + |
| 44 | + - name: Windows x86_64 |
| 45 | + os: windows-latest |
| 46 | + artifact: sam3-win-x86_64 |
| 47 | + cmake_args: "-DGGML_METAL=OFF -DSAM3_METAL=OFF -DBUILD_SHARED_LIBS=OFF -A x64" |
| 48 | + build_args: "--config Release" |
| 49 | + ext: zip |
| 50 | + |
| 51 | + steps: |
| 52 | + - name: Checkout |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + submodules: recursive |
| 56 | + |
| 57 | + - name: Install Ninja (Linux) |
| 58 | + if: runner.os == 'Linux' |
| 59 | + run: sudo apt-get update && sudo apt-get install -y ninja-build |
| 60 | + |
| 61 | + - name: Install Ninja (macOS) |
| 62 | + if: runner.os == 'macOS' |
| 63 | + run: brew install ninja |
| 64 | + |
| 65 | + - name: ccache |
| 66 | + uses: hendrikmuhs/ccache-action@v1 |
| 67 | + with: |
| 68 | + key: release-${{ matrix.artifact }} |
| 69 | + |
| 70 | + - name: Configure |
| 71 | + run: > |
| 72 | + cmake -B build |
| 73 | + ${{ runner.os != 'Windows' && '-G Ninja' || '' }} |
| 74 | + ${{ matrix.cmake_args }} |
| 75 | + ${{ runner.os != 'Windows' && '-DCMAKE_BUILD_TYPE=Release' || '' }} |
| 76 | + -DCMAKE_C_COMPILER_LAUNCHER=ccache |
| 77 | + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache |
| 78 | +
|
| 79 | + - name: Build |
| 80 | + run: cmake --build build ${{ matrix.build_args }} --parallel |
| 81 | + |
| 82 | + - name: Package (Unix) |
| 83 | + if: runner.os != 'Windows' |
| 84 | + run: | |
| 85 | + mkdir -p staging/${{ matrix.artifact }}/{lib,include,bin} |
| 86 | +
|
| 87 | + cp build/libsam3.a staging/${{ matrix.artifact }}/lib/ |
| 88 | + find build/ggml -name "*.a" -exec cp {} staging/${{ matrix.artifact }}/lib/ \; |
| 89 | +
|
| 90 | + cp sam3.h staging/${{ matrix.artifact }}/include/ |
| 91 | + cp -r ggml/include/* staging/${{ matrix.artifact }}/include/ |
| 92 | +
|
| 93 | + for bin in sam3_quantize sam3_benchmark sam3_profile_edgetam; do |
| 94 | + if [ -f "build/examples/${bin}" ]; then |
| 95 | + cp "build/examples/${bin}" staging/${{ matrix.artifact }}/bin/ |
| 96 | + fi |
| 97 | + done |
| 98 | +
|
| 99 | + cd staging |
| 100 | + tar czf ../${{ matrix.artifact }}.tar.gz ${{ matrix.artifact }} |
| 101 | +
|
| 102 | + - name: Package (Windows) |
| 103 | + if: runner.os == 'Windows' |
| 104 | + shell: pwsh |
| 105 | + run: | |
| 106 | + New-Item -ItemType Directory -Force -Path staging/${{ matrix.artifact }}/lib |
| 107 | + New-Item -ItemType Directory -Force -Path staging/${{ matrix.artifact }}/include |
| 108 | + New-Item -ItemType Directory -Force -Path staging/${{ matrix.artifact }}/bin |
| 109 | +
|
| 110 | + # Library (MSVC multi-config puts outputs in Release/) |
| 111 | + $libPaths = @("build/Release/sam3.lib", "build/sam3.lib") |
| 112 | + foreach ($p in $libPaths) { |
| 113 | + if (Test-Path $p) { Copy-Item $p staging/${{ matrix.artifact }}/lib/; break } |
| 114 | + } |
| 115 | +
|
| 116 | + # ggml static libs |
| 117 | + Get-ChildItem -Path build/ggml -Recurse -Filter "*.lib" | Copy-Item -Destination staging/${{ matrix.artifact }}/lib/ |
| 118 | +
|
| 119 | + # Headers |
| 120 | + Copy-Item sam3.h staging/${{ matrix.artifact }}/include/ |
| 121 | + Get-ChildItem -Path ggml/include -Filter "*.h" | Copy-Item -Destination staging/${{ matrix.artifact }}/include/ |
| 122 | +
|
| 123 | + # Example binaries |
| 124 | + foreach ($bin in @("sam3_quantize", "sam3_benchmark", "sam3_profile_edgetam")) { |
| 125 | + $paths = @("build/examples/Release/${bin}.exe", "build/examples/${bin}.exe") |
| 126 | + foreach ($p in $paths) { |
| 127 | + if (Test-Path $p) { Copy-Item $p staging/${{ matrix.artifact }}/bin/; break } |
| 128 | + } |
| 129 | + } |
| 130 | +
|
| 131 | + Compress-Archive -Path staging/${{ matrix.artifact }} -DestinationPath ${{ matrix.artifact }}.zip |
| 132 | +
|
| 133 | + - name: Upload artifact |
| 134 | + uses: actions/upload-artifact@v4 |
| 135 | + with: |
| 136 | + name: ${{ matrix.artifact }} |
| 137 | + path: ${{ matrix.artifact }}.${{ matrix.ext }} |
| 138 | + |
| 139 | + release: |
| 140 | + name: Create Release |
| 141 | + needs: build |
| 142 | + runs-on: ubuntu-latest |
| 143 | + permissions: |
| 144 | + contents: write |
| 145 | + |
| 146 | + steps: |
| 147 | + - name: Download all artifacts |
| 148 | + uses: actions/download-artifact@v4 |
| 149 | + with: |
| 150 | + path: artifacts |
| 151 | + |
| 152 | + - name: Create GitHub Release |
| 153 | + uses: softprops/action-gh-release@v2 |
| 154 | + with: |
| 155 | + tag_name: ${{ github.ref_name }} |
| 156 | + name: sam3.cpp ${{ github.ref_name }} |
| 157 | + draft: false |
| 158 | + prerelease: ${{ contains(github.ref_name, 'rc') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') }} |
| 159 | + generate_release_notes: true |
| 160 | + files: | |
| 161 | + artifacts/sam3-darwin-arm64/*.tar.gz |
| 162 | + artifacts/sam3-darwin-x86_64/*.tar.gz |
| 163 | + artifacts/sam3-linux-x86_64/*.tar.gz |
| 164 | + artifacts/sam3-linux-arm64/*.tar.gz |
| 165 | + artifacts/sam3-win-x86_64/*.zip |
0 commit comments