From e8061840235bb953d621796b7d65e86541dbc0a1 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Fri, 31 Jan 2025 16:19:41 -0800 Subject: [PATCH] fix release workflow --- .github/workflows/release.yaml | 57 +++++++++++++++++----------------- macapp/forge.config.ts | 2 +- scripts/build_darwin.sh | 30 +++++++++--------- scripts/build_windows.ps1 | 11 +++++-- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e9d8f7218..e9221bdfd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -81,7 +81,7 @@ jobs: path: dist/darwin-arm64 - run: | export VERSION=${GITHUB_REF_NAME#v} - ./scripts/build_darwin.sh macapp sign + ./scripts/build_darwin.sh sign macapp env: APPLE_IDENTITY: ${{ secrets.APPLE_IDENTITY }} APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }} @@ -197,33 +197,38 @@ jobs: env: GOFLAGS: ${{ needs.setup-environment.outputs.GOFLAGS }} steps: - - name: Install system dependencies + - name: Install AMD64 system dependencies + if: matrix.arch == 'amd64' run: | $ErrorActionPreference = "Stop" - if ("${{ matrix.arch }}" -eq 'amd64') { - Start-Process "C:\msys64\usr\bin\pacman.exe" -ArgumentList @("-S", "--noconfirm", "mingw-w64-clang-x86_64-gcc-compat", "mingw-w64-clang-x86_64-clang") -NoNewWindow -Wait - echo "C:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - } elseif ("${{ matrix.arch }}" -eq 'arm64') { - Set-ExecutionPolicy Bypass -Scope Process -Force - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 - iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) - echo "C:\ProgramData\chocolatey\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + Start-Process "C:\msys64\usr\bin\pacman.exe" -ArgumentList @("-S", "--noconfirm", "mingw-w64-clang-x86_64-gcc-compat", "mingw-w64-clang-x86_64-clang") -NoNewWindow -Wait + echo "C:\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "C:\msys64\clang64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: Install ARM64 system dependencies + if: matrix.arch == 'arm64' + run: | + $ErrorActionPreference = "Stop" + Set-ExecutionPolicy Bypass -Scope Process -Force + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 + iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + echo "C:\ProgramData\chocolatey\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - choco install -y --no-progress git gzip - echo "C:\Program Files\Git\cmd" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + choco install -y --no-progress git gzip + echo "C:\Program Files\Git\cmd" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - Invoke-WebRequest -Uri "https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-ucrt-aarch64.zip" -OutFile "${{ runner.temp }}\llvm-mingw-ucrt-aarch64.zip" - Expand-Archive -Path ${{ runner.temp }}\llvm-mingw-ucrt-aarch64.zip -DestinationPath "C:\Program Files\" - $installPath=(Resolve-Path -Path "C:\Program Files\llvm-mingw-*-ucrt-aarch64").path - echo $installPath\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - } + Invoke-WebRequest -Uri "https://github.com/mstorsjo/llvm-mingw/releases/download/20240619/llvm-mingw-20240619-ucrt-aarch64.zip" -OutFile "${{ runner.temp }}\llvm-mingw-ucrt-aarch64.zip" + Expand-Archive -Path ${{ runner.temp }}\llvm-mingw-ucrt-aarch64.zip -DestinationPath "C:\Program Files\" + $installPath=(Resolve-Path -Path "C:\Program Files\llvm-mingw-*-ucrt-aarch64").path + echo $installPath\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version-file: go.mod - run: | go build -o dist/${{ matrix.os }}-${{ matrix.arch }}/ . + - if: matrix.arch == 'arm64' + run: | + Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vc_redist.arm64.exe" -OutFile "dist\windows-arm64\vc_redist.arm64.exe" - run: | $env:VERSION='${{ github.ref_name }}' -Replace "v(.*)", '$1' & .\scripts\build_windows.ps1 buildApp @@ -258,12 +263,12 @@ jobs: echo "${{ vars.OLLAMA_CERT }}" >ollama_inc.crt - uses: actions/download-artifact@v4 with: - name: build-windows-* + pattern: build-windows-* path: dist\ merge-multiple: true - uses: actions/download-artifact@v4 with: - name: depends-windows-amd64-* + pattern: depends-windows-amd64-* path: dist\windows-amd64\ merge-multiple: true - run: | @@ -294,8 +299,8 @@ jobs: - uses: actions/checkout@v4 - uses: docker/setup-buildx-action@v3 - run: | - apt-get update && apt-get install pigz - for TARGET in ${{ matrix.targets }}; do docker buildx build --platform $PLATFORM --target $TARGET --build-arg GOFLAGS --build-arg CGO_CFLAGS --build-args CGO_CXXFLAGS --output type=local,dest=dist/$PLATFORM .; done + sudo apt-get update && sudo apt-get install pigz + for TARGET in ${{ matrix.targets }}; do docker buildx build --platform $PLATFORM --target $TARGET --build-arg GOFLAGS --build-arg CGO_CFLAGS --build-arg CGO_CXXFLAGS --output type=local,dest=dist/$PLATFORM .; done tar c -C dist/$PLATFORM . | pigz -9cv >dist/ollama-${PLATFORM//\//-}.tgz env: PLATFORM: ${{ matrix.os }}/${{ matrix.arch }} @@ -371,20 +376,16 @@ jobs: run: | - uses: actions/download-artifact@v4 with: + name: dist-darwin path: dist - pattern: dist-darwin - uses: actions/download-artifact@v4 with: + name: dist-windows path: dist - pattern: dist-windows - uses: actions/download-artifact@v4 with: - path: dist pattern: dist-linux-* - - uses: actions/download-artifact@v4 - with: path: dist - pattern: dist-windows - run: | ls -lh dist/ (cd dist; find . -type f | xargs sha256sum > ../sha256sum.txt) diff --git a/macapp/forge.config.ts b/macapp/forge.config.ts index d347eed41..540fc0a00 100644 --- a/macapp/forge.config.ts +++ b/macapp/forge.config.ts @@ -19,7 +19,7 @@ const config: ForgeConfig = { icon: './assets/icon.icns', extraResource: [ path.join(__dirname, '../dist/darwin/ollama'), - ...fs.readdirSync(path.join(__dirname, '../dist/darwin/amd64')).map(f => path.join(__dirname, '../dist/darwin/amd64', f)), + ...fs.readdirSync(path.join(__dirname, '../dist/darwin-amd64/lib/ollama')).map(f => path.join(__dirname, '../dist/darwin-amd64/lib/ollama', f)), path.join(__dirname, './assets/iconTemplate.png'), path.join(__dirname, './assets/iconTemplate@2x.png'), path.join(__dirname, './assets/iconUpdateTemplate.png'), diff --git a/scripts/build_darwin.sh b/scripts/build_darwin.sh index 7e586f5ff..1f1442f34 100755 --- a/scripts/build_darwin.sh +++ b/scripts/build_darwin.sh @@ -41,26 +41,24 @@ _build_darwin() { _sign_darwin() { status "Creating universal binary..." - lipo -create -output dist/darwin/ollama dist/darwin/*/ollama + mkdir -p dist/darwin + lipo -create -output dist/darwin/ollama dist/darwin-*/ollama - if [ -z "$APPLE_IDENTITY" ]; then - status "No APPLE_IDENTITY set, skipping code signing" - return + if [ -n "$APPLE_IDENTITY" ]; then + for F in dist/darwin/ollama dist/darwin-amd64/lib/ollama/*; do + codesign -f --timestamp -s "$APPLE_IDENTITY" --identifier ai.ollama.ollama --options=runtime $F + done + + # create a temporary zip for notarization + TEMP=$(mktemp -u).zip + ditto -c -k --keepParent dist/darwin/ollama "$TEMP" + xcrun notarytool submit dist/darwin/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID + rm -f "$TEMP" fi - for F in dist/darwin/ollama dist/darwin/amd64/lib*; do - codesign -f --timestamp -s "$APPLE_IDENTITY" --identifier ai.ollama.ollama --options=runtime $F - done - - # create a temporary zip for notarization - TEMP=$(mktemp -u).zip - ditto -c -k --keepParent dist/darwin/ollama "$TEMP" - xcrun notarytool submit dist/darwin/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID - rm -f "$TEMP" - - # create a universal tarball + status "Creating universal tarball..." tar -cf dist/ollama-darwin.tar --strip-components 2 dist/darwin/ollama - tar -rf dist/ollama-darwin.tar --strip-components 3 dist/darwin/amd64/lib* + tar -rf dist/ollama-darwin.tar --strip-components 4 dist/darwin-amd64/lib/ gzip -9vc dist/ollama-darwin.tgz } diff --git a/scripts/build_windows.ps1 b/scripts/build_windows.ps1 index 30cf98276..b0c7e32f2 100644 --- a/scripts/build_windows.ps1 +++ b/scripts/build_windows.ps1 @@ -208,8 +208,15 @@ function buildInstaller() { } function distZip() { - write-host "Generating stand-alone distribution zip file ${script:SRC_DIR}\dist\ollama-windows-${script:TARGET_ARCH}.zip" - Compress-Archive -Path "${script:SRC_DIR}\dist\windows-${script:TARGET_ARCH}\*" -DestinationPath "${script:SRC_DIR}\dist\ollama-windows-${script:TARGET_ARCH}.zip" -Force + if (Test-Path -Path "${script:SRC_DIR}\dist\windows-amd64") { + write-host "Generating stand-alone distribution zip file ${script:SRC_DIR}\dist\ollama-windows-amd64.zip" + Compress-Archive -Path "${script:SRC_DIR}\dist\windows-amd64\*" -DestinationPath "${script:SRC_DIR}\dist\ollama-windows-amd64.zip" -Force + } + + if (Test-Path -Path "${script:SRC_DIR}\dist\windows-arm64") { + write-host "Generating stand-alone distribution zip file ${script:SRC_DIR}\dist\ollama-windows-arm64.zip" + Compress-Archive -Path "${script:SRC_DIR}\dist\windows-arm64\*" -DestinationPath "${script:SRC_DIR}\dist\ollama-windows-arm64.zip" -Force + } } checkEnv