diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index ee7860806..042b80d5c 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -277,7 +277,9 @@ jobs: - name: Upload search indices to meilisearch env: - DATABASE_URL: ${{ secrets.DATABASE_URL }} + CF_D1_DOCS_API_KEY: ${{ secrets.CF_D1_DOCS_API_KEY }} + CF_D1_DOCS_ID: ${{ secrets.CF_D1_DOCS_ID }} + CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }} SEARCH_API_KEY: ${{ secrets.SEARCH_API_KEY }} uses: ./packages/actions/src/uploadSearchIndices diff --git a/packages/actions/package.json b/packages/actions/package.json index 7a8940513..c23744d6c 100644 --- a/packages/actions/package.json +++ b/packages/actions/package.json @@ -46,8 +46,6 @@ "@actions/glob": "^0.5.0", "@aws-sdk/client-s3": "^3.901.0", "@discordjs/scripts": "workspace:^", - "@vercel/blob": "^2.0.0", - "@vercel/postgres": "^0.10.0", "cloudflare": "^5.2.0", "commander": "^14.0.1", "meilisearch": "^0.38.0", diff --git a/packages/actions/src/uploadSearchIndices/index.ts b/packages/actions/src/uploadSearchIndices/index.ts index 32096740c..ac450481d 100644 --- a/packages/actions/src/uploadSearchIndices/index.ts +++ b/packages/actions/src/uploadSearchIndices/index.ts @@ -1,13 +1,13 @@ import process from 'node:process'; import { setFailed } from '@actions/core'; import { generateAllIndices } from '@discordjs/scripts'; -import { createPool } from '@vercel/postgres'; +import Cloudflare from 'cloudflare'; import { MeiliSearch } from 'meilisearch'; import pLimit from 'p-limit'; import { fetch } from 'undici'; -if (!process.env.DATABASE_URL) { - setFailed('DATABASE_URL is not set'); +if (!(process.env.CF_D1_DOCS_API_KEY && process.env.CF_D1_DOCS_ID && process.env.CF_ACCOUNT_ID)) { + setFailed('Missing Cloudflare D1 environment variables.'); } if (!process.env.SEARCH_API_URL) { @@ -18,8 +18,8 @@ if (!process.env.SEARCH_API_KEY) { setFailed('SEARCH_API_KEY is not set'); } -const pool = createPool({ - connectionString: process.env.DATABASE_URL, +const cf = new Cloudflare({ + apiToken: process.env.CF_D1_DOCS_API_KEY!, }); const client = new MeiliSearch({ @@ -34,16 +34,26 @@ try { console.log('Generating all indices...'); const indices = await generateAllIndices({ fetchPackageVersions: async (pkg) => { - console.log(`Fetching versions for ${pkg}...`); - const { rows } = await pool.sql`select version from documentation where name = ${pkg}`; + console.info(`Fetching versions for ${pkg}...`); - return rows.map((row) => row.version); + const { result } = await cf.d1.database.query(process.env.CF_D1_DOCS_ID!, { + account_id: process.env.CF_ACCOUNT_ID!, + sql: `select version from documentation where name = ? order by version desc;`, + params: [pkg], + }); + + return ((result[0]?.results as { version: string }[] | undefined) ?? []).map((row) => row.version); }, fetchPackageVersionDocs: async (pkg, version) => { console.log(`Fetching data for ${pkg} ${version}...`); - const { rows } = await pool.sql`select url from documentation where name = ${pkg} and version = ${version}`; - const res = await fetch(rows[0]?.url ?? ''); + const { result } = await cf.d1.database.query(process.env.CF_D1_DOCS_ID!, { + account_id: process.env.CF_ACCOUNT_ID!, + sql: `select url from documentation where name = ? and version = ?;`, + params: [pkg, version], + }); + + const res = await fetch(((result[0]?.results as { url: string }[] | undefined) ?? [])[0]?.url ?? ''); return res.json(); }, writeToFile: false, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4a34cd960..472365799 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -459,12 +459,6 @@ importers: '@discordjs/scripts': specifier: workspace:^ version: link:../scripts - '@vercel/blob': - specifier: ^2.0.0 - version: 2.0.0 - '@vercel/postgres': - specifier: ^0.10.0 - version: 0.10.0 cloudflare: specifier: ^5.2.0 version: 5.2.0(encoding@0.1.13)