@docupace/pipeline 1.0.7-beta.2 → 1.0.8-6.xray

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.
Files changed (64) hide show
  1. package/README.md +136 -0
  2. package/bin/azuread_update_callbacks_for_app.sh +58 -0
  3. package/bin/xray.sh +273 -0
  4. package/bitbucket-pipelines.yml +142 -0
  5. package/eslint.config.js +25 -2
  6. package/jest.config.js +15 -0
  7. package/next/execute.sh +8 -2
  8. package/package.json +23 -7
  9. package/src/auth0/alias.js +79 -0
  10. package/src/auth0/alias.test.js +172 -0
  11. package/src/auth0/cli.js +82 -0
  12. package/src/auth0/configure.js +902 -0
  13. package/src/auth0/configure.test.js +167 -0
  14. package/src/auth0/export.js +48 -0
  15. package/src/auth0/export.test.js +103 -0
  16. package/src/auth0/metadata.js +141 -0
  17. package/src/auth0/metadata.test.js +186 -0
  18. package/src/auth0/vault.js +60 -0
  19. package/src/auth0/vault.test.js +134 -0
  20. package/src/changeset/changelog-wiki.js +328 -0
  21. package/src/changeset/changeset-config.js +34 -0
  22. package/src/changeset/cli.js +151 -195
  23. package/src/changeset/create.js +215 -0
  24. package/src/changeset/package-util.js +87 -0
  25. package/src/changeset/util.js +43 -0
  26. package/src/changeset/validate.js +45 -1
  27. package/src/changeset/version.js +102 -0
  28. package/src/jenkins/setParams.groovy +1 -2
  29. package/src/jfrog/xray-scan.yaml +29 -0
  30. package/src/lib/merge-driver.js +204 -0
  31. package/src/merge/cli-merge-all.js +521 -0
  32. package/src/merge/cli-merge.js +572 -0
  33. package/src/merge/cli-resolve.js +399 -0
  34. package/src/merge/cli.js +38 -0
  35. package/src/merge/common.js +7 -0
  36. package/src/merge/merge-changelog.js +87 -0
  37. package/src/merge/merge-package.js +106 -0
  38. package/src/merge/merge-types.js +82 -0
  39. package/src/merge/pr.js +231 -0
  40. package/src/micro/cli.js +51 -0
  41. package/src/micro/ms-deploy.js +451 -0
  42. package/src/micro/ms-publish.js +186 -0
  43. package/src/next/alias.js +53 -0
  44. package/src/next/apache.js +81 -0
  45. package/src/next/cli.js +111 -15
  46. package/src/next/config.js +72 -7
  47. package/src/next/connect.js +226 -0
  48. package/src/next/copy.js +32 -1
  49. package/src/next/deploy.js +514 -75
  50. package/src/next/git-to-semver.js +79 -0
  51. package/src/next/haproxy.js +76 -0
  52. package/src/next/jenkins.js +3 -2
  53. package/src/next/jira.js +84 -0
  54. package/src/next/logger.js +17 -0
  55. package/src/next/pipline.js +0 -1
  56. package/src/next/publish.js +53 -30
  57. package/src/next/test.js +5 -0
  58. package/src/next/util.js +95 -0
  59. package/src/next/vault.js +45 -0
  60. package/terraform/apply.sh +41 -0
  61. package/terraform/import.sh +111 -0
  62. package/terraform/init.sh +78 -0
  63. package/terraform/plan.sh +95 -0
  64. package/terraform/validate.sh +17 -0
@@ -0,0 +1,87 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ export function getPackageNames(rootPath = '.') {
5
+ const appsDir = path.join(rootPath, 'apps');
6
+ const packagesDir = path.join(rootPath, 'packages');
7
+ const rootPackageJson = path.join(rootPath, 'package.json');
8
+
9
+ // Check if this is a monorepo (has apps and/or packages directories)
10
+ const hasAppsDir =
11
+ fs.existsSync(appsDir) && fs.statSync(appsDir).isDirectory();
12
+ const hasPackagesDir =
13
+ fs.existsSync(packagesDir) && fs.statSync(packagesDir).isDirectory();
14
+
15
+ if (hasAppsDir || hasPackagesDir) {
16
+ // This is a monorepo
17
+ const packages = [];
18
+
19
+ // Get packages from apps directory
20
+ if (hasAppsDir) {
21
+ const appsPackages = getPackagesFromDirectory(appsDir);
22
+ packages.push(...appsPackages);
23
+ }
24
+
25
+ // Get packages from packages directory
26
+ if (hasPackagesDir) {
27
+ const packagesPackages = getPackagesFromDirectory(packagesDir);
28
+ packages.push(...packagesPackages);
29
+ }
30
+
31
+ return packages;
32
+ } else {
33
+ // This is not a monorepo, return single package
34
+ if (fs.existsSync(rootPackageJson)) {
35
+ try {
36
+ const packageJson = JSON.parse(
37
+ fs.readFileSync(rootPackageJson, 'utf8'),
38
+ );
39
+ return packageJson.name
40
+ ? [{ name: packageJson.name, path: rootPath, content: packageJson }]
41
+ : [];
42
+ } catch (error) {
43
+ console.error('Error reading root package.json:', error);
44
+ return [];
45
+ }
46
+ }
47
+ return [];
48
+ }
49
+ }
50
+
51
+ function getPackagesFromDirectory(dirPath) {
52
+ const packages = [];
53
+
54
+ try {
55
+ const items = fs.readdirSync(dirPath);
56
+
57
+ for (const item of items) {
58
+ const itemPath = path.join(dirPath, item);
59
+ const packageJsonPath = path.join(itemPath, 'package.json');
60
+
61
+ // Check if item is a directory and has package.json
62
+ if (
63
+ fs.statSync(itemPath).isDirectory() &&
64
+ fs.existsSync(packageJsonPath)
65
+ ) {
66
+ try {
67
+ const packageJson = JSON.parse(
68
+ fs.readFileSync(packageJsonPath, 'utf8'),
69
+ );
70
+ if (packageJson.name) {
71
+ packages.push({
72
+ name: packageJson.name,
73
+ path: itemPath,
74
+ content: packageJson,
75
+ });
76
+ }
77
+ } catch (error) {
78
+ console.error(`Error reading package.json in ${itemPath}:`, error);
79
+ }
80
+ }
81
+ }
82
+ } catch (error) {
83
+ console.error(`Error reading directory ${dirPath}:`, error);
84
+ }
85
+
86
+ return packages;
87
+ }
@@ -0,0 +1,43 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+
4
+ async function fileExists(filePath) {
5
+ try {
6
+ await fs.promises.access(filePath);
7
+ return true;
8
+ } catch {
9
+ return false;
10
+ }
11
+ }
12
+ export async function getMainPackage() {
13
+ const mainModulePath = process.cwd();
14
+ return getPackage(mainModulePath);
15
+ }
16
+
17
+ export async function getPackage(mainModulePath) {
18
+ if (mainModulePath) {
19
+ const packageJsonPath = path.join(mainModulePath, 'package.json');
20
+ if (await fileExists(packageJsonPath)) {
21
+ const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
22
+ const packageJson = JSON.parse(fileContent);
23
+ return packageJson;
24
+ }
25
+ }
26
+ throw new Error('Main package.json not found');
27
+ }
28
+
29
+ /**
30
+ * Locates and extracts a JIRA Ticket ID from a given string.
31
+ * <p>
32
+ * The JIRA Ticket ID is expected to follow the pattern of uppercase letters (at least two) followed by a hyphen and digits (e.g., DC-1234, INFP-9).
33
+ * @param str the string to search for a JIRA ticket ID
34
+ * @returns {JIRA-TicketID|null}
35
+ */
36
+ export function findJiraTicketId(str) {
37
+ if (!str) {
38
+ return null;
39
+ }
40
+ const regex = /([A-Z]{2,}-\d+)/;
41
+ const matches = str.match(regex);
42
+ return matches ? matches[0] : null;
43
+ }
@@ -1,7 +1,51 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { $ } from 'zx';
3
4
 
4
- export async function validateChangesets(directoryPath) {
5
+ import { isMonoRepo, setGitInfo } from '../next/util.js';
6
+ import { versionStatus } from './version.js';
7
+
8
+ const CHANGESET_DIR = '.changeset';
9
+
10
+ function areArraysEqualIgnoringOrder(arr1, arr2) {
11
+ if (arr1.length !== arr2.length) return false;
12
+
13
+ const sortedA = [...arr1].sort();
14
+ const sortedB = [...arr2].sort();
15
+
16
+ return sortedA.every((element, index) => element === sortedB[index]);
17
+ }
18
+
19
+ export async function validateChangesets() {
20
+ await setGitInfo();
21
+ const destBranch = process.env.BITBUCKET_PR_DESTINATION_BRANCH;
22
+ await $`git fetch origin ${destBranch}:${destBranch}`;
23
+ let releases;
24
+
25
+ try {
26
+ console.log('🔍 Validating changesets...');
27
+ releases = await versionStatus(destBranch);
28
+ } catch (e) {
29
+ console.error(
30
+ '❌ No changeset found. Please add a changeset to this PR. Please see more information at https://docupacellc.atlassian.net/wiki/spaces/PM/pages/1350893571/Creating+changesets+for+Docupace+Next',
31
+ e,
32
+ );
33
+ process.exit(-1);
34
+ }
35
+
36
+ if (!['master', 'main'].includes(destBranch)) {
37
+ if (releases.some((item) => item.type !== 'patch')) {
38
+ console.error(
39
+ '❌ A changeset must be a patch for change to a release branch',
40
+ );
41
+ process.exit(-1);
42
+ }
43
+ }
44
+
45
+ console.log('✅ Changeset validation passed.');
46
+ }
47
+
48
+ export async function validateChangesetPath(directoryPath) {
5
49
  try {
6
50
  // Step 1: Read the directory for md files excluding README.md
7
51
  const allFiles = fs.readdirSync(directoryPath);
@@ -0,0 +1,102 @@
1
+ import { setGitInfo } from '../next/util.js';
2
+ import { $ } from 'zx';
3
+ import fs from 'fs';
4
+ import { updateComponentVersion } from '../next/jira.js';
5
+ import { findJiraTicketId } from './util.js';
6
+ import { revertBaseBranch, updateBaseBranch } from './changeset-config.js';
7
+ import semver from 'semver';
8
+
9
+ const changeSetPackage = `{
10
+ "name": "changeset-package",
11
+ "version": "1.0.0",
12
+ "description": "",
13
+ "scripts": {
14
+ },
15
+ "type": "module",
16
+ "keywords": [],
17
+ "author": "",
18
+ "license": "ISC",
19
+ "dependencies": {},
20
+ "devDependencies": {
21
+ "@changesets/cli": "^2.27.10"
22
+ }
23
+ }
24
+ `;
25
+
26
+ export function toShortVersion(version) {
27
+ const parsed = semver.parse(version);
28
+ if (!parsed) return null;
29
+ return `${parsed.major}.${parsed.minor}`;
30
+ }
31
+
32
+ export async function versionStatus(sinceBranch) {
33
+ const outputPath = './changeset-output.json';
34
+
35
+ if (sinceBranch) {
36
+ await $`pnpm changeset status --output=${outputPath} --since=${sinceBranch}`;
37
+ } else {
38
+ await $`pnpm changeset status --output=${outputPath}`;
39
+ }
40
+
41
+ // Read the file and parse JSON
42
+ const jsonOutput = JSON.parse(await fs.promises.readFile(outputPath, 'utf8'));
43
+
44
+ await fs.promises.rm(outputPath);
45
+ return jsonOutput.releases;
46
+ }
47
+
48
+ export async function versionCommand(closeVersion = false) {
49
+ console.log('📦 Running Changeset versioning...');
50
+ if (!process.env.IS_DEV) {
51
+ await setGitInfo();
52
+ await $`mv package.json package.json.bak`;
53
+ await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
54
+ await fs.promises.writeFile('package.json', changeSetPackage);
55
+ await $`pnpm install`;
56
+ await $`rm package.json pnpm-lock.yaml`;
57
+ await $`mv package.json.bak package.json`;
58
+ await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
59
+ }
60
+ if (closeVersion) {
61
+ await $`pnpm changeset pre exit`;
62
+ }
63
+
64
+ let originalBaseBranch;
65
+ try {
66
+ originalBaseBranch = updateBaseBranch();
67
+ const releases = await versionStatus();
68
+ revertBaseBranch(originalBaseBranch);
69
+ await $`pnpm changeset version`;
70
+
71
+ return releases;
72
+ } catch {
73
+ revertBaseBranch(originalBaseBranch);
74
+ return [];
75
+ }
76
+ }
77
+
78
+ export async function updateJiraWithVersion(releases) {
79
+ const lastCommit = (await $`git log -1 --pretty=%B`).stdout.trim();
80
+ console.log(`Last commit '${lastCommit}' being processed to get Jira ticket`);
81
+
82
+ const jiraTicketId = findJiraTicketId(lastCommit);
83
+
84
+ // If we have all the necessary data, update the component version in Jira
85
+ if (jiraTicketId) {
86
+ for (const release of releases) {
87
+ try {
88
+ await updateComponentVersion(
89
+ jiraTicketId,
90
+ release.name,
91
+ release.newVersion,
92
+ );
93
+ } catch (error) {
94
+ console.error(
95
+ `Failed to update Jira component version: ${error.message}`,
96
+ );
97
+ }
98
+ }
99
+ }
100
+
101
+ console.log('✅ Changeset versioning complete.');
102
+ }
@@ -1,6 +1,5 @@
1
1
  import groovy.json.JsonSlurper
2
-
3
- import hudson.model.*;
2
+ import hudson.model.*
4
3
 
5
4
  def build = Thread.currentThread().executable
6
5
  def params = build.getEnvironment(listener)
@@ -0,0 +1,29 @@
1
+ definitions:
2
+ steps:
3
+ - step: &xray
4
+ name: JFrog Xray Dependency Scan (TABLE report only)
5
+ runs-on:
6
+ - self.hosted
7
+ - linux.shell
8
+ - onprem
9
+ script:
10
+ - curl -fL https://install-cli.jfrog.io | sh
11
+ - jf --version
12
+ - jf config add scan1 --url=$JFROG_XRAY_URL --user=$JFROG_XRAY_USER --access-token=$JFROG_XRAY_PASSWORD
13
+ - jf c show
14
+ - mkdir -p xray-report
15
+ - jf audit . --format=table > xray-report/xray-audit.txt
16
+ - jf config remove scan1
17
+ artifacts:
18
+ - xray-report/xray-audit.txt
19
+ - step: &version-step
20
+ runs-on:
21
+ - self.hosted
22
+ - linux.shell
23
+ - onprem
24
+ name: Version, Tag
25
+ caches:
26
+ - gradle
27
+ script:
28
+ - npm config set //registry.npmjs.org/:_authToken $DOCUPACE_NPM_TOKEN
29
+ - eval $PIPELINE_CMD_VERSION_CHANGESET
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import { execSync } from 'child_process';
5
+ import path from 'path';
6
+ import { fileURLToPath } from 'url';
7
+
8
+ // Get __dirname equivalent in ESM
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ /**
13
+ * Default merge logic function - can be overridden
14
+ * @param {string} headContent - The content from HEAD (current branch)
15
+ * @param {string} branchContent - The content from the incoming branch
16
+ * @returns {string} - The merged content
17
+ * @throws {Error} - If the conflict cannot be automatically merged
18
+ */
19
+ export function defaultMergeLogic(headContent, branchContent) {
20
+ // Default implementation - throws error
21
+ // Users should provide their own implementation
22
+ throw new Error(
23
+ 'No merge logic provided - please pass a custom merge function',
24
+ );
25
+ }
26
+
27
+ /**
28
+ * Main merge driver function
29
+ * @param {string} filePath - Path to the file with conflicts
30
+ * @param {Function} customMergeLogic - Custom merge function (optional)
31
+ * @returns {Promise<{success: boolean, totalConflicts: number, resolvedConflicts: number, hasUnresolvedConflicts: boolean}>}
32
+ */
33
+ export async function mergeDriver(filePath, customMergeLogic = null) {
34
+ // Use provided merge logic or fall back to default
35
+ const mergeLogic = customMergeLogic || defaultMergeLogic;
36
+
37
+ if (!filePath) {
38
+ throw new Error('File path is required');
39
+ }
40
+
41
+ // Check if file exists
42
+ if (!fs.existsSync(filePath)) {
43
+ throw new Error(`File not found: ${filePath}`);
44
+ }
45
+
46
+ console.log(`Processing conflicts in: ${filePath}`);
47
+
48
+ // Read the file content
49
+ let fileContent;
50
+ try {
51
+ fileContent = fs.readFileSync(filePath, 'utf8');
52
+ } catch (error) {
53
+ throw new Error(`Error reading file: ${error.message}`);
54
+ }
55
+
56
+ // Split content into lines for processing
57
+ const lines = fileContent.split('\n');
58
+ const resultLines = [];
59
+
60
+ // Track merge state
61
+ let hasUnresolvedConflicts = false;
62
+ let totalConflicts = 0;
63
+ let resolvedConflicts = 0;
64
+
65
+ // State variables for parsing
66
+ let inConflict = false;
67
+ let headLines = [];
68
+ let branchLines = [];
69
+ let currentSection = null; // 'head' or 'branch'
70
+
71
+ // Process each line
72
+ for (let i = 0; i < lines.length; i++) {
73
+ const line = lines[i];
74
+
75
+ if (line.startsWith('<<<<<<<')) {
76
+ // Start of conflict marker
77
+ inConflict = true;
78
+ currentSection = 'head';
79
+ headLines = [];
80
+ branchLines = [];
81
+ totalConflicts++;
82
+ } else if (inConflict && line.startsWith('=======')) {
83
+ // Middle of conflict - switch from HEAD to branch
84
+ currentSection = 'branch';
85
+ } else if (inConflict && line.startsWith('>>>>>>>')) {
86
+ // End of conflict marker - attempt to merge
87
+ const headContent = headLines.join('\n');
88
+ const branchContent = branchLines.join('\n');
89
+
90
+ try {
91
+ // Call custom merge logic
92
+ const mergedContent = mergeLogic(headContent, branchContent);
93
+
94
+ // Add merged content to result
95
+ if (mergedContent !== null && mergedContent !== undefined) {
96
+ resultLines.push(mergedContent);
97
+ resolvedConflicts++;
98
+ console.log(`✓ Resolved conflict #${totalConflicts}`);
99
+ }
100
+ } catch (error) {
101
+ // Cannot merge this conflict - keep original conflict markers
102
+ hasUnresolvedConflicts = true;
103
+
104
+ console.log(
105
+ `✗ Could not resolve conflict #${totalConflicts}: ${error.message}`,
106
+ );
107
+
108
+ // Preserve the original conflict
109
+ resultLines.push(`<<<<<<< HEAD`);
110
+ resultLines.push(headContent);
111
+ resultLines.push('=======');
112
+ resultLines.push(branchContent);
113
+ resultLines.push(`>>>>>>> branch`);
114
+ }
115
+
116
+ // Reset conflict state
117
+ inConflict = false;
118
+ currentSection = null;
119
+ headLines = [];
120
+ branchLines = [];
121
+ } else if (inConflict) {
122
+ // Inside conflict - collect lines
123
+ if (currentSection === 'head') {
124
+ headLines.push(line);
125
+ } else if (currentSection === 'branch') {
126
+ branchLines.push(line);
127
+ }
128
+ } else {
129
+ // Normal line outside of conflict
130
+ resultLines.push(line);
131
+ }
132
+ }
133
+
134
+ // Write the result back to the file
135
+ const resultContent = resultLines.join('\n');
136
+ try {
137
+ fs.writeFileSync(filePath, resultContent, 'utf8');
138
+ console.log(`\nFile updated: ${filePath}`);
139
+ } catch (error) {
140
+ throw new Error(`Error writing file: ${error.message}`);
141
+ }
142
+
143
+ // Summary
144
+ console.log('\n--- Merge Summary ---');
145
+ console.log(`Total conflicts found: ${totalConflicts}`);
146
+ console.log(`Conflicts resolved: ${resolvedConflicts}`);
147
+ console.log(`Conflicts remaining: ${totalConflicts - resolvedConflicts}`);
148
+
149
+ // If all conflicts were resolved, stage the file
150
+ if (!hasUnresolvedConflicts && totalConflicts > 0) {
151
+ try {
152
+ execSync(`git add "${filePath}"`, { stdio: 'inherit' });
153
+ console.log(
154
+ `\n✓ All conflicts resolved! File has been staged with 'git add'.`,
155
+ );
156
+ } catch (error) {
157
+ console.error(`\nWarning: Could not stage file: ${error.message}`);
158
+ console.log('You may need to run "git add" manually.');
159
+ }
160
+ } else if (hasUnresolvedConflicts) {
161
+ console.log(`\n⚠ Some conflicts could not be resolved automatically.`);
162
+ console.log('Please review and resolve the remaining conflicts manually.');
163
+ } else if (totalConflicts === 0) {
164
+ console.log('\nNo conflicts found in the file.');
165
+ }
166
+
167
+ // Return result object for programmatic use
168
+ return {
169
+ success: !hasUnresolvedConflicts,
170
+ totalConflicts,
171
+ resolvedConflicts,
172
+ hasUnresolvedConflicts,
173
+ filePath,
174
+ };
175
+ }
176
+
177
+ /**
178
+ * Process multiple files with the same merge logic
179
+ * @param {string[]} filePaths - Array of file paths to process
180
+ * @param {Function} customMergeLogic - Custom merge function
181
+ * @returns {Promise<Array>} - Array of results for each file
182
+ */
183
+ export async function mergeMultipleFiles(filePaths, customMergeLogic) {
184
+ const results = [];
185
+
186
+ for (const filePath of filePaths) {
187
+ try {
188
+ const result = await mergeDriver(filePath, customMergeLogic);
189
+ results.push(result);
190
+ } catch (error) {
191
+ console.error(`Error processing ${filePath}: ${error.message}`);
192
+ results.push({
193
+ success: false,
194
+ error: error.message,
195
+ filePath,
196
+ });
197
+ }
198
+ }
199
+
200
+ return results;
201
+ }
202
+
203
+ // Default export for convenience
204
+ export default mergeDriver;