oc-deploy/publish/main.go

84 lines
2.0 KiB
Go
Raw Normal View History

2024-09-11 15:44:20 +02:00
package main
import (
2024-09-13 14:43:09 +02:00
"fmt"
"os"
"io/ioutil"
"encoding/base64"
"oc-publish/releases"
"oc-publish/occonst"
2024-09-11 15:44:20 +02:00
)
func main() {
2024-09-13 14:43:09 +02:00
version := os.Args[1]
2024-09-11 15:44:20 +02:00
2024-09-13 14:43:09 +02:00
fmt.Printf(" >> oc-publish :\n")
2024-09-11 15:44:20 +02:00
2024-09-13 14:43:09 +02:00
fmt.Printf(" << Url : %s/%s\n", occonst.PUBLISH_URL, occonst.PUBLISH_REPO)
2024-09-11 15:44:20 +02:00
2024-09-13 14:43:09 +02:00
fmt.Printf(" << version : %s %s\n", version, occonst.PUBLISH_BRANCH)
2024-09-11 15:44:20 +02:00
2024-09-13 14:43:09 +02:00
vversion := fmt.Sprintf("v%s", version)
existe, _ := releases.CheckRelease(vversion)
2024-09-11 15:44:20 +02:00
2024-09-13 14:43:09 +02:00
if existe == false {
err := releases.CreateRelease(vversion, occonst.PUBLISH_BRANCH)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
2024-09-11 15:44:20 +02:00
2024-09-13 14:43:09 +02:00
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
2024-09-11 15:44:20 +02:00
}