Skip to content

Commit

Permalink
feat(release): Handle ios release
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Oct 2, 2018
1 parent fd3bcca commit 3b04c06
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 74 deletions.
21 changes: 4 additions & 17 deletions cmd/berty-release/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"strconv"

"github.com/spf13/cobra"
)
Expand All @@ -19,12 +18,12 @@ var buildListCmd = &cobra.Command{
Short: "list last 30 builds, if branch is omitted list all 30 recent builds",
Run: func(cmd *cobra.Command, args []string) {
var pull string
if len(args) > 0 && args[0] != "" {
if len(args) > 0 {
pull = args[0]

}

bs, err := cfg.client.Builds(pull, 30, 0)
bs, err := cfg.client.Builds(pull, "", 30, 0)
if err != nil {
fmt.Println("client error: ", err)
return
Expand All @@ -42,13 +41,7 @@ var buildGetCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
Short: "get build info",
Run: func(cmd *cobra.Command, args []string) {
bn, err := strconv.Atoi(args[0])
if err != nil {
fmt.Println("args error: ", err)
return
}

bs, err := cfg.client.Build(bn)
bs, err := cfg.client.Build(args[0])
if err != nil {
fmt.Println("client error: ", err)
return
Expand All @@ -66,13 +59,7 @@ var buildGetArtifactsCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
Short: "get build artifacts",
Run: func(cmd *cobra.Command, args []string) {
bn, err := strconv.Atoi(args[0])
if err != nil {
fmt.Println("args error: ", err)
return
}

arts, err := cfg.client.GetArtifacts(bn, true)
arts, err := cfg.client.GetArtifacts(args[0], true)
if err != nil {
fmt.Println("client error: ", err)
return
Expand Down
6 changes: 4 additions & 2 deletions cmd/berty-release/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

type serverConfig struct {
addr string
addr string
hostname string
}

var serverCfg serverConfig
Expand All @@ -15,13 +16,14 @@ var serveCmd = &cobra.Command{
Use: "serve",
Short: "Server release tool",
Run: func(cmd *cobra.Command, args []string) {
s := server.NewServer(cfg.client)
s := server.NewServer(cfg.client, serverCfg.hostname)
panic(s.Start(serverCfg.addr))
},
}

func init() {
serveCmd.PersistentFlags().StringVarP(&serverCfg.addr, "listen", "l", ":3670", "Listen addr")
serveCmd.PersistentFlags().StringVarP(&serverCfg.hostname, "hostname", "n", "localhost", "hostname")

rootCmd.AddCommand(serveCmd)
}
57 changes: 51 additions & 6 deletions pkg/circle/build.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
package circle

import (
"bytes"
"io"
"strconv"

circleci "github.com/jszwedko/go-circleci"
)

func (c *Client) Builds(pull string, limit, offset int) ([]*circleci.Build, error) {
return c.ci.ListRecentBuildsForProject(c.username, c.repo, pull, "", limit, offset)
func (c *Client) Builds(pull string, job string, limit, offset int) ([]*circleci.Build, error) {
bs, err := c.ci.ListRecentBuildsForProject(c.username, c.repo, pull, "", limit, offset)
if job == "" {
return bs, err
}

var jbuild []*circleci.Build
for _, b := range bs {
if j, ok := b.BuildParameters["CIRCLE_JOB"]; ok {
if j == job {
jbuild = append(jbuild, b)
}

}
}

return jbuild, nil
}

func (c *Client) Build(build string) (*circleci.Build, error) {
i, err := strconv.Atoi(build)
if err != nil {
return nil, err
}

return c.ci.GetBuild(c.username, c.repo, i)
}

func (c *Client) Build(nbuild int) (*circleci.Build, error) {
return c.ci.GetBuild(c.username, c.repo, nbuild)
func (c *Client) GetArtifact(art *circleci.Artifact) (io.ReadCloser, error) {
res, err := c.http.Get(art.URL)
return res.Body, err
}

func (c *Client) GetArtifacts(nbuild int, token bool) ([]*circleci.Artifact, error) {
arts, err := c.ci.ListBuildArtifacts(c.username, c.repo, nbuild)
func (c *Client) GetRawArtifact(art *circleci.Artifact) ([]byte, int64, error) {
body, err := c.GetArtifact(art)

buf := &bytes.Buffer{}
nRead, err := io.Copy(buf, body)

body.Close()

return buf.Bytes(), nRead, err
}

func (c *Client) GetArtifacts(build string, token bool) ([]*circleci.Artifact, error) {
i, err := strconv.Atoi(build)
if err != nil {
return nil, err
}

arts, err := c.ci.ListBuildArtifacts(c.username, c.repo, i)
if err != nil {
return nil, err
}
Expand Down
47 changes: 9 additions & 38 deletions pkg/circle/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Client struct {
username string
repo string
token string

http *http.Client
}

func New(token, username, repo string) *Client {
Expand All @@ -22,42 +24,11 @@ func New(token, username, repo string) *Client {
}

ci := &circleci.Client{Token: token, HTTPClient: httpclient}
return &Client{ci, username, repo, token}
return &Client{
ci: ci,
username: username,
repo: repo,
token: token,
http: httpclient,
}
}

// func (c *Client) client() *http.Client {
// return http.DefaultClient
// }

// func (c *Client) request(bodyStruct interface{}) error {
// req, err := http.NewRequest(method, u.String(), nil)
// if err != nil {
// return err
// }

// req.Header.Add("Accept", "application/json")
// req.Header.Add("Content-Type", "application/json")

// if bodyStruct != nil {
// b, err := json.Marshal(bodyStruct)
// if err != nil {
// return err
// }

// req.Body = nopCloser{bytes.NewBuffer(b)}
// }

// resp, err := c.client().Do(req)
// if err != nil {
// return err
// }
// defer resp.Body.Close()

// if responseStruct != nil {
// err = json.NewDecoder(resp.Body).Decode(responseStruct)
// if err != nil {
// return err
// }
// }

// }
58 changes: 58 additions & 0 deletions server/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package server

import "howett.net/plist"

var ApplePlistHeader = `
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
//"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
`

type ApplePlistAsset struct {
Kind string `plist:"kind"`
URL string `plist:"url"` // kind, url
}

type ApplePlistMetadata struct {
BundleIdentifier string `plist:"bundle-identifier"`
BundleVersion string `plist:"bundle-version"`
Kind string `plist:"kind"`
Title string `plist:"title"`
}

type ApplePlistItem struct {
Assets []*ApplePlistAsset `plist:"assets"`
Metadata *ApplePlistMetadata `plist:"metadata"`
}

type ApplePlistRelease struct {
Items []*ApplePlistItem
}

func NewPlistRelease(bundle, version, title, url string) ([]byte, error) {
meta := &ApplePlistMetadata{
BundleIdentifier: bundle,
BundleVersion: version,
Kind: "software",
Title: title,
}

assets := []*ApplePlistAsset{
&ApplePlistAsset{
Kind: "software-package",
URL: url,
},
}

items := []*ApplePlistItem{
&ApplePlistItem{
Assets: assets,
Metadata: meta,
},
}

release := &ApplePlistRelease{
Items: items,
}

return plist.MarshalIndent(release, plist.XMLFormat, "\t")
}
Loading

0 comments on commit 3b04c06

Please sign in to comment.