Skip to content

Commit

Permalink
chore: make upload to Algolia part of deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Sep 9, 2023
1 parent 19250f1 commit 556983d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
19 changes: 11 additions & 8 deletions commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<DiagnosticData>({ prefix: [DIAGNOSTICS_KEY] });
const objects: Record<string, unknown>[] = [];
for await (const { value } of list) {
objects.push({
objectID: `ts_diagnostic_${value.code}`,
...value,
});
}
log.light(`uploading ${objects.length} records.`);

kia.start("uploading...");

Expand Down

0 comments on commit 556983d

Please sign in to comment.