name: test on: pull_request: paths: - '**/*' - '!docs/**' - '!examples/**' - '!README.md' jobs: changes: runs-on: ubuntu-latest outputs: GENERATE_CUDA: ${{ steps.changes.outputs.GENERATE_CUDA }} GENERATE_ROCM: ${{ steps.changes.outputs.GENERATE_ROCM }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - id: changes run: | changed() { git diff-tree -r --no-commit-id --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} \ | xargs python3 -c "import sys; print(any([x.startswith('$1') for x in sys.argv[1:]]))" } { echo GENERATE=$(changed llm/) echo GENERATE_CUDA=$(changed llm/) echo GENERATE_ROCM=$(changed llm/) } >>$GITHUB_OUTPUT generate: needs: [changes] if: ${{ needs.changes.outputs.GENERATE == 'True' }} strategy: matrix: os: [ubuntu-latest, macos-latest, windows-2019] arch: [amd64, arm64] exclude: - os: ubuntu-latest arch: arm64 - os: windows-2019 arch: arm64 runs-on: ${{ matrix.os }} env: GOARCH: ${{ matrix.arch }} steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: '1.22' cache: true - run: go get ./... - run: | $gopath=(get-command go).source | split-path -parent & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1" cd $env:GITHUB_WORKSPACE $env:CMAKE_SYSTEM_VERSION="10.0.22621.0" $env:PATH="$gopath;$env:PATH" go generate -x ./... if: ${{ startsWith(matrix.os, 'windows-') }} name: "Windows Go Generate" - run: go generate -x ./... if: ${{ ! startsWith(matrix.os, 'windows-') }} name: "Unix Go Generate" - uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}-${{ matrix.arch }}-libraries path: llm/llama.cpp/build/**/lib/* generate-cuda: needs: [changes] if: ${{ needs.changes.outputs.GENERATE_CUDA == 'True' }} strategy: matrix: cuda-version: - '11.8.0' runs-on: linux container: nvidia/cuda:${{ matrix.cuda-version }}-devel-ubuntu20.04 steps: - run: | apt-get update && apt-get install -y git build-essential curl curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1-linux-x86_64.tar.gz \ | tar -zx -C /usr --strip-components 1 env: DEBIAN_FRONTEND: noninteractive - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: go-version: '1.22' cache: true - run: go get ./... - run: | git config --global --add safe.directory /__w/ollama/ollama go generate -x ./... env: OLLAMA_SKIP_CPU_GENERATE: '1' - uses: actions/upload-artifact@v4 with: name: cuda-${{ matrix.cuda-version }}-libraries path: llm/llama.cpp/build/**/lib/* generate-rocm: needs: [changes] if: ${{ needs.changes.outputs.GENERATE_ROCM == 'True' }} strategy: matrix: rocm-version: - '6.0.2' runs-on: linux container: rocm/dev-ubuntu-20.04:${{ matrix.rocm-version }} steps: - run: | apt-get update && apt-get install -y git build-essential curl rocm-libs curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1-linux-x86_64.tar.gz \ | tar -zx -C /usr --strip-components 1 env: DEBIAN_FRONTEND: noninteractive - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: go-version: '1.22' cache: true - run: go get ./... - run: | git config --global --add safe.directory /__w/ollama/ollama go generate -x ./... env: OLLAMA_SKIP_CPU_GENERATE: '1' - uses: actions/upload-artifact@v4 with: name: rocm-${{ matrix.rocm-version }}-libraries path: llm/llama.cpp/build/**/lib/* lint: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-2019] arch: [amd64, arm64] exclude: - os: ubuntu-latest arch: arm64 - os: windows-2019 arch: arm64 - os: macos-latest arch: amd64 runs-on: ${{ matrix.os }} env: GOARCH: ${{ matrix.arch }} CGO_ENABLED: '1' steps: - uses: actions/checkout@v4 with: submodules: recursive - uses: actions/setup-go@v5 with: go-version: '1.22' cache: false - run: | case ${{ matrix.arch }} in amd64) echo ARCH=x86_64 ;; arm64) echo ARCH=arm64 ;; esac >>$GITHUB_ENV shell: bash - run: | mkdir -p llm/llama.cpp/build/linux/$ARCH/stub/lib/ touch llm/llama.cpp/build/linux/$ARCH/stub/lib/stub.so if: ${{ startsWith(matrix.os, 'ubuntu-') }} - run: | mkdir -p llm/llama.cpp/build/darwin/$ARCH/stub/lib/ touch llm/llama.cpp/build/darwin/$ARCH/stub/lib/stub.dylib touch llm/llama.cpp/ggml-metal.metal if: ${{ startsWith(matrix.os, 'macos-') }} - run: | mkdir -p llm/llama.cpp/build/windows/$ARCH/stub/stub/lib/ touch llm/llama.cpp/build/windows/$ARCH/stub/stub/lib/stub.dll if: ${{ startsWith(matrix.os, 'windows-') }} - uses: golangci/golangci-lint-action@v3 test: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-2019] arch: [amd64] exclude: - os: ubuntu-latest arch: arm64 - os: windows-2019 arch: arm64 runs-on: ${{ matrix.os }} env: GOARCH: ${{ matrix.arch }} CGO_ENABLED: '1' steps: - uses: actions/checkout@v4 with: submodules: recursive - uses: actions/setup-go@v5 with: go-version: '1.22' cache: true - run: go get - run: | case ${{ matrix.arch }} in amd64) echo ARCH=x86_64 ;; arm64) echo ARCH=arm64 ;; esac >>$GITHUB_ENV shell: bash - run: | mkdir -p llm/llama.cpp/build/linux/$ARCH/stub/lib/ touch llm/llama.cpp/build/linux/$ARCH/stub/lib/stub.so if: ${{ startsWith(matrix.os, 'ubuntu-') }} - run: | mkdir -p llm/llama.cpp/build/darwin/$ARCH/stub/lib/ touch llm/llama.cpp/build/darwin/$ARCH/stub/lib/stub.dylib touch llm/llama.cpp/ggml-metal.metal if: ${{ startsWith(matrix.os, 'macos-') }} - run: | mkdir -p llm/llama.cpp/build/windows/$ARCH/stub/stub/lib/ touch llm/llama.cpp/build/windows/$ARCH/stub/stub/lib/stub.dll if: ${{ startsWith(matrix.os, 'windows-') }} - run: go build - run: go test -v ./... - uses: actions/upload-artifact@v4 with: name: ${{ matrix.os }}-binaries path: ollama