main.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package main
  2. import (
  3. "app-uploader/huawei"
  4. "app-uploader/utils"
  5. "fmt"
  6. "runtime"
  7. "strconv"
  8. "strings"
  9. )
  10. func main() {
  11. // 读取package.json版本数据
  12. // 复制app.json文件和logo文件
  13. // 读取配置
  14. appConf, err := utils.ReadAppConfig()
  15. if err != nil {
  16. fmt.Println("读取配置文件错误")
  17. return
  18. }
  19. uploadConf, err := utils.ReadConfig()
  20. if err != nil {
  21. fmt.Println("读取配置文件错误")
  22. return
  23. }
  24. dest := ""
  25. copyFiles := []string{}
  26. // 需要修改版本的文件
  27. modify := ""
  28. // 复制文件到对应目录
  29. switch appConf.Key {
  30. case "queenter":
  31. dest = uploadConf.Queenter.Dest
  32. copyFiles = uploadConf.Queenter.Files
  33. modify = uploadConf.Queenter.Modify
  34. default:
  35. return
  36. }
  37. // 复制文件到目标目录中
  38. for _, file := range copyFiles {
  39. err := utils.Copy(file, fmt.Sprintf("%s/%s", dest, file))
  40. if err != nil {
  41. fmt.Println(err)
  42. return
  43. }
  44. }
  45. // 获取版本信息
  46. version, err := utils.GetVersion()
  47. if err != nil {
  48. fmt.Println(err)
  49. return
  50. }
  51. appConf.Version = version
  52. appConfDest := fmt.Sprintf("%s/%s", dest, modify)
  53. err = utils.WriteAppConfig(appConf, appConfDest)
  54. if err != nil {
  55. fmt.Println(err)
  56. return
  57. }
  58. // 压缩文件
  59. // remoteswift-v1.0.0-x64-windows.zip
  60. zipFile := fmt.Sprintf("%s-v%s-%s-%s.zip", appConf.Key, version, runtime.GOARCH, runtime.GOOS)
  61. zipPath := fmt.Sprintf("output/%s", zipFile)
  62. fmt.Println("压缩文件中...")
  63. err = utils.Zip(zipPath, dest)
  64. if err != nil {
  65. fmt.Println("压缩文件出错")
  66. return
  67. }
  68. fmt.Println("上传中...")
  69. // 上传文件
  70. huawei.InitConfig()
  71. // http://spu3dv1.obs.cn-east-3.myhuaweicloud.com/pkg/lancher1.0.2.windows-amd64.zip
  72. obsDir := "pkg"
  73. obs, err := huawei.UploadFile(zipPath, obsDir, zipFile)
  74. if err != nil {
  75. fmt.Println(err)
  76. return
  77. }
  78. if len(obs.Url) < 1 {
  79. fmt.Println("上传zipfile错误")
  80. return
  81. }
  82. fmt.Println("succ uploaded=>", obs.Url)
  83. // 获取最新版本
  84. // 输出db文件
  85. outputDb := "output/db.json"
  86. sizeM, err := strconv.Atoi(strings.Replace(appConf.Size, "MB", "", -1))
  87. if err != nil {
  88. fmt.Println("转换size string->int 错误:", err)
  89. }
  90. err = utils.WriteVersionDb(&utils.Version{
  91. Name: appConf.Key,
  92. Version: version,
  93. SizeM: sizeM,
  94. Url: fmt.Sprintf("https:%s", obs.Url),
  95. }, outputDb)
  96. if err != nil {
  97. fmt.Println(err)
  98. return
  99. }
  100. fmt.Println("上传成功")
  101. }