package main import ( "fmt" "os" "io" "encoding/base64" "oc-publish/releases" "oc-publish/occonst" ) func main() { version := os.Args[1] fmt.Printf(" >> oc-publish :\n") fmt.Printf(" << Url : %s/%s\n", occonst.PUBLISH_URL, occonst.PUBLISH_REPO) fmt.Printf(" << version : %s %s\n", version, occonst.PUBLISH_BRANCH) vversion := fmt.Sprintf("v%s", version) existe, _ := releases.CheckRelease(vversion) if existe == false { err := releases.CreateRelease(vversion, occonst.PUBLISH_BRANCH) if err != nil { fmt.Println(err) os.Exit(1) } } idRelease, _ := releases.GetReleaseId(vversion) if existe == true { fmt.Println(fmt.Sprintf(" << Release existante : %d ", idRelease)) } else { fmt.Println(fmt.Sprintf(" << Release crée : %d ", idRelease)) } assetname := "oc.json" ficversion := fmt.Sprintf("../oc_%s.yml", version) ficjson := fmt.Sprintf("../%s", assetname) err := createJsonFile(ficversion, ficjson) if err != nil { fmt.Println(err) os.Exit(1) } idAsset, _ := releases.GetAssetId(idRelease, assetname) if idAsset == 0 { fmt.Println(fmt.Sprintf(" << Ajout Asset : %s", assetname)) err := releases.CreateAsset(idRelease, ficjson, assetname) if err != nil { fmt.Println(err) os.Exit(1) } } else { fmt.Println(fmt.Sprintf(" << Mise à jour : %s (idAsset=%d) ", assetname, idAsset)) err := releases.UpdateAsset(idRelease, idAsset, ficjson, assetname) if err != nil { fmt.Println(err) os.Exit(1) } } } func createJsonFile(ficversion string, jsonfile string) error { fout, _ := os.Create(jsonfile) defer fout.Close() fin, err := os.Open(ficversion) if err != nil { return err } defer fin.Close() byteValue, err := io.ReadAll(fin) // data := "abc123!?$*&()'-=@~" data64 := base64.StdEncoding.EncodeToString(byteValue) content := fmt.Sprintf(`{"value": "%s"}`, data64) fout.Write([]byte(content)) fout.Write([]byte("\n")) return nil }