84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"io/ioutil"
|
|
"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-deploy.base64"
|
|
binary := fmt.Sprintf("../bin/oc-deploy")
|
|
binary64 := fmt.Sprintf("../%s", assetname)
|
|
err := createBinaryFile(binary, binary64)
|
|
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, binary64, 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, binary64, assetname)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
func createBinaryFile(source string, dest string) error {
|
|
fout, _ := os.Create(dest)
|
|
defer fout.Close()
|
|
|
|
byteValue, err := ioutil.ReadFile(source)
|
|
if err != nil {
|
|
fmt.Println("64e", err)
|
|
|
|
return err
|
|
}
|
|
|
|
data64 := base64.StdEncoding.EncodeToString(byteValue)
|
|
fout.Write([]byte(data64))
|
|
return nil
|
|
}
|