Skip to content

Commit 86af48b

Browse files
fixing gitsource (#127)
1 parent e06cdd0 commit 86af48b

File tree

7 files changed

+80
-81
lines changed

7 files changed

+80
-81
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.118
1+
VERSION=v0.0.119
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/git-source.go

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ import (
5252

5353
type (
5454
GitSourceCreateOptions struct {
55-
InsCloneOpts *git.CloneOptions
56-
GsCloneOpts *git.CloneOptions
57-
GsName string
58-
RuntimeName string
59-
FullGsPath string
60-
CreateDemoWorkflowTemplate bool
61-
Exclude string
62-
Include string
55+
InsCloneOpts *git.CloneOptions
56+
GsCloneOpts *git.CloneOptions
57+
GsName string
58+
RuntimeName string
59+
CreateDemoResources bool
60+
Exclude string
61+
Include string
6362
}
6463

6564
GitSourceDeleteOptions struct {
@@ -155,66 +154,34 @@ func NewGitSourceCreateCommand() *cobra.Command {
155154
ctx := cmd.Context()
156155

157156
return RunGitSourceCreate(ctx, &GitSourceCreateOptions{
158-
InsCloneOpts: insCloneOpts,
159-
GsCloneOpts: gsCloneOpts,
160-
GsName: args[1],
161-
RuntimeName: args[0],
162-
FullGsPath: gsCloneOpts.Path(),
163-
CreateDemoWorkflowTemplate: false,
157+
InsCloneOpts: insCloneOpts,
158+
GsCloneOpts: gsCloneOpts,
159+
GsName: args[1],
160+
RuntimeName: args[0],
161+
CreateDemoResources: false,
164162
})
165163
},
166164
}
167165

168-
insCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
169-
CreateIfNotExist: true,
170-
})
166+
insCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{})
171167
gsCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
172-
Prefix: "git-src",
173-
Optional: true,
174-
CreateIfNotExist: true,
168+
Prefix: "git-src",
169+
Optional: true,
175170
})
176171

177172
return cmd
178173
}
179174

180175
func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error {
181-
if opts.CreateDemoWorkflowTemplate {
182-
183-
gsRepo, gsFs, err := opts.GsCloneOpts.GetRepo(ctx)
184-
if err != nil {
185-
return err
186-
}
187-
188-
fi, err := gsFs.ReadDir(".")
189-
if err != nil {
190-
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
191-
}
192-
193-
if len(fi) == 0 {
194-
err = createCronExamplePipeline(&gitSourceCronExampleOptions{
195-
runtimeName: opts.RuntimeName,
196-
gsCloneOpts: opts.GsCloneOpts,
197-
gsFs: gsFs,
198-
})
199-
if err != nil {
200-
return fmt.Errorf("failed to create cron example pipeline. Error: %w", err)
201-
}
202-
203-
err = createGithubExamplePipeline(&gitSourceGithubExampleOptions{
204-
runtimeName: opts.RuntimeName,
205-
gsCloneOpts: opts.GsCloneOpts,
206-
gsFs: gsFs,
207-
})
208-
if err != nil {
209-
return fmt.Errorf("failed to create github example pipeline. Error: %w", err)
210-
}
211-
212-
commitMsg := fmt.Sprintf("Created demo pipelines in %s Directory", opts.GsCloneOpts.Path())
176+
// upsert git-source repo
177+
gsRepo, gsFs, err := opts.GsCloneOpts.GetRepo(ctx)
178+
if err != nil {
179+
return fmt.Errorf("failed to clone git-source repo: %w", err)
180+
}
213181

214-
log.G(ctx).Info("Pushing demo pipelines to the new git-source repo")
215-
if err := apu.PushWithMessage(ctx, gsRepo, commitMsg); err != nil {
216-
return fmt.Errorf("failed to push demo pipelines to git-source repo: %w", err)
217-
}
182+
if opts.CreateDemoResources {
183+
if err := createDemoResources(ctx, opts, gsRepo, gsFs); err != nil {
184+
return fmt.Errorf("failed to create git source demo resources: %w", err)
218185
}
219186
}
220187

@@ -227,7 +194,43 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
227194
if err := appDef.CreateApp(ctx, nil, opts.InsCloneOpts, opts.RuntimeName, store.Get().CFGitSourceType, opts.Include, ""); err != nil {
228195
return fmt.Errorf("failed to create git-source application. Err: %w", err)
229196
}
230-
log.G(ctx).Infof("Successfully created the git-source: '%s'", opts.GsName)
197+
log.G(ctx).Infof("Successfully created git-source: '%s'", opts.GsName)
198+
199+
return nil
200+
}
201+
202+
func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRepo git.Repository, gsFs fs.FS) error {
203+
fi, err := gsFs.ReadDir(".")
204+
if err != nil {
205+
return fmt.Errorf("failed to read files in git-source repo. Err: %w", err)
206+
}
207+
208+
if len(fi) == 0 {
209+
err = createCronExamplePipeline(&gitSourceCronExampleOptions{
210+
runtimeName: opts.RuntimeName,
211+
gsCloneOpts: opts.GsCloneOpts,
212+
gsFs: gsFs,
213+
})
214+
if err != nil {
215+
return fmt.Errorf("failed to create cron example pipeline. Error: %w", err)
216+
}
217+
218+
err = createGithubExamplePipeline(&gitSourceGithubExampleOptions{
219+
runtimeName: opts.RuntimeName,
220+
gsCloneOpts: opts.GsCloneOpts,
221+
gsFs: gsFs,
222+
})
223+
if err != nil {
224+
return fmt.Errorf("failed to create github example pipeline. Error: %w", err)
225+
}
226+
227+
commitMsg := fmt.Sprintf("Created demo pipelines in %s Directory", opts.GsCloneOpts.Path())
228+
229+
log.G(ctx).Info("Pushing demo pipelines to the new git-source repo")
230+
if err := apu.PushWithMessage(ctx, gsRepo, commitMsg); err != nil {
231+
return fmt.Errorf("failed to push demo pipelines to git-source repo: %w", err)
232+
}
233+
}
231234

232235
return nil
233236
}

cmd/commands/runtime.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747

4848
"github.com/Masterminds/semver/v3"
4949
"github.com/ghodss/yaml"
50+
"github.com/go-git/go-billy/v5/memfs"
5051
billyUtils "github.com/go-git/go-billy/v5/util"
5152
"github.com/juju/ansiterm"
5253
"github.com/spf13/cobra"
@@ -316,34 +317,31 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
316317
return err
317318
}
318319

319-
gsPath := opts.GsCloneOpts.FS.Join(apstore.Default.AppsDir, store.Get().GitSourceName, opts.RuntimeName)
320-
fullGsPath := opts.GsCloneOpts.FS.Join(opts.GsCloneOpts.FS.Root(), gsPath)[1:]
321-
322320
if err = RunGitSourceCreate(ctx, &GitSourceCreateOptions{
323-
InsCloneOpts: opts.InsCloneOpts,
324-
GsCloneOpts: opts.GsCloneOpts,
325-
GsName: store.Get().GitSourceName,
326-
RuntimeName: opts.RuntimeName,
327-
FullGsPath: fullGsPath,
328-
CreateDemoWorkflowTemplate: true,
321+
InsCloneOpts: opts.InsCloneOpts,
322+
GsCloneOpts: opts.GsCloneOpts,
323+
GsName: store.Get().GitSourceName,
324+
RuntimeName: opts.RuntimeName,
325+
CreateDemoResources: true,
329326
}); err != nil {
330327
return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err)
331328
}
332329

333330
mpCloneOpts := &git.CloneOptions{
334331
Repo: store.Get().MarketplaceRepo,
332+
Auth: opts.GsCloneOpts.Auth,
333+
FS: fs.Create(memfs.New()),
335334
}
336335
mpCloneOpts.Parse()
337336
if err = RunGitSourceCreate(ctx, &GitSourceCreateOptions{
338-
InsCloneOpts: opts.InsCloneOpts,
339-
GsCloneOpts: mpCloneOpts,
340-
GsName: store.Get().MarketplaceGitSourceName,
341-
RuntimeName: opts.RuntimeName,
342-
FullGsPath: store.Get().MarketplaceRepo,
343-
CreateDemoWorkflowTemplate: false,
344-
Include: "**/workflowTemplate.yaml",
337+
InsCloneOpts: opts.InsCloneOpts,
338+
GsCloneOpts: mpCloneOpts,
339+
GsName: store.Get().MarketplaceGitSourceName,
340+
RuntimeName: opts.RuntimeName,
341+
CreateDemoResources: false,
342+
Include: "**/workflowTemplate.yaml",
345343
}); err != nil {
346-
return fmt.Errorf("failed to create `%s`: %w", store.Get().GitSourceName, err)
344+
return fmt.Errorf("failed to create `%s`: %w", store.Get().MarketplaceGitSourceName, err)
347345
}
348346

349347
var wg sync.WaitGroup

docs/commands/cli-v2_git-source_create.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ cli-v2 git-source create runtime_name git-source_name [flags]
1919
```
2020
--git-src-git-token string Your git provider api token [GIT_SRC_GIT_TOKEN]
2121
--git-src-git-user string Your git provider user name [GIT_SRC_GIT_USER] (not required in GitHub)
22-
--git-src-provider string The git provider, one of: gitea|github
2322
--git-src-repo string Repository URL [GIT_SRC_GIT_REPO]
2423
-t, --git-token string Your git provider api token [GIT_TOKEN]
2524
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
2625
-h, --help help for create
27-
--provider string The git provider, one of: gitea|github
2826
--repo string Repository URL [GIT_REPO]
2927
```
3028

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cf version
2020
### Linux
2121
```bash
2222
# download and extract the binary
23-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.118/cf-linux-amd64.tar.gz | tar zx
23+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.119/cf-linux-amd64.tar.gz | tar zx
2424

2525
# move the binary to your $PATH
2626
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -32,7 +32,7 @@ cf version
3232
### Mac
3333
```bash
3434
# download and extract the binary
35-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.118/cf-darwin-amd64.tar.gz | tar zx
35+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.119/cf-darwin-amd64.tar.gz | tar zx
3636

3737
# move the binary to your $PATH
3838
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.118
8+
version: 0.0.119
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/store/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func init() {
146146
s.MaxDefVersion = semver.MustParse(maxDefVersion)
147147
s.RuntimeDefURL = RuntimeDefURL
148148
s.MarketplaceGitSourceName = "marketplace-git-source"
149-
s.MarketplaceRepo = "https://github.com/codefresh-io/2.0-marketplace.git/"
149+
s.MarketplaceRepo = "https://github.com/codefresh-io/2.0-marketplace.git"
150150
s.WaitTimeout = 8 * time.Minute
151151
s.WorkflowName = "workflow"
152152
s.WorkflowReporterName = "workflow-reporter"

0 commit comments

Comments
 (0)