@docupace/pipeline 1.0.82 → 1.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/merge/cli-merge-all.js +18 -4
- package/src/merge/cli-merge.js +87 -7
- package/src/merge/common.js +7 -0
- package/src/next/cli.js +11 -2
- package/src/next/deploy.js +67 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { readFileSync, existsSync, mkdirSync } from 'fs';
|
|
|
3
3
|
import { join, dirname } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { getExistingPRsWithDescription } from './pr.js';
|
|
6
|
+
import { BuildResults } from './common.js';
|
|
6
7
|
|
|
7
8
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
9
|
|
|
@@ -214,18 +215,22 @@ async function runPreparePhase(
|
|
|
214
215
|
|
|
215
216
|
// Log result based on exit code
|
|
216
217
|
switch (result.exitCode) {
|
|
217
|
-
case
|
|
218
|
+
case BuildResults.success:
|
|
218
219
|
console.log(`✅ ${configName}: Merge and build successful`);
|
|
219
220
|
break;
|
|
220
|
-
case
|
|
221
|
+
case BuildResults.unresolvedConflicts:
|
|
221
222
|
console.log(`⚠️ ${configName}: Merge has unresolved conflicts`);
|
|
222
223
|
break;
|
|
223
|
-
case
|
|
224
|
+
case BuildResults.buildFailed:
|
|
224
225
|
console.log(`⚠️ ${configName}: Build failed`);
|
|
225
226
|
break;
|
|
226
|
-
case
|
|
227
|
+
case BuildResults.noChanges:
|
|
227
228
|
console.log(`✅ ${configName}: No Changes`);
|
|
228
229
|
break;
|
|
230
|
+
case BuildResults.changeLogsExist:
|
|
231
|
+
console.log(`❌ Stopping Merge`);
|
|
232
|
+
process.exit(1);
|
|
233
|
+
break;
|
|
229
234
|
default:
|
|
230
235
|
console.log(
|
|
231
236
|
`❌ ${configName}: Unknown error (exit code: ${result.exitCode})`,
|
|
@@ -428,6 +433,15 @@ async function mergeAll(verbose = false) {
|
|
|
428
433
|
verbose,
|
|
429
434
|
);
|
|
430
435
|
|
|
436
|
+
if (
|
|
437
|
+
branchResult.success &&
|
|
438
|
+
branchResult.summary.successes > 0 &&
|
|
439
|
+
i < config.mergeBranches.length - 1
|
|
440
|
+
) {
|
|
441
|
+
console.log('Pausing before next merge');
|
|
442
|
+
await new Promise((res) => setTimeout(res, 90000));
|
|
443
|
+
}
|
|
444
|
+
|
|
431
445
|
if (!branchResult.success) {
|
|
432
446
|
console.log(`Exiting due to failure of one or more merges`);
|
|
433
447
|
process.exit(1);
|
package/src/merge/cli-merge.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createBitbucketPR } from './pr.js';
|
|
|
3
3
|
import { autoResolveConflicts } from './cli-resolve.js';
|
|
4
4
|
import { getPackageNames } from '../changeset/package-util.js';
|
|
5
5
|
import { writeChangesetFile } from '../changeset/create.js';
|
|
6
|
+
import { BuildResults } from './common.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Create and checkout merge branch from target branch
|
|
@@ -216,9 +217,27 @@ function mergeIntoTarget(
|
|
|
216
217
|
stdio: verbose ? 'inherit' : 'pipe',
|
|
217
218
|
});
|
|
218
219
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
// Delete local merge branch
|
|
221
|
+
try {
|
|
222
|
+
execSync(`git branch -d ${mergeBranchName}`, {
|
|
223
|
+
stdio: 'pipe',
|
|
224
|
+
});
|
|
225
|
+
if (verbose)
|
|
226
|
+
console.log(`🗑️ Deleted local merge branch: ${mergeBranchName}`);
|
|
227
|
+
} catch {
|
|
228
|
+
// Branch doesn't exist, which is fine
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Delete remote merge branch
|
|
232
|
+
try {
|
|
233
|
+
execSync(`git push origin --delete ${mergeBranchName}`, {
|
|
234
|
+
stdio: 'pipe',
|
|
235
|
+
});
|
|
236
|
+
if (verbose)
|
|
237
|
+
console.log(`🗑️ Deleted remote merge branch: ${mergeBranchName}`);
|
|
238
|
+
} catch (e) {
|
|
239
|
+
console.error('Failed to delete remote branch', e);
|
|
240
|
+
}
|
|
222
241
|
|
|
223
242
|
if (verbose) console.log(`✅ Successfully merged into ${targetBranch}`);
|
|
224
243
|
} else {
|
|
@@ -269,6 +288,62 @@ function cleanupFailedMerge(verbose = false) {
|
|
|
269
288
|
}
|
|
270
289
|
}
|
|
271
290
|
|
|
291
|
+
/**
|
|
292
|
+
* Check if source branch has uncommitted changesets
|
|
293
|
+
*/
|
|
294
|
+
function checkForUncommittedChangesets(sourceBranch, verbose = false) {
|
|
295
|
+
if (verbose)
|
|
296
|
+
console.log(`🔍 Checking for uncommitted changesets in ${sourceBranch}`);
|
|
297
|
+
|
|
298
|
+
// Store current branch
|
|
299
|
+
const currentBranch = execSync('git branch --show-current', {
|
|
300
|
+
encoding: 'utf8',
|
|
301
|
+
stdio: 'pipe',
|
|
302
|
+
}).trim();
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
// Checkout source branch
|
|
306
|
+
|
|
307
|
+
execSync(`git checkout ${sourceBranch}`, {
|
|
308
|
+
stdio: 'pipe',
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
execSync(`git pull`, {
|
|
312
|
+
stdio: verbose ? 'inherit' : 'pipe',
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Check for .md files in .changeset directory (excluding README.md)
|
|
316
|
+
try {
|
|
317
|
+
const changesetFiles = execSync(
|
|
318
|
+
'find .changeset -name "*.md" -not -name "README.md" 2>/dev/null | head -1',
|
|
319
|
+
{
|
|
320
|
+
encoding: 'utf8',
|
|
321
|
+
stdio: 'pipe',
|
|
322
|
+
},
|
|
323
|
+
).trim();
|
|
324
|
+
|
|
325
|
+
if (changesetFiles) {
|
|
326
|
+
console.log(
|
|
327
|
+
`❌ Cannot merge a branch where version has not been bumped. Found changesets in ${sourceBranch}`,
|
|
328
|
+
);
|
|
329
|
+
process.exit(BuildResults.changeLogsExist);
|
|
330
|
+
}
|
|
331
|
+
} catch (error) {
|
|
332
|
+
if (error.message.includes('Cannot merge')) {
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
// If find command fails (no .changeset directory), that's fine
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (verbose) console.log('✅ No uncommitted changesets found');
|
|
339
|
+
} finally {
|
|
340
|
+
// Return to original branch
|
|
341
|
+
execSync(`git checkout ${currentBranch}`, {
|
|
342
|
+
stdio: 'pipe',
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
272
347
|
export function setupMerge(program) {
|
|
273
348
|
program
|
|
274
349
|
.command('merge')
|
|
@@ -306,6 +381,11 @@ export function setupMerge(program) {
|
|
|
306
381
|
);
|
|
307
382
|
}
|
|
308
383
|
|
|
384
|
+
// Check for uncommitted changesets in source branch
|
|
385
|
+
if (!mergeFail && !mergeSuccess) {
|
|
386
|
+
checkForUncommittedChangesets(sourceBranch, verbose);
|
|
387
|
+
}
|
|
388
|
+
|
|
309
389
|
// 1. Create merge branch from target branch
|
|
310
390
|
const mergeBranchName = createMergeBranch(
|
|
311
391
|
sourceBranch,
|
|
@@ -327,7 +407,7 @@ export function setupMerge(program) {
|
|
|
327
407
|
console.log('✅ No changes to merge');
|
|
328
408
|
execSync(`git checkout ${targetBranch}`, { stdio: 'pipe' });
|
|
329
409
|
execSync(`git branch -d ${mergeBranchName}`, { stdio: 'pipe' });
|
|
330
|
-
process.exit(
|
|
410
|
+
process.exit(BuildResults.noChanges);
|
|
331
411
|
}
|
|
332
412
|
|
|
333
413
|
// 4. If conflicts, try auto-resolve
|
|
@@ -378,7 +458,7 @@ export function setupMerge(program) {
|
|
|
378
458
|
console.log(
|
|
379
459
|
`⚠️ Merge completed with unresolved conflicts on branch: ${mergeBranchName}`,
|
|
380
460
|
);
|
|
381
|
-
process.exit(
|
|
461
|
+
process.exit(BuildResults.unresolvedConflicts);
|
|
382
462
|
}
|
|
383
463
|
|
|
384
464
|
console.log(
|
|
@@ -420,9 +500,9 @@ export function setupMerge(program) {
|
|
|
420
500
|
});
|
|
421
501
|
}
|
|
422
502
|
if (buildPassed) {
|
|
423
|
-
process.exit(
|
|
503
|
+
process.exit(BuildResults.success);
|
|
424
504
|
} else {
|
|
425
|
-
process.exit(
|
|
505
|
+
process.exit(BuildResults.buildFailed);
|
|
426
506
|
}
|
|
427
507
|
} else {
|
|
428
508
|
// 6e) Build failed, dev mode, or prepare-only - create PR
|
package/src/next/cli.js
CHANGED
|
@@ -89,11 +89,19 @@ program
|
|
|
89
89
|
.requiredOption('-t, --to-env <toEnv>', 'Target environment')
|
|
90
90
|
.requiredOption('-F, --from-site <fromSite>', 'Source site')
|
|
91
91
|
.requiredOption('-T, --to-site <toSite>', 'Target site')
|
|
92
|
+
.option('-j, --jira-ticket <jiraTicket>', 'JIRA ticket', '')
|
|
92
93
|
.option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
|
|
93
94
|
.option('-C, --deploy-connect <deployConnect>', 'Deploy Connect', 'false')
|
|
94
95
|
.action(async (options) => {
|
|
95
|
-
const {
|
|
96
|
-
|
|
96
|
+
const {
|
|
97
|
+
fromEnv,
|
|
98
|
+
fromSite,
|
|
99
|
+
toEnv,
|
|
100
|
+
toSite,
|
|
101
|
+
deployCore,
|
|
102
|
+
deployConnect,
|
|
103
|
+
jiraTicket,
|
|
104
|
+
} = options;
|
|
97
105
|
await deployFromSite(
|
|
98
106
|
fromEnv,
|
|
99
107
|
fromSite,
|
|
@@ -101,6 +109,7 @@ program
|
|
|
101
109
|
toSite,
|
|
102
110
|
deployCore,
|
|
103
111
|
deployConnect,
|
|
112
|
+
jiraTicket,
|
|
104
113
|
);
|
|
105
114
|
});
|
|
106
115
|
|
package/src/next/deploy.js
CHANGED
|
@@ -9,6 +9,7 @@ import { appInfo, environmentConfig, getRepUrl } from './config.js';
|
|
|
9
9
|
import { copy2 } from './copy.js';
|
|
10
10
|
import { gitDescribeToSemver } from './git-to-semver.js';
|
|
11
11
|
import { deployConnect, deployCore } from './jenkins.js';
|
|
12
|
+
import { makeJiraRequest } from './jira.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Clone the repository, read the YAML file, and return the parsed data and file paths.
|
|
@@ -557,7 +558,73 @@ export async function deployFromSite(
|
|
|
557
558
|
toSite,
|
|
558
559
|
isDeployCore,
|
|
559
560
|
isDeployConnect,
|
|
561
|
+
jiraTicket,
|
|
560
562
|
) {
|
|
563
|
+
console.log(
|
|
564
|
+
`Deploying changes from ${fromSite} in ${fromEnv} to ${toSite} in ${toEnv}${jiraTicket ? ` approved by JIRA ticket ${jiraTicket}` : ''}`,
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
if (jiraTicket) {
|
|
568
|
+
try {
|
|
569
|
+
const response = await makeJiraRequest(`/rest/api/2/issue/${jiraTicket}`);
|
|
570
|
+
const docupacecInstance = response.fields.customfield_10045.value;
|
|
571
|
+
const siteUrl = response.fields.customfield_10041;
|
|
572
|
+
const status = response.fields.status.name;
|
|
573
|
+
const jiraBaseUrl = response.self.split('/rest/api')[0];
|
|
574
|
+
const jiraTicketUrl = `${jiraBaseUrl}/browse/${response.key}`;
|
|
575
|
+
|
|
576
|
+
console.log(`Docupace Instance: ${docupacecInstance}`);
|
|
577
|
+
console.log(`Docupace Site URL: ${siteUrl}`);
|
|
578
|
+
console.log(`JIRA Ticket Status: ${status}`);
|
|
579
|
+
console.log(`JIRA Ticket URL: ${jiraTicketUrl}`);
|
|
580
|
+
|
|
581
|
+
const allowedStatuses = ['To Do', 'In Progress'];
|
|
582
|
+
if (!allowedStatuses.includes(status)) {
|
|
583
|
+
console.error(
|
|
584
|
+
`The JIRA ticket status must be "To Do" or "In Progress", but got "${status}"`,
|
|
585
|
+
);
|
|
586
|
+
console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
|
|
587
|
+
process.exit(1);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (!siteUrl.includes(toSite)) {
|
|
591
|
+
console.error(
|
|
592
|
+
`The toSite "${toSite}" must be present in the Docupace Site URL: "${siteUrl}"`,
|
|
593
|
+
);
|
|
594
|
+
console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
|
|
595
|
+
process.exit(1);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (toEnv === 'prod') {
|
|
599
|
+
if (docupacecInstance !== 'Production') {
|
|
600
|
+
console.error(
|
|
601
|
+
`The deployment to prod environment requires Docupace Instance to be "Production", but got "${docupacecInstance}"`,
|
|
602
|
+
);
|
|
603
|
+
console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
|
|
604
|
+
process.exit(1);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
if (fromSite !== toSite) {
|
|
608
|
+
console.error(
|
|
609
|
+
`The deployment to prod environment requires fromSite and toSite to be equal, but fromSite: "${fromSite}", toSite: "${toSite}"`,
|
|
610
|
+
);
|
|
611
|
+
console.error(`Please check the JIRA ticket: ${jiraTicketUrl}`);
|
|
612
|
+
process.exit(1);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
console.log('Production deployment validations passed');
|
|
616
|
+
}
|
|
617
|
+
} catch (error) {
|
|
618
|
+
console.error(`Failed to make a Jira request: ${error.message}`);
|
|
619
|
+
process.exit(1);
|
|
620
|
+
}
|
|
621
|
+
} else if (toEnv === 'prod') {
|
|
622
|
+
console.error(
|
|
623
|
+
'The deployment to prod environment requires a JIRA ticket to be provided',
|
|
624
|
+
);
|
|
625
|
+
process.exit(1);
|
|
626
|
+
}
|
|
627
|
+
|
|
561
628
|
if (isDeployCore === 'true') {
|
|
562
629
|
const branchName = await getCoreBranchName(fromEnv, fromSite);
|
|
563
630
|
|