Compare commits
No commits in common. "main" and "develop" have entirely different histories.
19
oc_0.1.0.yml
19
oc_0.1.0.yml
@ -12,26 +12,15 @@ tools:
|
|||||||
version: v3.16.0
|
version: v3.16.0
|
||||||
|
|
||||||
opencloud:
|
opencloud:
|
||||||
- oci:
|
- repository:
|
||||||
url: oci://harbor.dtf/dev
|
name: opencloud-0.1.0
|
||||||
|
url: https://harbor.dtf/dev
|
||||||
|
opts: --insecure-skip-tls-verify
|
||||||
charts:
|
charts:
|
||||||
- name: oc-mongo
|
- name: oc-mongo
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
helm_opts: --insecure-skip-tls-verify
|
|
||||||
helm_filevalues:
|
|
||||||
- values.yml
|
|
||||||
- name: oc-catalog
|
- name: oc-catalog
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
helm_opts: --insecure-skip-tls-verify
|
|
||||||
helm_filevalues:
|
|
||||||
- values.yml
|
|
||||||
- name: oc-shared
|
- name: oc-shared
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
helm_opts: --insecure-skip-tls-verify
|
|
||||||
helm_filevalues:
|
|
||||||
- values.yml
|
|
||||||
- name: oc-workspace
|
- name: oc-workspace
|
||||||
version: 0.1.0
|
|
||||||
helm_opts: --insecure-skip-tls-verify
|
|
||||||
helm_filevalues:
|
|
||||||
- values.yml
|
|
||||||
|
@ -21,47 +21,30 @@ func main() {
|
|||||||
|
|
||||||
vversion := fmt.Sprintf("v%s", version)
|
vversion := fmt.Sprintf("v%s", version)
|
||||||
existe, _ := releases.CheckRelease(vversion)
|
existe, _ := releases.CheckRelease(vversion)
|
||||||
|
fmt.Printf(" << existe : %t\n", existe)
|
||||||
|
|
||||||
if existe == false {
|
if existe == false {
|
||||||
err := releases.CreateRelease(vversion, occonst.PUBLISH_BRANCH)
|
err := releases.CreateRelease(vversion, occonst.PUBLISH_BRANCH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idRelease, _ := releases.GetReleaseId(vversion)
|
idRelease, _ := releases.GetReleaseId(vversion)
|
||||||
if existe == true {
|
fmt.Println(fmt.Sprintf(" << id : %d ", idRelease))
|
||||||
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)
|
ficversion := fmt.Sprintf("../oc_%s.yml", version)
|
||||||
ficjson := fmt.Sprintf("../%s", assetname)
|
ficjson := fmt.Sprintf("../oc.json")
|
||||||
err := createJsonFile(ficversion, ficjson)
|
createJsonFile(ficversion, ficjson)
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
idAsset, _ := releases.GetAssetId(idRelease, assetname)
|
idAsset, _ := releases.GetAssetId(idRelease, "oc.json")
|
||||||
if idAsset == 0 {
|
if idAsset == 0 {
|
||||||
fmt.Println(fmt.Sprintf(" << Ajout Asset : %s", assetname))
|
releases.CreateAsset(idRelease, ficjson)
|
||||||
err := releases.CreateAsset(idRelease, ficjson, assetname)
|
} else {
|
||||||
if err != nil {
|
releases.UpdateAsset(idRelease, idAsset, ficjson)
|
||||||
fmt.Println(err)
|
fmt.Println(fmt.Sprintf(" << idAsset : %d ", idAsset))
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -54,7 +53,7 @@ func GetAssetId(idRelease int, name string) (int, error) {
|
|||||||
// -H 'accept: application/json' \
|
// -H 'accept: application/json' \
|
||||||
// -H 'Content-Type: multipart/form-data' \
|
// -H 'Content-Type: multipart/form-data' \
|
||||||
// -F 'attachment=oc-deploy'
|
// -F 'attachment=oc-deploy'
|
||||||
func CreateAsset(idRelease int, filename string, name string) (error) {
|
func CreateAsset(idRelease int, filename string, name string) (int, error) {
|
||||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets?name=%s&token=%s",
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets?name=%s&token=%s",
|
||||||
occonst.PUBLISH_URL,
|
occonst.PUBLISH_URL,
|
||||||
occonst.PUBLISH_REPO,
|
occonst.PUBLISH_REPO,
|
||||||
@ -64,42 +63,20 @@ func CreateAsset(idRelease int, filename string, name string) (error) {
|
|||||||
|
|
||||||
err := uploadFile(url, "attachment", filename)
|
err := uploadFile(url, "attachment", filename)
|
||||||
|
|
||||||
return err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateAsset(idRelease int, idAsset int, filename string, name string) (error) {
|
func UpdateAsset(idRelease int, idAsset int,filename string, name string) (int, error) {
|
||||||
|
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets?name=%s&token=%s",
|
||||||
|
occonst.PUBLISH_URL,
|
||||||
|
occonst.PUBLISH_REPO,
|
||||||
|
idRelease,
|
||||||
|
name,
|
||||||
|
occonst.PUBLISH_TOKEN)
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/api/v1/repos/%s/releases/%d/assets/%d?token=%s",
|
err := uploadFile(url, "attachment", filename)
|
||||||
occonst.PUBLISH_URL,
|
|
||||||
occonst.PUBLISH_REPO,
|
|
||||||
idRelease,
|
|
||||||
idAsset,
|
|
||||||
occonst.PUBLISH_TOKEN)
|
|
||||||
|
|
||||||
// Create client
|
return 0, err
|
||||||
client := &http.Client{}
|
|
||||||
|
|
||||||
// Create request
|
|
||||||
req, err := http.NewRequest("DELETE", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch Request
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
// Read Response Body
|
|
||||||
respBody, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println(string(respBody))
|
|
||||||
|
|
||||||
return CreateAsset(idRelease, filename, name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadFile(url string, paramName string, filePath string) error {
|
func uploadFile(url string, paramName string, filePath string) error {
|
||||||
@ -108,7 +85,7 @@ func uploadFile(url string, paramName string, filePath string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
body := &bytes.Buffer{}
|
body := &bytes.Buffer{}
|
||||||
writer := multipart.NewWriter(body)
|
writer := multipart.NewWriter(body)
|
||||||
part, err := writer.CreateFormFile(paramName, filepath.Base(filePath))
|
part, err := writer.CreateFormFile(paramName, filepath.Base(filePath))
|
||||||
@ -127,19 +104,14 @@ func uploadFile(url string, paramName string, filePath string) error {
|
|||||||
request.Header.Add("accept", "application/json")
|
request.Header.Add("accept", "application/json")
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
response, err := client.Do(request)
|
response, err := client.Do(request)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(109, err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
if response.StatusCode > 400 {
|
_, err := io.ReadAll(response.Body)
|
||||||
return fmt.Errorf(response.Status)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err1 := io.ReadAll(response.Body)
|
|
||||||
|
|
||||||
// Handle the server response...
|
// Handle the server response...
|
||||||
return err1
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package releases
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -87,19 +86,14 @@ func CreateRelease(version string, branch string) (error) {
|
|||||||
occonst.PUBLISH_REPO,
|
occonst.PUBLISH_REPO,
|
||||||
occonst.PUBLISH_TOKEN)
|
occonst.PUBLISH_TOKEN)
|
||||||
|
|
||||||
releasebytes, err := ioutil.ReadFile("release.txt")
|
|
||||||
releasetxt := string(releasebytes)
|
|
||||||
releasetxt = strings.Replace(releasetxt, "\n", "\\n", -1)
|
|
||||||
releasetxt = fmt.Sprintf(releasetxt, version, occonst.PUBLISH_URL, occonst.PUBLISH_REPO, version)
|
|
||||||
|
|
||||||
body := fmt.Sprintf(`{
|
body := fmt.Sprintf(`{
|
||||||
"body": "%s",
|
"body": "Version %s",
|
||||||
"draft": false,
|
"draft": false,
|
||||||
"name": "%s",
|
"name": "%s",
|
||||||
"prerelease": false,
|
"prerelease": false,
|
||||||
"tag_name": "%s",
|
"tag_name": "%s",
|
||||||
"target_commitish": "%s"
|
"target_commitish": "%s"
|
||||||
}`, releasetxt, version, version, branch)
|
}`, version, version, version, branch)
|
||||||
|
|
||||||
request, err := http.NewRequest("POST", url, strings.NewReader(body))
|
request, err := http.NewRequest("POST", url, strings.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -116,9 +110,6 @@ func CreateRelease(version string, branch string) (error) {
|
|||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
_, err1 := io.ReadAll(response.Body)
|
_, err1 := io.ReadAll(response.Body)
|
||||||
// cnt, err1 := io.ReadAll(response.Body)
|
|
||||||
// fmt.Println(string(cnt))
|
|
||||||
|
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return err1
|
return err1
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user