Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/publish-ollama.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: publish-ollama
# Every change to main that touches a Modelfile or an Ollama page is published on ollama.com:
# the changed models are rebuilt and pushed as Tromset/<name>, then the pages are updated from docs/ollama/.
# Needs two repository secrets (Settings > Secrets and variables > Actions):
# OLLAMA_KEY the private key ~/.ollama/id_ed25519 of a machine linked to the Tromset account (`ollama signin`)
# OLLAMA_API_KEY an API key from https://ollama.com/settings/keys
on:
push:
branches: [main]
paths:
- 'Modelfile*'
- 'docs/ollama/**'
- 'scripts/publish.sh'
- 'scripts/update-ollama-pages.sh'
- '.github/workflows/publish-ollama.yml'
workflow_dispatch:
inputs:
models:
description: 'Models to publish (space-separated names, "all", or "none" for pages only)'
default: all
concurrency:
group: publish-ollama
cancel-in-progress: false
jobs:
publish:
if: github.repository == 'Tromset/flycoder'
runs-on: ubuntu-latest
timeout-minutes: 120
env:
OLLAMA_KEY: ${{ secrets.OLLAMA_KEY }}
OLLAMA_API_KEY: ${{ secrets.OLLAMA_API_KEY }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Pick the models to publish
id: pick
env:
BEFORE: ${{ github.event.before }}
REQUESTED: ${{ inputs.models }}
run: |
if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then
models=$REQUESTED
elif ! changed=$(git diff --name-only "$BEFORE" "$GITHUB_SHA" 2>/dev/null); then
models=all
else
models=
for file in $changed; do
case $file in
Modelfile) models="$models flycoder0.3" ;;
Modelfile.fast) models="$models flycoder0.3fast" ;;
Modelfile.pro) models="$models flycoder0.3pro" ;;
Modelfile.lite) models="$models flycoder0.3:lite" ;;
Modelfile.router) models="$models flycoder0.3:router" ;;
scripts/publish.sh|.github/workflows/publish-ollama.yml) models=all; break ;;
esac
done
fi
[ -n "$models" ] || models=none
echo "Models to publish: $models"
echo "models=$models" >> "$GITHUB_OUTPUT"

- name: Check the secrets
run: |
[ -n "$OLLAMA_KEY" ] || { echo "::error::Add the OLLAMA_KEY secret (contents of ~/.ollama/id_ed25519 from a machine signed in to the Tromset account)."; exit 1; }
[ -n "$OLLAMA_API_KEY" ] || echo "::warning::OLLAMA_API_KEY is not set: the model pages will not be updated."

- name: Free disk space for the base models
if: steps.pick.outputs.models != 'none'
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force >/dev/null
df -h /

- name: Start Ollama with the Tromset key
if: steps.pick.outputs.models != 'none'
run: |
curl -fsSL https://ollama.com/install.sh | sh
sudo systemctl disable --now ollama || true
# Pushes are signed by the server with ~/.ollama/id_ed25519: run it as this user.
mkdir -p ~/.ollama && chmod 700 ~/.ollama
printf '%s\n' "$OLLAMA_KEY" > ~/.ollama/id_ed25519 && chmod 600 ~/.ollama/id_ed25519
ssh-keygen -y -f ~/.ollama/id_ed25519 > ~/.ollama/id_ed25519.pub
nohup ollama serve > "$RUNNER_TEMP/ollama.log" 2>&1 &
for _ in $(seq 30); do ollama list >/dev/null 2>&1 && break; sleep 1; done
ollama --version

- name: Build and push the models
if: steps.pick.outputs.models != 'none'
env:
FLYCODER_PRUNE: '1'
MODELS: ${{ steps.pick.outputs.models }}
run: |
# MODELS is a space-separated list of names: split it on purpose.
# shellcheck disable=SC2086
if [ "$MODELS" = all ]; then sh scripts/publish.sh Tromset; else sh scripts/publish.sh Tromset $MODELS; fi

- name: Update the model pages
if: env.OLLAMA_API_KEY != ''
run: |
if sh scripts/update-ollama-pages.sh Tromset; then
echo "Model pages updated from docs/ollama/." >> "$GITHUB_STEP_SUMMARY"
else
echo "::warning::Some ollama.com pages were not updated (see the log). Paste docs/ollama/<model>.md into the page by hand."
echo "Some ollama.com pages were not updated: paste docs/ollama/<model>.md by hand." >> "$GITHUB_STEP_SUMMARY"
fi

- name: Remove the key
if: always()
run: rm -f ~/.ollama/id_ed25519 ~/.ollama/id_ed25519.pub
Loading
Loading