pull-models.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  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. if (!value1) throw new Error("ZEN_MODELS1 not found")
  16. if (!value2) throw new Error("ZEN_MODELS2 not found")
  17. if (!value3) throw new Error("ZEN_MODELS3 not found")
  18. if (!value4) throw new Error("ZEN_MODELS4 not found")
  19. // validate value
  20. ZenData.validate(JSON.parse(value1 + value2 + value3 + value4))
  21. // update the secret
  22. await $`bun sst secret set ZEN_MODELS1 ${value1}`
  23. await $`bun sst secret set ZEN_MODELS2 ${value2}`
  24. await $`bun sst secret set ZEN_MODELS3 ${value3}`
  25. await $`bun sst secret set ZEN_MODELS4 ${value4}`