@docupace/pipeline 1.0.5-alpha.16 → 1.0.5-alpha.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.5-alpha.16",
3
+ "version": "1.0.5-alpha.19",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -35,6 +35,6 @@
35
35
  },
36
36
  "scripts": {
37
37
  "test-deploy-core": "dp-next-cli deploy-core-pipeline dev template",
38
- "test-deploy-from-site": "dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template"
38
+ "test-deploy-from-site": "dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template --deploy-core true"
39
39
  }
40
40
  }
@@ -9,6 +9,7 @@ import { zodResponseFormat } from 'openai/helpers/zod';
9
9
  import z from 'zod';
10
10
  import dotenv from 'dotenv';
11
11
  dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
12
+ import { exec } from 'child_process';
12
13
 
13
14
  const program = new Command();
14
15
 
@@ -16,6 +17,18 @@ const args = process.argv;
16
17
 
17
18
  const DIR = path.resolve(process.cwd());
18
19
 
20
+ function run(command) {
21
+ return new Promise((resolve, reject) => {
22
+ exec(command, { shell: true }, (error, stdout, stderr) => {
23
+ if (error) {
24
+ reject(error);
25
+ } else {
26
+ resolve({ stdout, stderr });
27
+ }
28
+ });
29
+ });
30
+ }
31
+
19
32
  async function fileExists(filePath) {
20
33
  try {
21
34
  await fs.promises.access(filePath);
@@ -155,11 +168,13 @@ program
155
168
 
156
169
  try {
157
170
  // Step 1: Get the current branch name
158
- const branchName = (await $`git branch --show-current`).stdout.trim();
171
+ console.log('Before');
172
+ const { stdout: branchStdout } = await run(`git branch --show-current`);
173
+ const branchName = branchStdout.trim();
159
174
  console.log(`Current branch: ${branchName}`);
160
175
 
161
- // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
162
- const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
176
+ // Step 2: Extract Jira ticket number (e.g., JIRA-1234)
177
+ const jiraTicketMatch = branchName.match(/([A-Z]+-\\d+)/);
163
178
  if (!jiraTicketMatch) {
164
179
  throw new Error('No Jira ticket found in the branch name.');
165
180
  }
@@ -173,7 +188,9 @@ program
173
188
  const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
174
189
  const jiraResponse = await fetch(jiraUrl, {
175
190
  headers: {
176
- Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
191
+ Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString(
192
+ 'base64',
193
+ )}`,
177
194
  'Content-Type': 'application/json',
178
195
  },
179
196
  });
@@ -195,6 +212,7 @@ program
195
212
  `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
196
213
  );
197
214
 
215
+ // Step 4: Use OpenAI to generate release notes
198
216
  const openaiClient = new OpenAI({
199
217
  apiKey: process.env['OPENAI_API_KEY'],
200
218
  });
@@ -231,22 +249,23 @@ program
231
249
  console.log(`Change type: ${change_type}`);
232
250
  console.log(`Release note: ${summary}`);
233
251
 
234
- // Step 5: Create a changeset using pnpm
252
+ // Step 5: Create a changeset .md file
235
253
  const changesetContent = `---
236
254
  "${componentName}": ${change_type}
237
255
  ---
238
256
 
239
257
  ${summary} [${jiraTicketId}]
240
- `;
258
+ `;
241
259
  const changesetFile = `./.changeset/${jiraTicketId}.md`;
242
260
 
243
- await $`mkdir -p ./.changeset`;
261
+ await run(`mkdir -p ./.changeset`);
244
262
  await fs.promises.writeFile(changesetFile, changesetContent);
245
263
  console.log(`Created changeset file at ${changesetFile}`);
246
264
 
247
265
  console.log('Done!');
248
266
  } catch (err) {
249
267
  console.error(`Error: ${err.message}`);
268
+ process.exit(1);
250
269
  }
251
270
  });
252
271
 
package/src/next/cli.js CHANGED
@@ -47,9 +47,10 @@ program
47
47
  .requiredOption('-t, --to-env <toEnv>', 'Target environment')
48
48
  .requiredOption('-F, --from-site <fromSite>', 'Source site')
49
49
  .requiredOption('-T, --to-site <toSite>', 'Target site')
50
+ .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
50
51
  .action(async (options) => {
51
- const { fromEnv, fromSite, toEnv, toSite } = options;
52
- await deployFromSite(fromEnv, fromSite, toEnv, toSite);
52
+ const { fromEnv, fromSite, toEnv, toSite, deployCore } = options;
53
+ await deployFromSite(fromEnv, fromSite, toEnv, toSite, deployCore);
53
54
  });
54
55
 
55
56
  program
@@ -1,5 +1,29 @@
1
1
  export const environments = ['dev', 'qa', 'uat', 'stage', 'prod'];
2
2
 
3
+ export const environmentConfig = {
4
+ dev: {
5
+ newUrl: (site) => `${site}.dev.dpai.tech`,
6
+ oldUrl: (site) => `https://www.dev.docupaceinc.com/${site}`,
7
+ },
8
+ qa: {
9
+ newUrl: (site) => `${site}.qa.dpai.tech`,
10
+ oldUrl: (site) => `https://www.preprod.docupaceinc.com/${site}`,
11
+ },
12
+ uat: {
13
+ newUrl: (site) => `${site}.qa.dpai.tech`,
14
+ oldUrl: (site) => `https://www2.paperout.com/${site}_uat`,
15
+ },
16
+ stage: {
17
+ newUrl: (site) => `${site}.stage.dpai.tech`,
18
+ oldUrl: (site) => `https://www2.paperout.com/${site}_staging`,
19
+ },
20
+
21
+ prod: {
22
+ newUrl: (site) => `${site}.dpai.tech`,
23
+ oldUrl: (site) => `https://www2.paperout.com/${site}`,
24
+ },
25
+ };
26
+
3
27
  export const appInfo = {
4
28
  'graphql-server': {
5
29
  repositoryName: 'docupace-graphql-server',
@@ -43,6 +67,6 @@ export const getRepUrl = (repoName) => {
43
67
  const { username, password, workspace } = getBitbucketInfo();
44
68
  const repoUrl = `https://${username}:${password}@bitbucket.org/${workspace}/${repoName}.git`;
45
69
  return repoUrl;
46
- }
70
+ };
47
71
 
48
72
  export const jfRegistryUrl = 'registry.paperout.com';
@@ -3,8 +3,11 @@ import path from 'path';
3
3
  import yaml from 'js-yaml';
4
4
  import { $ } from 'zx';
5
5
  import lodash from 'lodash';
6
- import {appInfo, getBitbucketInfo, getRepUrl} from './config.js';
6
+ import { appInfo, environmentConfig, getRepUrl } from './config.js';
7
7
  import { copy } from './copy.js';
8
+ import axios from 'axios';
9
+ import { runPipeline } from './pipline.js';
10
+ import { deployCore } from './jenkins.js';
8
11
 
9
12
  /**
10
13
  * Clone the repository, read the YAML file, and return the parsed data and file paths.
@@ -186,7 +189,72 @@ export async function deploy(application, site) {
186
189
  console.log('Deployment completed successfully.');
187
190
  }
188
191
 
189
- export async function deployFromSite(fromEnv, fromSite, toEnv, toSite) {
192
+ async function getAppInfo(coreUrl) {
193
+ const url = `${coreUrl}/b2b/rest/v1/appinfo`;
194
+ return await axios.get(url);
195
+ }
196
+
197
+ function getBranchNameFromVersion(version) {
198
+ const match = version.match(/(\d+\.\d+\.[^\-]+)(?:-(\d+)-g([a-f0-9]+))?/);
199
+
200
+ if (!match) {
201
+ throw new Error(`Invalid version format: ${version}`);
202
+ }
203
+
204
+ const fullVersion = match[1]; // e.g., 24.19.19, 24.20.alpha3, etc.
205
+ const customBranch = match[2]; // e.g., 4, 58, or 0
206
+ const commitHash = match[3]; // e.g., 668edef58e, 634cf6c904, etc.
207
+
208
+ // If "alpha" is in the version or customBranch is non-zero, use the commit hash
209
+ if (fullVersion.includes('alpha') || (customBranch && customBranch !== '0')) {
210
+ return commitHash;
211
+ }
212
+
213
+ // Otherwise, use the full version
214
+ return fullVersion;
215
+ }
216
+
217
+ async function getCoreBranchName(fromEnv, fromSite) {
218
+ const envConfig = environmentConfig[fromEnv];
219
+ const oldUrl = envConfig.oldUrl(fromSite);
220
+ const newUrl = envConfig.newUrl(fromSite) + '/core';
221
+
222
+ let appinfo;
223
+ try {
224
+ appinfo = await getAppInfo(oldUrl);
225
+ } catch {
226
+ try {
227
+ appinfo = await getAppInfo(newUrl);
228
+ } catch {
229
+ throw new Error('Cannot get app info');
230
+ }
231
+ }
232
+
233
+ const coreVersion = appinfo.data.core.version;
234
+ const branchName = getBranchNameFromVersion(coreVersion);
235
+ return branchName;
236
+ }
237
+
238
+ export async function deployFromSite(
239
+ fromEnv,
240
+ fromSite,
241
+ toEnv,
242
+ toSite,
243
+ isDeployCore,
244
+ ) {
245
+ if (isDeployCore === 'true') {
246
+ const branchName = await getCoreBranchName(fromEnv, fromSite);
247
+ await deployCore(toEnv, toSite, 'true', branchName);
248
+
249
+ // To be added back when splitting between on prem and in cloud
250
+ /*await runPipeline('site-deploy', 'deploy-core', 'main', {
251
+ ENV: toEnv,
252
+ SITE: toSite,
253
+ LIQUIBASE: 'true',
254
+ BRANCH: branchName,
255
+ });*/
256
+ }
257
+
190
258
  // Clone repositories for source and target environments
191
259
  const fromRepoPath = await cloneEnvRepository(fromEnv);
192
260
  const toRepoPath =