oc-version/publish/main.go
2024-09-13 12:49:49 +00:00

70 lines
1.5 KiB
Go

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)
fmt.Printf(" << existe : %t\n", existe)
if existe == false {
err := releases.CreateRelease(vversion, occonst.PUBLISH_BRANCH)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
idRelease, _ := releases.GetReleaseId(vversion)
fmt.Println(fmt.Sprintf(" << id : %d ", idRelease))
ficversion := fmt.Sprintf("../oc_%s.yml", version)
ficjson := fmt.Sprintf("../oc.json")
createJsonFile(ficversion, ficjson)
idAsset, _ := releases.GetAssetId(idRelease, "oc.json")
if idAsset == 0 {
releases.CreateAsset(idRelease, ficjson)
} else {
releases.UpdateAsset(idRelease, idAsset, ficjson)
fmt.Println(fmt.Sprintf(" << idAsset : %d ", idAsset))
}
}
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
}