ci: update search with github actions

This commit is contained in:
iCrawl
2023-11-07 16:11:25 +01:00
parent 009c0a3bae
commit 792840bae6
8 changed files with 172 additions and 99 deletions

View File

@@ -42,7 +42,9 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/glob": "^0.4.0",
"@discordjs/scripts": "workspace:^",
"@planetscale/database": "^1.11.0",
"meilisearch": "^0.35.0",
"tslib": "^2.6.2",
"undici": "5.27.2"
},

View File

@@ -0,0 +1,5 @@
name: 'Upload search indicies'
description: 'Uploads the search indicies to a meilisearch database'
runs:
using: node16
main: ../../dist/uploadSearchIndicies/index.js

View File

@@ -0,0 +1,64 @@
import process from 'node:process';
import { setFailed } from '@actions/core';
import { generateAllIndices } from '@discordjs/scripts';
import { connect } from '@planetscale/database';
import MeiliSearch from 'meilisearch';
import { fetch } from 'undici';
if (!process.env.DATABASE_URL) {
setFailed('DATABASE_URL is not set');
}
if (!process.env.SEARCH_API) {
setFailed('SEARCH_API is not set');
}
if (!process.env.SEARCH_API_KEY) {
setFailed('SEARCH_API_KEY is not set');
}
const sql = connect({
fetch,
url: process.env.DATABASE_URL!,
});
const client = new MeiliSearch({
host: process.env.SEARCH_API!,
apiKey: process.env.SEARCH_API_KEY!,
});
try {
console.log('Generating all indices...');
const indicies = await generateAllIndices({
fetchPackageVersions: async (pkg) => {
console.log(`Fetching versions for ${pkg}...`);
const { rows } = await sql.execute('select version from documentation where name = ?', [pkg]);
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows.map((row) => row.version);
},
fetchPackageVersionDocs: async (pkg, version) => {
console.log(`Fetching data for ${pkg} ${version}...`);
const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
pkg,
version,
]);
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows[0].data;
},
writeToFile: false,
});
console.log('Generated all indices.');
console.log('Uploading indices...');
for (const index of indicies) {
console.log(`Uploading ${index.index}...`);
await client.index(index.index).addDocuments([index]);
}
console.log('Uploaded all indices.');
} catch (error) {
const err = error as Error;
setFailed(err.message);
}