(config BundleConfig, fileName string, hash string)
| 294 | } |
| 295 | |
| 296 | func createAndUploadBundle(config BundleConfig, fileName string, hash string) error { |
| 297 | log.Println("✦ Zipping bundle"+" "+config.AppName+" "+config.TargetVersion, fileName) |
| 298 | utils.Zip(config.ProjectDir+"build", fileName) |
| 299 | |
| 300 | // exec.Command("open", config.ProjectDir+"build").Run() |
| 301 | os.RemoveAll(config.ProjectDir + "build") |
| 302 | log.Println("✦ Uploading bundle") |
| 303 | |
| 304 | Url, err := url.Parse(config.RemoteURL + "/bundle/upload") |
| 305 | if err != nil { |
| 306 | log.Panic(err.Error()) |
| 307 | } |
| 308 | pathName := fileName |
| 309 | req, err := newfileUploadRequest(Url.String(), config.AuthKey, map[string]string{"filename": fileName}, "file", pathName) |
| 310 | if err != nil { |
| 311 | log.Panic(err.Error()) |
| 312 | } |
| 313 | uploadClient := &http.Client{} |
| 314 | resp, err := uploadClient.Do(req) |
| 315 | if err != nil { |
| 316 | os.RemoveAll(fileName) |
| 317 | log.Panic(err.Error()) |
| 318 | } |
| 319 | defer resp.Body.Close() |
| 320 | body, err := io.ReadAll(resp.Body) |
| 321 | if err != nil { |
| 322 | os.RemoveAll(fileName) |
| 323 | log.Panicf("Failed to read response body: %v", err) |
| 324 | } |
| 325 | if resp.StatusCode != 200 { |
| 326 | log.Println("✦ Upload fail", string(body)) |
| 327 | os.RemoveAll(fileName) |
| 328 | return fmt.Errorf("upload failed: %s", resp.Status) |
| 329 | } |
| 330 | log.Println("✦ Bundle has been uploaded successfully.") |
| 331 | log.Println("✦ Creating a new bundle") |
| 332 | |
| 333 | Url, err = url.Parse(config.RemoteURL + "/bundle/create") |
| 334 | if err != nil { |
| 335 | os.RemoveAll(fileName) |
| 336 | log.Panic("Server url error :", err) |
| 337 | } |
| 338 | fileInfo, _ := os.Stat(fileName) |
| 339 | size := fileInfo.Size() |
| 340 | createBundleReq := types.CreateNewBundleRequest{ |
| 341 | AppName: config.AppName, |
| 342 | Environment: config.Environment, |
| 343 | DownloadFile: fileName, |
| 344 | Description: config.Description, |
| 345 | AppVersion: config.TargetVersion, |
| 346 | Size: size, |
| 347 | Hash: hash, |
| 348 | } |
| 349 | jsonByte, _ := json.Marshal(createBundleReq) |
| 350 | req, _ = http.NewRequest("POST", Url.String(), bytes.NewBuffer(jsonByte)) |
| 351 | req.Header.Set("Content-Type", "application/json") |
| 352 | req.Header.Set("x-auth-key", config.AuthKey) |
| 353 | createBundleClient := &http.Client{} |
no test coverage detected