diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3bde07a..f0e9c13 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,14 +17,14 @@ jobs: env: GH_REPO: tswhy-test GH_TOKEN: github_pat_token - ALGOLIA_APP_ID: app_id - ALGOLIA_ADMIN_KEY: admin_key + ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} + ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }} DENO_KV_ACCESS_TOKEN: ${{ secrets.DENO_KV_ACCESS_TOKEN }} steps: - name: clone repository uses: actions/checkout@v3 - + - name: install deno uses: denoland/setup-deno@v1 with: @@ -38,6 +38,12 @@ jobs: with: project: "tswhy" entrypoint: "./main.ts" - + - name: upload KV store run: "deno task build docs -p" + + - name: build local KV store + run: "deno task build docs" + + - name: upload to Algolia + run: "deno task build upload" diff --git a/commands/upload.ts b/commands/upload.ts index 422862b..e1655ad 100644 --- a/commands/upload.ts +++ b/commands/upload.ts @@ -9,6 +9,7 @@ import { load } from "std/dotenv/mod.ts"; import type { DiagnosticData } from "$types"; import { kia } from "$util/cli.ts"; +import { DIAGNOSTICS_KEY } from "$util/kv.ts"; import { log } from "$util/log.ts"; export default new Command() @@ -36,14 +37,16 @@ export default new Command() const index = client.initIndex("typescript_errors"); - const all: DiagnosticData[] = JSON.parse( - await Deno.readTextFile("./db/_all.json"), - ); - log.light(`uploading ${all.length} records.`); - const objects = all.map((item) => ({ - objectID: `ts_diagnostic_${item.code}`, - ...item, - })); + const kv = await Deno.openKv(); + const list = kv.list({ prefix: [DIAGNOSTICS_KEY] }); + const objects: Record[] = []; + for await (const { value } of list) { + objects.push({ + objectID: `ts_diagnostic_${value.code}`, + ...value, + }); + } + log.light(`uploading ${objects.length} records.`); kia.start("uploading...");