@@ -16,6 +16,7 @@ const INSTALLATION_DEFAULTS = {
16
16
MAKE_DEFAULT_RE : false ,
17
17
RUN_DEMO_PIPELINE : true ,
18
18
DEMO_PIPELINE_NAME : 'Codefresh-Runner Demo' ,
19
+ PROJECT_NAME : 'Runner' ,
19
20
CF_CONTEXT_NAME : 'cf-runner' ,
20
21
} ;
21
22
@@ -24,10 +25,40 @@ const DefaultLogFormatter = 'plain';
24
25
const defaultOpenIssueMessage = 'If you had any issues with this process please report them at: ' +
25
26
`${ colors . blue ( 'https://github.com/codefresh-io/cli/issues/new' ) } ` ;
26
27
27
- async function createTestPipeline ( runtimeName , pipelineName , pipelineCommands , progressReporter ) {
28
+ async function _createRunnerProjectIfNotExists ( ) {
29
+ const [ err , projectExists ] = await to ( sdk . projects . getByName ( { name : INSTALLATION_DEFAULTS . PROJECT_NAME } ) ) ;
30
+ if ( _ . get ( err , 'message' , '' ) . includes ( 'not found' ) || ! projectExists ) {
31
+ await sdk . projects . create ( { projectName : INSTALLATION_DEFAULTS . PROJECT_NAME } ) ;
32
+ console . log ( `Project "${ colors . cyan ( INSTALLATION_DEFAULTS . PROJECT_NAME ) } " was created` ) ;
33
+ } else {
34
+ console . log ( `Project "${ colors . cyan ( INSTALLATION_DEFAULTS . PROJECT_NAME ) } " already exists` ) ;
35
+ }
36
+ }
37
+
38
+ async function getTestPipelineLink ( pipelineName , pipeline ) {
28
39
const url = _ . get ( sdk , 'config.context.url' , 'https://g.codefresh.io' ) ;
29
- console . log ( `Creating test pipeline with the name: "${ colors . cyan ( pipelineName ) } "` ) ;
30
- const pipeline = await sdk . pipelines . create ( { metadata : { name : pipelineName } } ) ;
40
+ let _pipeline = pipeline ;
41
+ if ( ! _pipeline ) {
42
+ const pipelines = await sdk . pipelines . list ( { id : `${ INSTALLATION_DEFAULTS . PROJECT_NAME } /${ pipelineName } ` } ) ;
43
+ if ( _ . get ( pipelines , 'docs.length' ) ) {
44
+ [ _pipeline ] = pipelines . docs ;
45
+ }
46
+ }
47
+
48
+ if ( _pipeline ) {
49
+ const cleanPipelineName = _pipeline . metadata . name . replace ( `${ INSTALLATION_DEFAULTS . PROJECT_NAME } /` , '' ) ; // remove the project prefix
50
+ return `${ url } /pipelines/edit/workflow?id=${ _pipeline . metadata . id } &pipeline=${ encodeURI ( cleanPipelineName ) } ` +
51
+ `&projects=${ encodeURI ( INSTALLATION_DEFAULTS . PROJECT_NAME ) } ` ;
52
+ }
53
+
54
+ return '' ;
55
+ }
56
+
57
+ async function createTestPipeline ( runtimeName , pipelineName , pipelineCommands , progressReporter ) {
58
+ await _createRunnerProjectIfNotExists ( ) ;
59
+ console . log ( `Creating test pipeline with the name: "${ colors . cyan ( pipelineName ) } " ` +
60
+ `in project "${ colors . cyan ( INSTALLATION_DEFAULTS . PROJECT_NAME ) } "` ) ;
61
+ const pipeline = await sdk . pipelines . create ( { metadata : { name : `${ INSTALLATION_DEFAULTS . PROJECT_NAME } /${ pipelineName } ` } } ) ;
31
62
32
63
pipeline . spec . runtimeEnvironment = {
33
64
name : runtimeName ,
@@ -42,7 +73,7 @@ async function createTestPipeline(runtimeName, pipelineName, pipelineCommands, p
42
73
} ;
43
74
44
75
await sdk . pipelines . replace (
45
- { name : pipelineName } ,
76
+ { name : ` ${ INSTALLATION_DEFAULTS . PROJECT_NAME } / ${ pipelineName } ` } ,
46
77
{
47
78
kind : pipeline . kind ,
48
79
spec : pipeline . spec ,
@@ -55,28 +86,17 @@ async function createTestPipeline(runtimeName, pipelineName, pipelineCommands, p
55
86
await to ( progressReporter . report ( PIPELINE_CREATED , STATUSES . SUCCESS ) ) ;
56
87
}
57
88
58
- const pipelineLink = ` ${ url } /pipelines/edit/workflow?id= ${ pipeline . metadata . id } &pipeline= ${ encodeURI ( pipeline . metadata . name ) } ` ;
89
+ const pipelineLink = await getTestPipelineLink ( undefined , pipeline ) ;
59
90
console . log ( `Created test pipeline with the name "${ colors . cyan ( pipelineName ) } ". Watch it here: ${ colors . blue ( pipelineLink ) } ` ) ;
60
91
61
92
return pipeline ;
62
93
}
63
94
64
- async function getTestPipelineLink ( pipelineName ) {
65
- const url = _ . get ( sdk , 'config.context.url' , 'https://g.codefresh.io' ) ;
66
- const pipelines = await sdk . pipelines . list ( { id : pipelineName } ) ;
67
- if ( _ . get ( pipelines , 'docs.length' ) ) {
68
- const pipeline = pipelines . docs [ 0 ] ;
69
- return `${ url } /pipelines/edit/workflow?id=${ pipeline . metadata . id } &pipeline=${ encodeURI ( pipeline . metadata . name ) } ` ;
70
- }
71
- return '' ;
72
- }
73
-
74
95
async function getTestPipeline ( pipelineName ) {
75
- const url = _ . get ( sdk , 'config.context.url' , 'https://g.codefresh.io' ) ;
76
- const pipelines = await sdk . pipelines . list ( { id : pipelineName } ) ;
96
+ const pipelines = await sdk . pipelines . list ( { id : `${ INSTALLATION_DEFAULTS . PROJECT_NAME } /${ pipelineName } ` } ) ;
77
97
if ( _ . get ( pipelines , 'docs.length' ) ) {
78
98
const pipeline = pipelines . docs [ 0 ] ;
79
- const pipelineLink = ` ${ url } /pipelines/edit/workflow?id= ${ pipeline . metadata . id } &pipeline= ${ encodeURI ( pipeline . metadata . name ) } ` ;
99
+ const pipelineLink = await getTestPipelineLink ( undefined , pipeline ) ;
80
100
console . log ( `Test pipeline with the name: "${ colors . cyan ( pipelineName ) } " already exists.` +
81
101
` Watch it here: ${ colors . blue ( pipelineLink ) } ` ) ;
82
102
return pipeline ;
@@ -86,6 +106,24 @@ async function getTestPipeline(pipelineName) {
86
106
return null ;
87
107
}
88
108
109
+ async function updateTestPipelineRuntime ( pipeline , runtimeName ) {
110
+ // update pipeline runtime
111
+ const _pipeline = pipeline ;
112
+ _pipeline . spec . runtimeEnvironment = {
113
+ name : runtimeName ,
114
+ } ;
115
+
116
+ await sdk . pipelines . replace (
117
+ { name : _pipeline . metadata . name } ,
118
+ {
119
+ kind : _pipeline . kind ,
120
+ spec : _pipeline . spec ,
121
+ metadata : _pipeline . metadata ,
122
+ version : _pipeline . version ,
123
+ } ,
124
+ ) ;
125
+ }
126
+
89
127
async function executeTestPipeline ( runtimeName , pipeline , progressReporter ) {
90
128
const url = _ . get ( sdk , 'config.context.url' , 'https://g.codefresh.io' ) ;
91
129
const pipelineName = _ . get ( pipeline , 'metadata.name' ) ;
@@ -226,6 +264,7 @@ module.exports = {
226
264
getRuntimeVersion,
227
265
createTestPipeline,
228
266
getTestPipeline,
267
+ updateTestPipelineRuntime,
229
268
executeTestPipeline,
230
269
createProgressBar,
231
270
getTestPipelineLink,
0 commit comments