Browse Source

Fixed use instancename

pull/4/head
chess 3 years ago
parent
commit
e5257ec878
2 changed files with 94 additions and 52 deletions
  1. 48
    27
      i.js
  2. 46
    25
      index.js

+ 48
- 27
i.js View File

/* Version: 1.0.0 - May 12, 2021 19:58:01 */
/* Version: 1.0.0 - May 14, 2021 00:18:25 */
'use strict'; 'use strict';


var path$1 = require('path'); var path$1 = require('path');






const BUILD_VERSION = 'Version: 1.0.0 - built on May 12, 2021 19:58:01';
const BUILD_VERSION = 'Version: 1.0.0 - built on May 14, 2021 00:18:25';
const runtimestamp = (new Date()).getTime(); const runtimestamp = (new Date()).getTime();
function getVersion() { return BUILD_VERSION; } function getVersion() { return BUILD_VERSION; }
console.log(getVersion()); console.log(getVersion());
return promise = promise.then(()=>{ return elxr.getpulltask(def)() }).catch(e => { console.error( 'performPullOrCloneForBranch : Failed ' + e );}) return promise = promise.then(()=>{ return elxr.getpulltask(def)() }).catch(e => { console.error( 'performPullOrCloneForBranch : Failed ' + e );})
}; };


var performCloneAndCheckout = null;
// cant use git checkout -b it fails when branch already exists. // cant use git checkout -b it fails when branch already exists.
var performCheckout = (def) => {
var performCheckout = performCloneAndCheckout = (def) => {
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true }) if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true })
return performPullOrCloneForBranch(def).then(()=>{ return performPullOrCloneForBranch(def).then(()=>{
}) })
}; };


if (runconfig.NODE_ENV === 'development') performCheckout = (def) => { return performPullOrCloneForBranch(def) };
var mergeSources = {
'development': null,
'test': 'master',
'production': 'master'
};
var mergesource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV];

// Checkout is reduced to pull provided the current branch is the targetbranch
if(branch === mergesource) performCheckout = (def) => {
var dscoverbranchcmd = gitops.getdiscoverbranchcmd(repo);
return nodeShellExec.apply(null, dscoverbranchcmd(repo)).then(__branch=>{
if(branch === __branch) return performCloneAndCheckout(def)
return performPullOrCloneForBranch(def)
})
.catch((e) => { console.error(e); return { error: true, message: repo } })
};
// else performCheckout = (def) => { return performPullOrCloneForBranch(def) }


var performPullAll = (def) => { var performPullAll = (def) => {
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true }) if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true })
, title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${def.repo}` , title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${def.repo}`
}).catch((e) => { console.error(e); return { error: true, message: def.repo } }) }).catch((e) => { console.error(e); return { error: true, message: def.repo } })
}; };

var mergeSources = {
'development': null,
'test': 'master',
'production': 'master'
};
var excludeCheckouts = Object.assign(exludeMergeRepos); var excludeCheckouts = Object.assign(exludeMergeRepos);
delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`]; delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`];
delete excludeCheckouts[`cihsr-config-${runconfig.NODE_ENV}`]; delete excludeCheckouts[`cihsr-config-${runconfig.NODE_ENV}`];


var mergesource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV];
var performMerge = (def) => { var performMerge = (def) => {
if (exludeMergeRepos[def.repo]) return Promise.resolve({ 'skipped': true }) if (exludeMergeRepos[def.repo]) return Promise.resolve({ 'skipped': true })
return nodeShellExec('git', ['merge', mergesource], { return nodeShellExec('git', ['merge', mergesource], {
, runas: processedArgs.runas , runas: processedArgs.runas
}).catch((e) => { console.error(e); }) }).catch((e) => { console.error(e); })
}; };
if (runconfig.NODE_ENV === 'development') performMerge = () => { return Promise.resolve(true) };
if(!mergesource || branch === mergesource) performMerge = () => { return Promise.resolve(true) };


// var performRepoOperation = function(def) { // var performRepoOperation = function(def) {
// elevatedRunasRepos.map((repo) => enqueueCheckout({ repo, branch: def.branch, requiresElevation : true })) // elevatedRunasRepos.map((repo) => enqueueCheckout({ repo, branch: def.branch, requiresElevation : true }))
//Switch to target branch //Switch to target branch
return any(gitRepos.map((repodef) => { return performCheckout({ repo : repodef.repo, branch}).catch(e=>{ console.log(e); }) } )) return any(gitRepos.map((repodef) => { return performCheckout({ repo : repodef.repo, branch}).catch(e=>{ console.log(e); }) } ))
// pull or clone target branch // pull or clone target branch
.then(() => any(gitRepos.map((repo) => performPullAll(repo))) )
.then(() => {
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(gitRepos.map((repo) => performPullAll(repo)))
})
// switch to source branch // switch to source branch
.then( () => { .then( () => {
if(mergesource) return any(gitRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource})))
else return Promise.resolve(true) // Dont do anything if there is no source to merge from.
if(!mergesource || branch === mergesource ) return Promise.resolve(true) // Dont do anything if there is no source to merge from.
return any(gitRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource})))
}) })
//Pull on merge source branch //Pull on merge source branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource ) return Promise.resolve(true)
return any(gitRepos.map((repo) => performPullAll(repo))) return any(gitRepos.map((repo) => performPullAll(repo)))
}) })
//Switch to target branch //Switch to target branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource ) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch}))) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch})))
}) })
.then( //Merge source branch to target branch .then( //Merge source branch to target branch
() => { () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(gitRepos.map((repo) => performMerge( repo ))).catch(err => { console.error('error in performMerge ' + err); }) return any(gitRepos.map((repo) => performMerge( repo ))).catch(err => { console.error('error in performMerge ' + err); })
}) })
}) })
} }
return any(tasks).then(()=>{ return any(tasks).then(()=>{
// checkout target branch
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true}))) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true})))
// pull or clone target branch // pull or clone target branch
.then( () => any(elevatedRunasRepos.map((repo) => performPullAll(repo))) )
.then(() => {
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repo) => performPullAll(repo)))
})
// switch to source branch // switch to source branch
.then( () => { .then( () => {
if(mergesource) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource, requiresElevation : true})))
else return Promise.resolve(true) // Dont do anything if there is no source to merge from.
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource, requiresElevation : true})))
}) })
//Pull on merge source branch //Pull on merge source branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performPullAll({repo : repodef.repo, requiresElevation : true }))) return any(elevatedRunasRepos.map((repodef) => performPullAll({repo : repodef.repo, requiresElevation : true })))
}) })
//Switch to target branch //Switch to target branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true}))) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true})))
}) })
.then( //Merge source branch to target branch .then( //Merge source branch to target branch
() => { () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performMerge({ repo : repodef.repo, requiresElevation : true }))).catch(err => { console.error('error in performMerge ' + err); }) return any(elevatedRunasRepos.map((repodef) => performMerge({ repo : repodef.repo, requiresElevation : true }))).catch(err => { console.error('error in performMerge ' + err); })
}) })
.then(() => { .then(() => {
if(def.elevatedRepos){ if(def.elevatedRepos){
elevatedpulltasks = function() { elevatedpulltasks = function() {
return any(def.elevatedRepos.map((def) => performPull(def.repo))).then(() => { return any(def.elevatedRepos.map((def) => performPull(def.repo))).then(() => {
fs.writeFileSync('run.done', 'success');
// fs.writeFileSync('run.done', 'success')
return true; return true;
}).catch(() => { fs.writeFileSync('run.done', 'error'); })
}).catch((e) => {
console.error(e);
fs.writeFileSync('run.done', 'error');
})
}; };
} }
if(def.reqularRepos) { if(def.reqularRepos) {

+ 46
- 25
index.js View File

return promise = promise.then(()=>{ return elxr.getpulltask(def)() }).catch(e => { console.error( 'performPullOrCloneForBranch : Failed ' + e )}) return promise = promise.then(()=>{ return elxr.getpulltask(def)() }).catch(e => { console.error( 'performPullOrCloneForBranch : Failed ' + e )})
} }


var performCloneAndCheckout = null;
// cant use git checkout -b it fails when branch already exists. // cant use git checkout -b it fails when branch already exists.
var performCheckout = (def) => {
var performCheckout = performCloneAndCheckout = (def) => {
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true }) if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true })
return performPullOrCloneForBranch(def).then(()=>{ return performPullOrCloneForBranch(def).then(()=>{
queue.push(function(){ return task(def)}.bind(def)); queue.push(function(){ return task(def)}.bind(def));
} }


if (runconfig.NODE_ENV === 'development') performCheckout = (def) => { return performPullOrCloneForBranch(def) }
var mergeSources = {
'development': null,
'test': 'master',
'production': 'master'
}
var mergesource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]

// Checkout is reduced to pull provided the current branch is the targetbranch
if(branch === mergesource) performCheckout = (def) => {
var dscoverbranchcmd = gitops.getdiscoverbranchcmd(repo)
return nodeShellExec.apply(null, dscoverbranchcmd(repo)).then(__branch=>{
if(branch === __branch) return performCloneAndCheckout(def)
return performPullOrCloneForBranch(def)
})
.catch((e) => { console.error(e); return { error: true, message: repo } })
}
// else performCheckout = (def) => { return performPullOrCloneForBranch(def) }


var performPullAll = (def) => { var performPullAll = (def) => {
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true }) if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true })
, title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${def.repo}` , title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${def.repo}`
}).catch((e) => { console.error(e); return { error: true, message: def.repo } }) }).catch((e) => { console.error(e); return { error: true, message: def.repo } })
} }

var mergeSources = {
'development': null,
'test': 'master',
'production': 'master'
}
var excludeCheckouts = Object.assign(exludeMergeRepos) var excludeCheckouts = Object.assign(exludeMergeRepos)
delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`] delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`]
delete excludeCheckouts[`cihsr-config-${runconfig.NODE_ENV}`] delete excludeCheckouts[`cihsr-config-${runconfig.NODE_ENV}`]


var mergesource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]
var performMerge = (def) => { var performMerge = (def) => {
if (exludeMergeRepos[def.repo]) return Promise.resolve({ 'skipped': true }) if (exludeMergeRepos[def.repo]) return Promise.resolve({ 'skipped': true })
return nodeShellExec('git', ['merge', mergesource], { return nodeShellExec('git', ['merge', mergesource], {
, runas: processedArgs.runas , runas: processedArgs.runas
}).catch((e) => { console.error(e) }) }).catch((e) => { console.error(e) })
} }
if (runconfig.NODE_ENV === 'development') performMerge = () => { return Promise.resolve(true) }
if(!mergesource || branch === mergesource) performMerge = () => { return Promise.resolve(true) }


// var performRepoOperation = function(def) { // var performRepoOperation = function(def) {
// elevatedRunasRepos.map((repo) => enqueueCheckout({ repo, branch: def.branch, requiresElevation : true })) // elevatedRunasRepos.map((repo) => enqueueCheckout({ repo, branch: def.branch, requiresElevation : true }))
//Switch to target branch //Switch to target branch
return any(gitRepos.map((repodef) => { return performCheckout({ repo : repodef.repo, branch}).catch(e=>{ console.log(e); }) } )) return any(gitRepos.map((repodef) => { return performCheckout({ repo : repodef.repo, branch}).catch(e=>{ console.log(e); }) } ))
// pull or clone target branch // pull or clone target branch
.then(() => any(gitRepos.map((repo) => performPullAll(repo))) )
.then(() => {
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(gitRepos.map((repo) => performPullAll(repo)))
})
// switch to source branch // switch to source branch
.then( () => { .then( () => {
if(mergesource) return any(gitRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource})))
else return Promise.resolve(true) // Dont do anything if there is no source to merge from.
if(!mergesource || branch === mergesource ) return Promise.resolve(true) // Dont do anything if there is no source to merge from.
return any(gitRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource})))
}) })
//Pull on merge source branch //Pull on merge source branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource ) return Promise.resolve(true)
return any(gitRepos.map((repo) => performPullAll(repo))) return any(gitRepos.map((repo) => performPullAll(repo)))
}) })
//Switch to target branch //Switch to target branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource ) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch}))) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch})))
}) })
.then( //Merge source branch to target branch .then( //Merge source branch to target branch
() => { () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(gitRepos.map((repo) => performMerge( repo ))).catch(err => { console.error('error in performMerge ' + err) }) return any(gitRepos.map((repo) => performMerge( repo ))).catch(err => { console.error('error in performMerge ' + err) })
}) })
}) })
} }
return any(tasks).then(()=>{ return any(tasks).then(()=>{
// checkout target branch
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true}))) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true})))
// pull or clone target branch // pull or clone target branch
.then( () => any(elevatedRunasRepos.map((repo) => performPullAll(repo))) )
.then(() => {
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repo) => performPullAll(repo)))
})
// switch to source branch // switch to source branch
.then( () => { .then( () => {
if(mergesource) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource, requiresElevation : true})))
else return Promise.resolve(true) // Dont do anything if there is no source to merge from.
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource, requiresElevation : true})))
}) })
//Pull on merge source branch //Pull on merge source branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performPullAll({repo : repodef.repo, requiresElevation : true }))) return any(elevatedRunasRepos.map((repodef) => performPullAll({repo : repodef.repo, requiresElevation : true })))
}) })
//Switch to target branch //Switch to target branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true}))) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true})))
}) })
.then( //Merge source branch to target branch .then( //Merge source branch to target branch
() => { () => {
if(!mergesource) return Promise.resolve(true)
if(!mergesource || branch === mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repodef) => performMerge({ repo : repodef.repo, requiresElevation : true }))).catch(err => { console.error('error in performMerge ' + err) }) return any(elevatedRunasRepos.map((repodef) => performMerge({ repo : repodef.repo, requiresElevation : true }))).catch(err => { console.error('error in performMerge ' + err) })
}) })
.then(() => { .then(() => {
if(def.elevatedRepos){ if(def.elevatedRepos){
elevatedpulltasks = function() { elevatedpulltasks = function() {
return any(def.elevatedRepos.map((def) => performPull(def.repo))).then(() => { return any(def.elevatedRepos.map((def) => performPull(def.repo))).then(() => {
fs.writeFileSync('run.done', 'success')
// fs.writeFileSync('run.done', 'success')
return true; return true;
}).catch(() => { fs.writeFileSync('run.done', 'error') })
}).catch((e) => {
console.error(e)
fs.writeFileSync('run.done', 'error')
})
} }
} }
if(def.reqularRepos) { if(def.reqularRepos) {

Loading…
Cancel
Save