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
12 changes: 7 additions & 5 deletions .github/workflows/backend_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ on:
type: string
secrets:
dockerUsername:
required: true
required: false
dockerPassword:
required: true
required: false
quayUsername:
required: true
quayPassword:
Expand All @@ -66,6 +66,8 @@ on:
jobs:
backend-build:
runs-on: ${{ inputs.runs-on }}
env:
quay_username: ${{ secrets.quayUsername }}
steps:


Expand Down Expand Up @@ -187,7 +189,7 @@ jobs:
password: ${{ secrets.dockerPassword }}

- name: Login to Quay.io
# if: github.event_name != 'pull_request'
if: ${{ env.quay_username != '' }}
uses: docker/login-action@v3
with:
registry: quay.io
Expand Down Expand Up @@ -230,12 +232,12 @@ jobs:
file: ${{ inputs.dockerfile }}
cache-from: type=gha
platforms: ${{ inputs.platforms }}
push: true
push: ${{ env.quay_username != '' }}
tags: ${{ steps.meta_pull_request.outputs.tags }}
labels: ${{ steps.meta_pull_request.outputs.labels }}



- name: job summary
run: |
echo "Built image: ${{ steps.meta.outputs.labels }}" >> $GITHUB_STEP_SUMMARY
echo "Built image: ${{ steps.meta.outputs.labels }}" >> $GITHUB_STEP_SUMMARY
58 changes: 58 additions & 0 deletions .github/workflows/backend_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 'build backend container images (PR-filtered)'

on:
pull_request:

concurrency:
group: ci-backends-pr-${{ github.head_ref || github.ref }}-${{ github.repository }}
cancel-in-progress: true

jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has-backends: ${{ steps.set-matrix.outputs.has-backends }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: |
bun add js-yaml
bun add @octokit/core

# filters the matrix in backend.yml
- name: Filter matrix for changed backends
id: set-matrix
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_EVENT_PATH: ${{ github.event_path }}
run: bun run scripts/changed-backends.js

backend-jobs:
needs: generate-matrix
uses: ./.github/workflows/backend_build.yml
if: needs.generate-matrix.outputs.has-backends == 'true'
with:
tag-latest: ${{ matrix.tag-latest }}
tag-suffix: ${{ matrix.tag-suffix }}
build-type: ${{ matrix.build-type }}
cuda-major-version: ${{ matrix.cuda-major-version }}
cuda-minor-version: ${{ matrix.cuda-minor-version }}
platforms: ${{ matrix.platforms }}
runs-on: ${{ matrix.runs-on }}
base-image: ${{ matrix.base-image }}
backend: ${{ matrix.backend }}
dockerfile: ${{ matrix.dockerfile }}
skip-drivers: ${{ matrix.skip-drivers }}
context: ${{ matrix.context }}
secrets:
quayUsername: ${{ secrets.LOCALAI_REGISTRY_USERNAME }}
quayPassword: ${{ secrets.LOCALAI_REGISTRY_PASSWORD }}
strategy:
fail-fast: true
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
1 change: 0 additions & 1 deletion backend/go/stablediffusion-ggml/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package main

// Note: this is started internally by LocalAI and a server is allocated for each model
import (
"flag"

Expand Down
79 changes: 79 additions & 0 deletions scripts/changed-backends.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import fs from "fs";
import yaml from "js-yaml";
import { Octokit } from "@octokit/core";

// Load backend.yml and parse matrix.include
const backendYml = yaml.load(fs.readFileSync(".github/workflows/backend.yml", "utf8"));
const jobs = backendYml.jobs;
const backendJob = jobs["backend-jobs"];
const strategy = backendJob.strategy;
const matrix = strategy.matrix;
const includes = matrix.include;

// Set up Octokit for PR changed files
const token = process.env.GITHUB_TOKEN;
const octokit = new Octokit({ auth: token });

const eventPath = process.env.GITHUB_EVENT_PATH;
const event = JSON.parse(fs.readFileSync(eventPath, "utf8"));

let prNumber, repo, owner;
if (event.pull_request) {
prNumber = event.pull_request.number;
repo = event.repository.name;
owner = event.repository.owner.login;
} else {
throw new Error("This workflow must be triggered by a pull_request event.");
}

async function getChangedFiles() {
let files = [];
let page = 1;
while (true) {
const res = await octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}/files', {
owner,
repo,
pull_number: prNumber,
per_page: 100,
page
});
files = files.concat(res.data.map(f => f.filename));
if (res.data.length < 100) break;
page++;
}
return files;
}

// Infer backend path
function inferBackendPath(item) {
if (item.dockerfile.endsWith("python")) {
return `backend/python/${item.backend}`;
}
if (item.dockerfile.endsWith("golang")) {
return `backend/go/${item.backend}`;
}
if (item.dockerfile.endsWith("llama-cpp")) {
return `backend/cpp/llama-cpp`;
}
return null;
}

(async () => {
const changedFiles = await getChangedFiles();

console.log("Changed files:", changedFiles);

const filtered = includes.filter(item => {
const backendPath = inferBackendPath(item);
if (!backendPath) return false;
return changedFiles.some(file => file.startsWith(backendPath));
});

console.log("Filtered files:", filtered);

const hasBackends = filtered.length > 0 ? 'true' : 'false';
console.log("Has backends?:", hasBackends);

fs.appendFileSync(process.env.GITHUB_OUTPUT, `has-backends=${hasBackends}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `matrix=${JSON.stringify({ include: filtered })}\n`);
})();
Loading