Skip to content

Commit

Permalink
Add formating setting of CustomWarPackage object (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen authored Nov 6, 2020
1 parent 4d34938 commit ed2b9aa
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 56 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ COVERED_MAIN_SRC_FILE=./main
PATH := $(PATH):$(PWD)/bin

darwin:
gofmt -s -w pkg
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/darwin/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/darwin/$(NAME)
rm -rf $(NAME) && ln -s bin/darwin/$(NAME) cj

linux:
gofmt -s -w pkg
GO111MODULE=on CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) $(BUILD_TARGET) $(BUILDFLAGS) -o bin/linux/$(NAME) $(MAIN_SRC_FILE)
chmod +x bin/linux/$(NAME)
rm -rf $(NAME) && ln -s bin/linux/$(NAME) cj
Expand Down
50 changes: 25 additions & 25 deletions pkg/build/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ type BuildOptions struct {
Token string

DockerUsername string
DockerToken string
DockerToken string

CleanWAR bool
CleanWAR bool
CleanTempDir bool
CleanImage bool
DryRun bool
CleanImage bool
DryRun bool

ConfigManager *common.CustomConfigManager
}

// NewBuildCommand build the custom Jenkins
func NewBuildCommand(commonOpts *common.Options) (cmd *cobra.Command) {
buildOptions := BuildOptions{
Options: commonOpts,
Options: commonOpts,
ConfigManager: &common.CustomConfigManager{},
}
cmd = &cobra.Command{
Use: "build",
Short: "build the custom Jenkins",
RunE: buildOptions.Run,
RunE: buildOptions.Run,
}
cmd.Flags().StringVarP(&buildOptions.Username, "username", "u", "",
`The username of Bintray API`)
Expand Down Expand Up @@ -197,34 +197,34 @@ type VersionFormula struct {
}

type BintrayVersion struct {
Name string
Desc string
Package string
Repo string
Owner string
Labels []string
Published bool
Name string
Desc string
Package string
Repo string
Owner string
Labels []string
Published bool
AttributeNames []string
Created string
Updated string
Released string
Message string
Created string
Updated string
Released string
Message string
}

type BintrayFile struct {
Name string
Path string
Repo string
Name string
Path string
Repo string
Package string
Version string
Owner string
Owner string
Created string
Size int64
Sha1 string
Sha256 string
Size int64
Sha1 string
Sha256 string
}

func (o *BuildOptions) getVersionFiles(version string) (files []BintrayFile, err error){
func (o *BuildOptions) getVersionFiles(version string) (files []BintrayFile, err error) {
client := &http.Client{}
api := fmt.Sprintf("https://api.bintray.com/packages/jenkins-zh/generic/jenkins/versions/%s/files", version)

Expand Down
4 changes: 2 additions & 2 deletions pkg/check/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ type CheckOptions struct {
// NewCheckCommand check the version command
func NewCheckCommand(commonOpts *common.Options) (cmd *cobra.Command) {
checkOptions := CheckOptions{
Options: commonOpts,
Options: commonOpts,
ConfigManager: &common.CustomConfigManager{},
}
cmd = &cobra.Command{
Use: "check",
Short: "check update of the Jenkins version",
RunE: checkOptions.Run,
RunE: checkOptions.Run,
}
return
}
Expand Down
43 changes: 21 additions & 22 deletions pkg/common/custom_war.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func RenderTemplate(path string, values map[string]string) (result string, err error) {
var t *template.Template
if t, err = template.ParseFiles(path); err == nil {
f,_ := ioutil.TempFile("/tmp", ".yaml")
f, _ := ioutil.TempFile("/tmp", ".yaml")
err = t.Execute(f, values)

result = f.Name()
Expand All @@ -18,47 +18,46 @@ func RenderTemplate(path string, values map[string]string) (result string, err e
}

type CustomWarPackage struct {
Bundle Bundle
BuildSettings BuildSettings
War CustomWar
Plugins []Plugin
Bundle Bundle `yaml:"bundle"`
BuildSettings BuildSettings `yaml:"buildSettings"`
War CustomWar `yaml:"war"`
Plugins []Plugin `yaml:"plugins"`
}

type CASC struct {

}

type Plugin struct {
GroupId string
ArtifactId string
Source Source
GroupId string `yaml:"groupId"`
ArtifactId string `yaml:"artifactId"`
Source Source `yaml:"source"`
}

type Bundle struct {
GroupId string
ArtifactId string
Description string
Vendor string
GroupId string `yaml:"groupId"`
ArtifactId string `yaml:"artifactId"`
Description string `yaml:"description"`
Vendor string `yaml:"vendor"`
}

type BuildSettings struct {
Docker BuildDockerSetting
Docker BuildDockerSetting `yaml:"docker"`
}

type BuildDockerSetting struct {
Base string
Tag string
Build bool
Base string `yaml:"base"`
Tag string `yaml:"tag"`
Build bool `yaml:"build"`
}

type CustomWar struct {
GroupId string
ArtifactId string
Source Source
GroupId string `yaml:"groupId"`
ArtifactId string `yaml:"artifactId"`
Source Source `yaml:"source"`
}

type Source struct {
Version string
Version string `yaml:"version"`
}

func ReadCustomWarConfig(path string) (cwp *CustomWarPackage, err error) {
Expand All @@ -75,4 +74,4 @@ func SetCustomWarConfigVersion(version string, cwp *CustomWarPackage) {

func SaveCustomWarConfig(cwp *CustomWarPackage, path string) (err error) {
return
}
}
8 changes: 4 additions & 4 deletions pkg/common/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ type Options struct {

type CustomConfig struct {
Formulas []CustomFormula
LTS []string
Weekly []string
LTS []string
Weekly []string
}

type CustomFormula struct {
Name string
MD5 string
MD5 string
}

type CustomConfigManager struct {
CustomConfig *CustomConfig
ConfigPath string
ConfigPath string
}

func (c *CustomConfigManager) Read(path string) (err error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/common/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
fakeLTS = "fake-lts"
fakeLTS = "fake-lts"
fakeWeekly = "fake-weekly"
)

Expand All @@ -32,7 +32,7 @@ func TestReadCustomConfig(t *testing.T) {
var ok bool
// lts testing
if ok, err = mgr.HasTLS(fakeLTS); err != nil || ok {
t.Fatalf("%s should not exists, %v", fakeLTS, err)
t.Fatalf("%s should not exists, %v", fakeLTS, err)
}

if err = mgr.AddTLS(fakeLTS); err != nil {
Expand Down Expand Up @@ -78,4 +78,4 @@ lts:
weekly:
- 2.223
`
}
}

0 comments on commit ed2b9aa

Please sign in to comment.