mirror of
https://github.com/mudler/LocalAI.git
synced 2026-03-31 21:25:59 -04:00
chore(ci): Scope tests extras backend tests (#9170)
Signed-off-by: Richard Palethorpe <io@richiejp.com>
This commit is contained in:
committed by
GitHub
parent
dd3376e0a9
commit
e0eb2fd734
@@ -10,40 +10,9 @@ const backendJobsDarwin = jobs["backend-jobs-darwin"];
|
||||
const includes = backendJobs.strategy.matrix.include;
|
||||
const includesDarwin = backendJobsDarwin.strategy.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")) {
|
||||
@@ -66,6 +35,65 @@ function inferBackendPathDarwin(item) {
|
||||
return `backend/${item.lang}/${item.backend}/`;
|
||||
}
|
||||
|
||||
// Build a deduplicated map of backend name -> path prefix from all matrix entries
|
||||
function getAllBackendPaths() {
|
||||
const paths = new Map();
|
||||
for (const item of includes) {
|
||||
const p = inferBackendPath(item);
|
||||
if (p && !paths.has(item.backend)) {
|
||||
paths.set(item.backend, p);
|
||||
}
|
||||
}
|
||||
for (const item of includesDarwin) {
|
||||
const p = inferBackendPathDarwin(item);
|
||||
if (p && !paths.has(item.backend)) {
|
||||
paths.set(item.backend, p);
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
const allBackendPaths = getAllBackendPaths();
|
||||
|
||||
// Non-PR events: output run-all=true and all backends as true
|
||||
if (!event.pull_request) {
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `run-all=true\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `has-backends=true\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `has-backends-darwin=true\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `matrix=${JSON.stringify({ include: includes })}\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `matrix-darwin=${JSON.stringify({ include: includesDarwin })}\n`);
|
||||
for (const backend of allBackendPaths.keys()) {
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `${backend}=true\n`);
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// PR context
|
||||
const prNumber = event.pull_request.number;
|
||||
const repo = event.repository.name;
|
||||
const owner = event.repository.owner.login;
|
||||
|
||||
const token = process.env.GITHUB_TOKEN;
|
||||
const octokit = new Octokit({ auth: token });
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const changedFiles = await getChangedFiles();
|
||||
|
||||
@@ -90,8 +118,15 @@ function inferBackendPathDarwin(item) {
|
||||
console.log("Has backends?:", hasBackends);
|
||||
console.log("Has Darwin backends?:", hasBackendsDarwin);
|
||||
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `run-all=false\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `has-backends=${hasBackends}\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `has-backends-darwin=${hasBackendsDarwin}\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `matrix=${JSON.stringify({ include: filtered })}\n`);
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `matrix-darwin=${JSON.stringify({ include: filteredDarwin })}\n`);
|
||||
|
||||
// Per-backend boolean outputs
|
||||
for (const [backend, pathPrefix] of allBackendPaths) {
|
||||
const changed = changedFiles.some(file => file.startsWith(pathPrefix));
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `${backend}=${changed ? 'true' : 'false'}\n`);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user