promote-models.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  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`.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. if (!value1) throw new Error("ZEN_MODELS1 not found")
  18. if (!value2) throw new Error("ZEN_MODELS2 not found")
  19. if (!value3) throw new Error("ZEN_MODELS3 not found")
  20. if (!value4) throw new Error("ZEN_MODELS4 not found")
  21. if (!value5) throw new Error("ZEN_MODELS5 not found")
  22. if (!value6) throw new Error("ZEN_MODELS6 not found")
  23. // validate value
  24. ZenData.validate(JSON.parse(value1 + value2 + value3 + value4 + value5 + value6))
  25. // update the secret
  26. await $`bun sst secret set ZEN_MODELS1 ${value1} --stage ${stage}`
  27. await $`bun sst secret set ZEN_MODELS2 ${value2} --stage ${stage}`
  28. await $`bun sst secret set ZEN_MODELS3 ${value3} --stage ${stage}`
  29. await $`bun sst secret set ZEN_MODELS4 ${value4} --stage ${stage}`
  30. await $`bun sst secret set ZEN_MODELS5 ${value5} --stage ${stage}`
  31. await $`bun sst secret set ZEN_MODELS6 ${value6} --stage ${stage}`