pull-models.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. const value6 = lines.find((line) => line.startsWith("ZEN_MODELS6"))?.split("=")[1]
  17. const value7 = lines.find((line) => line.startsWith("ZEN_MODELS7"))?.split("=")[1]
  18. if (!value1) throw new Error("ZEN_MODELS1 not found")
  19. if (!value2) throw new Error("ZEN_MODELS2 not found")
  20. if (!value3) throw new Error("ZEN_MODELS3 not found")
  21. if (!value4) throw new Error("ZEN_MODELS4 not found")
  22. if (!value5) throw new Error("ZEN_MODELS5 not found")
  23. if (!value6) throw new Error("ZEN_MODELS6 not found")
  24. if (!value7) throw new Error("ZEN_MODELS7 not found")
  25. // validate value
  26. ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5 + value6 + value7))
  27. // update the secret
  28. await $`bun sst secret set ZEN_MODELS1 ${value1}`
  29. await $`bun sst secret set ZEN_MODELS2 ${value2}`
  30. await $`bun sst secret set ZEN_MODELS3 ${value3}`
  31. await $`bun sst secret set ZEN_MODELS4 ${value4}`
  32. await $`bun sst secret set ZEN_MODELS5 ${value5}`
  33. await $`bun sst secret set ZEN_MODELS6 ${value6}`
  34. await $`bun sst secret set ZEN_MODELS7 ${value7}`