pull-models.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bun
  2. import { $ } from "bun"
  3. import path from "path"
  4. import { ZenData } from "../src/model"
  5. const stage = process.argv[2]
  6. if (!stage) throw new Error("Stage is required")
  7. const root = path.resolve(process.cwd(), "..", "..", "..")
  8. // read the secret
  9. const ret = await $`bun sst secret list --stage ${stage}`.cwd(root).text()
  10. const lines = ret.split("\n")
  11. const value1 = lines.find((line) => line.startsWith("ZEN_MODELS1"))?.split("=")[1]
  12. const value2 = lines.find((line) => line.startsWith("ZEN_MODELS2"))?.split("=")[1]
  13. const value3 = lines.find((line) => line.startsWith("ZEN_MODELS3"))?.split("=")[1]
  14. const value4 = lines.find((line) => line.startsWith("ZEN_MODELS4"))?.split("=")[1]
  15. const value5 = lines.find((line) => line.startsWith("ZEN_MODELS5"))?.split("=")[1]
  16. if (!value1) throw new Error("ZEN_MODELS1 not found")
  17. if (!value2) throw new Error("ZEN_MODELS2 not found")
  18. if (!value3) throw new Error("ZEN_MODELS3 not found")
  19. if (!value4) throw new Error("ZEN_MODELS4 not found")
  20. if (!value5) throw new Error("ZEN_MODELS5 not found")
  21. // validate value
  22. ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5))
  23. // update the secret
  24. await $`bun sst secret set ZEN_MODELS1 ${value1}`
  25. await $`bun sst secret set ZEN_MODELS2 ${value2}`
  26. await $`bun sst secret set ZEN_MODELS3 ${value3}`
  27. await $`bun sst secret set ZEN_MODELS4 ${value4}`
  28. await $`bun sst secret set ZEN_MODELS5 ${value5}`