mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
ci: update search with github actions
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
5
packages/actions/src/uploadSearchIndicies/action.yml
Normal file
5
packages/actions/src/uploadSearchIndicies/action.yml
Normal 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
|
||||
64
packages/actions/src/uploadSearchIndicies/index.ts
Normal file
64
packages/actions/src/uploadSearchIndicies/index.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user