LiteRT-LM / .github /workflows /ci-build-win.yml
SeaWolf-AI's picture
Upload full LiteRT-LM codebase
5f923cd verified
name: "CI-Win"
on:
push:
tags:
- v*.*.*
pull_request:
branches:
- main
schedule:
- cron: "0 10 * * *" # Run at 2am PST (10am UTC) every day to refresh the cache.
workflow_dispatch: # Manual trigger
inputs:
REFRESH_CACHE:
description: 'Refresh cache to remove unused files'
type: boolean
default: true
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
presubmit:
name: "Presubmit-Win"
runs-on: Windows_x64
defaults:
run:
shell: pwsh
permissions:
actions: write # For gh cache delete.
contents: write # For gh release upload.
env:
MODEL_KEY: gemma-3-1b-it-v1
MODEL_PATH: .\models\gemma3-1b-it-int4.litertlm
MODEL_URL: https://huggingface.co/litert-community/Gemma3-1B-IT/resolve/main/gemma3-1b-it-int4.litertlm
# Clear ANDROID_NDK_HOME as Windows_x64 has NDK where jobs don't have permission for
# androidndk rulesto create symlinks.
ANDROID_NDK_HOME:
GH_TOKEN: ${{ github.token }} # For gh release upload.
REFRESH_CACHE: ${{ github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && inputs.REFRESH_CACHE) }}
steps:
- name: Checkout code.
uses: actions/checkout@v4
with:
lfs: true
- name : Set up cache keys and bazel output base.
id: cache-keys
run: |
$CACHE_RESTORE_KEY_2="${{ github.workflow }}"
$CACHE_RESTORE_KEY_1="$CACHE_RESTORE_KEY_2-${{ hashFiles('**/WORKSPACE', '**/.bazelrc') }}"
$CACHE_RESTORE_KEY_0="$CACHE_RESTORE_KEY_1-${{ hashFiles('**/BUILD*') }}"
# If it's not a pull request, then it will be the same as $CACHE_RESTORE_KEY_1-.
$CACHE_RESTORE_KEY_HEAD="$CACHE_RESTORE_KEY_0-${{ github.event.pull_request.base.sha }}"
$CACHE_KEY="$CACHE_RESTORE_KEY_0-${{ github.sha }}"
echo "CACHE_RESTORE_KEY_2=$CACHE_RESTORE_KEY_2" >> "$env:GITHUB_OUTPUT"
echo "CACHE_RESTORE_KEY_1=$CACHE_RESTORE_KEY_1" >> "$env:GITHUB_OUTPUT"
echo "CACHE_RESTORE_KEY_0=$CACHE_RESTORE_KEY_0" >> "$env:GITHUB_OUTPUT"
echo "CACHE_RESTORE_KEY_HEAD=$CACHE_RESTORE_KEY_HEAD" >> "$env:GITHUB_OUTPUT"
echo "CACHE_KEY=$CACHE_KEY" >> "$env:GITHUB_OUTPUT"
# D: is faster than C: for I/O.
$SHORT_SHA=$("${{ github.sha }}".SubString(0, 8))
echo "BAZEL_OUTPUT_BASE=D:/w-$SHORT_SHA" >> "$env:GITHUB_ENV"
- name: Clean build outputs if cache is being refreshed.
if: env.REFRESH_CACHE == 'true'
run: bazel --output_base="$env:BAZEL_OUTPUT_BASE" clean --expunge
- name: Restore bazel cache if cache is not being refreshed.
id: bazel-cache
if: env.REFRESH_CACHE != 'true'
uses: actions/cache/restore@v4
with:
path: |
~/.cache/bazel-windows
~/.cache/bazel-windows-dll
key: ${{ steps.cache-keys.outputs.CACHE_KEY }}
restore-keys: |
${{ steps.cache-keys.outputs.CACHE_RESTORE_KEY_HEAD }}
${{ steps.cache-keys.outputs.CACHE_RESTORE_KEY_0 }}-
${{ steps.cache-keys.outputs.CACHE_RESTORE_KEY_1 }}-
${{ steps.cache-keys.outputs.CACHE_RESTORE_KEY_2 }}-
- name: Check cache hit.
run: |
echo "Cache Hit: ${{ steps.bazel-cache.outputs.cache-hit }}"
echo "Cache Primary Key: ${{ steps.bazel-cache.outputs.cache-primary-key }}"
echo "Cache Matched Key: ${{ steps.bazel-cache.outputs.cache-matched-key }}"
- name: Download Model
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
if (-not (Test-Path "./models")) {
New-Item -ItemType Directory -Path "./models" -Force
}
$headers = @{
"Authorization" = "Bearer $($env:HF_TOKEN)"
}
Write-Host "Downloading model from Hugging Face: ${{ env.MODEL_URL }}"
Invoke-WebRequest -Uri "${{ env.MODEL_URL }}" `
-Headers $headers `
-OutFile "${{ env.MODEL_PATH }}" `
-MaximumRetryCount 5
$file = Get-Item "${{ env.MODEL_PATH }}"
$sizeMB = [math]::Round($file.Length / 1MB, 2)
Write-Host "Verification Success: $($file.Name) ($sizeMB MB) is ready."
Get-ChildItem "${{ env.MODEL_PATH }}" | Select-Object Name, @{Name="Size(MB)";Expression={$_.Length / 1MB}}
- name: Run bazel build on Windows.
run: |
bazel --output_base="$env:BAZEL_OUTPUT_BASE" `
build --disk_cache=~/.cache/bazel-windows `
--build_tag_filters='-nowindows' `
//... `
//runtime/engine:litert_lm_main
- name: Update litert_lm_main prebuilt for Windows if new version tag is pushed.
if: github.ref_type == 'tag'
run: |
cp bazel-bin/runtime/engine/litert_lm_main.exe litert_lm_main.windows_x86_64.exe
gh release upload ${{ github.ref_name }} litert_lm_main.windows_x86_64.exe --clobber
- name: Run bazel test on Windows.
run: |
bazel --output_base="$env:BAZEL_OUTPUT_BASE" `
test --disk_cache=~/.cache/bazel-windows --test_output=errors `
--test_tag_filters='-requires-mac-inputs:hard,-nowindows' //...
- name: Install pytest
run: python3 -m pip install --break-system-packages pytest==8.3.4
- name: Run pytest
run: pytest tools/test/ --model-path=${{ env.MODEL_PATH }} --build-system=bazel
- name: Run bazel build on Windows with dynamic linking.
run: |
bazel --output_base="$env:BAZEL_OUTPUT_BASE" `
build --disk_cache=~/.cache/bazel-windows-dll `
--define=litert_link_capi_so=true `
--define=resolve_symbols_in_exec=false `
//runtime/engine:litert_lm_main
- name: Remove cache if cache is being refreshed.
if: env.REFRESH_CACHE == 'true'
continue-on-error: true # Ignore errors when cache is not found.
run: gh cache delete ${{ steps.cache-keys.outputs.CACHE_KEY }}
- name: Save bazel cache if it's new or being refreshed.
uses: actions/cache/save@v4
if: env.REFRESH_CACHE == 'true' || steps.bazel-cache.outputs.cache-hit != 'true'
with:
path: |
~/.cache/bazel-windows
~/.cache/bazel-windows-dll
key: ${{ steps.cache-keys.outputs.CACHE_KEY }}