@docupace/pipeline 1.0.39-matttest.3 → 1.0.39-matttest.31

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 ADDED
@@ -0,0 +1,136 @@
1
+ # Pipeline Shared Scripts
2
+
3
+ A collection of CLI tools for Docupace's CI/CD pipelines and deployment workflows.
4
+
5
+ ## Overview
6
+
7
+ This package provides a set of command-line interfaces (CLIs) to facilitate various DevOps operations in the Docupace ecosystem:
8
+
9
+ - `dp-next-cli`: Deployment and pipeline management for Next applications
10
+ - `dp-changeset-cli`: Versioning and changeset management
11
+ - `dp-auth0-cli`: Auth0 tenant configuration and management
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @docupace/pipeline
17
+ ```
18
+
19
+ Or with pnpm:
20
+
21
+ ```bash
22
+ pnpm add @docupace/pipeline
23
+ ```
24
+
25
+ ## Command Line Interfaces
26
+
27
+ ### dp-next-cli
28
+
29
+ Manages deployment, Docker image handling, and infrastructure configuration.
30
+
31
+ ```bash
32
+ dp-next-cli [command] [options]
33
+ ```
34
+
35
+ **Commands:**
36
+
37
+ - `pull <imageName>`: Pull a Docker image from the registry
38
+ - `sonar`: Run Sonar analysis
39
+ - `addApacheSite`: Add site to apache
40
+ - `connectClone`: Clone connect site
41
+ - `haproxySync`: Sync haproxy config
42
+ - `vaultAddSiteData`: Add m2m auth0 data to vault
43
+ - `-s, --site-name <siteName>`: Site name
44
+ - `-p, --site-config-remote-path <path>`: Site config remote path
45
+ - `publish`: Publish a Docker image
46
+ - `deploy-from-site`: Deploy an application for a specific site
47
+ - `-f, --from-env <fromEnv>`: Source environment
48
+ - `-t, --to-env <toEnv>`: Target environment
49
+ - `-F, --from-site <fromSite>`: Source site
50
+ - `-T, --to-site <toSite>`: Target site
51
+ - `-c, --deploy-core <deployCore>`: Deploy Core (default: "false")
52
+ - `-C, --deploy-connect <deployConnect>`: Deploy Connect (default: "false")
53
+ - `deploy-template`: Deploy an application for a specific site
54
+ - `deploy-app <application>`: Deploy an application for a specific site
55
+ - `deploy-core <env> <site>`: Deploy Core
56
+ - `-l, --liquibase <liquibase>`: Application name (default: "true")
57
+ - `-b, --branch <branch>`: Branch (default: "master")
58
+ - `deploy-connect <env> <site>`: Deploy Connect
59
+ - `-l, --liquibase <liquibase>`: Application name (default: "true")
60
+ - `-b, --branch <branch>`: Branch (default: "master")
61
+ - `deploy-core-pipeline <env> <site>`: Deploy Core via pipeline
62
+ - `-l, --liquibase <liquibase>`: Application name (default: "true")
63
+ - `-b, --branch <branch>`: Branch (default: "master")
64
+ - `copy`: Copy a Docker image between registries
65
+ - `-a, --application <application>`: Application name
66
+ - `-f, --from-env <fromEnv>`: Source environment
67
+ - `-t, --to-env <toEnv>`: Target environment
68
+ - `-g, --tag <tag>`: Image tag
69
+ - `run-pipeline`: Trigger a pipeline by name
70
+ - `-r, --repository <repository>`: Repository name
71
+ - `-p, --pipeline-name <pipelineName>`: Pipeline name
72
+ - `-b, --branch <branch>`: Branch name
73
+ - `-v, --variables <key=value>`: Pipeline variable as key=value pair
74
+ - `-w, --wait`: Wait for the pipeline to complete (default: false)
75
+
76
+ ### dp-changeset-cli
77
+
78
+ Manages versioning and changesets for mono-repos and single-package repos.
79
+
80
+ ```bash
81
+ dp-changeset-cli [command] [options]
82
+ ```
83
+
84
+ **Commands:**
85
+
86
+ - `validate`: Validate changesets for the provided PR
87
+ - `version`: Run Changeset versioning
88
+ - `commit-tag`: Commit and tag the new version
89
+ - `version-commit-tag`: Run versioning and commit-and-tag in sequence
90
+ - `close-version`: Close a version and create a release branch
91
+ - `create-changeset`: Create a changeset based on the current branch and Jira ticket information
92
+
93
+ ### dp-auth0-cli
94
+
95
+ Manages Auth0 tenant configuration across environments.
96
+
97
+ ```bash
98
+ dp-auth0-cli [command] [options]
99
+ ```
100
+
101
+ **Commands:**
102
+
103
+ - `configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain> <useS3>`: Configure Auth0 tenants
104
+ - `getVaultSecrets <vaultPath>`: Get secrets from Vault
105
+ - `configureAlias <site> <env> <username> <password> <realm>`: Configure Core Alias for the given site
106
+ - `exportConf <site> <env>`: Export Auth0 configuration for the given site
107
+ - `getAuth0Metadata <site> <env>`: Get Auth0 metadata for the given site
108
+
109
+ ## Environment Configuration
110
+
111
+ The CLI tools look for environment configuration in the following locations:
112
+ - `.env.pipeline.local`
113
+ - `config/.env.pipeline.local`
114
+
115
+ ## Examples
116
+
117
+ ```bash
118
+ # Deploy from one site to another
119
+ dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template --deploy-core true
120
+
121
+ # Run a pipeline
122
+ dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa
123
+
124
+ # Validate changesets
125
+ dp-changeset-cli validate
126
+
127
+ # Create a new changeset
128
+ dp-changeset-cli create-changeset
129
+
130
+ # Configure Auth0 for a site
131
+ dp-auth0-cli configureFromSite sourceSite targetSite dev prod true true true false
132
+ ```
133
+
134
+ ## License
135
+
136
+ ISC
package/next/execute.sh CHANGED
@@ -53,8 +53,14 @@ copy() {
53
53
  }
54
54
 
55
55
  publish() {
56
- BUILD_IMAGE_NAME="${BITBUCKET_REPO_SLUG}:build-${BITBUCKET_BUILD_NUMBER}"
57
- IMAGE_NAME="${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}"
56
+ SLUG_SUFFIX=""
57
+ if [ -n "$APP_NAME" ]; then
58
+ SLUG_SUFFIX="-${APP_NAME}"
59
+ fi
60
+
61
+ BUILD_IMAGE_NAME="${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:build-${BITBUCKET_BUILD_NUMBER}"
62
+ IMAGE_NAME="${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:sha-${GIT_SHA}"
63
+
58
64
  export DOCKER_HOST=""
59
65
 
60
66
  echo "Publishing Docker image ${IMAGE_NAME}..."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.39-matttest.3",
3
+ "version": "1.0.39-matttest.31",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,6 +23,7 @@
23
23
  "commander": "^12.1.0",
24
24
  "dotenv": "^16.4.7",
25
25
  "fs-extra": "^11.3.0",
26
+ "inquirer": "^12.6.1",
26
27
  "js-yaml": "^4.1.0",
27
28
  "lodash": "^4.17.21",
28
29
  "openai": "^4.76.3",
@@ -42,6 +43,7 @@
42
43
  "test-deploy-core": "dp-next-cli deploy-core-pipeline dev template",
43
44
  "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",
44
45
  "test-run-pipline": "dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa",
45
- "test-validate": "dp-changset-cli validate"
46
+ "test-validate": "dp-changset-cli validate",
47
+ "test-create": "dp-changset-cli create-changeset"
46
48
  }
47
49
  }
@@ -5,16 +5,16 @@ import crypto from 'crypto';
5
5
 
6
6
  import {
7
7
  cloneEnvRepository,
8
- readDeployConfig,
9
- pushDeployConfig,
10
8
  cloneRepository,
9
+ pushDeployConfig,
10
+ readDeployConfig,
11
11
  } from '../next/deploy.js';
12
12
 
13
13
  import { getVaultSecrets, updateVaultSecrets } from './vault.js';
14
14
  import {
15
- getVaultSecretsConfigs,
16
- environmentConfig,
17
15
  coreSiteEnvMap,
16
+ environmentConfig,
17
+ getVaultSecretsConfigs,
18
18
  } from '../next/config.js';
19
19
 
20
20
  async function ensureDirectoryExists(dirPath) {
@@ -1,11 +1,10 @@
1
1
  import fs from 'fs-extra';
2
2
  import axios from 'axios';
3
3
  import path from 'path';
4
- import { cloneRepository } from '../next/deploy.js';
4
+ import { cloneRepository, pushDeployConfig } from '../next/deploy.js';
5
5
  import { getAuth0AuthToken } from './configure.js';
6
6
  import { getVaultSecrets } from './vault.js';
7
7
  import { getVaultSecretsConfigs } from '../next/config.js';
8
- import { pushDeployConfig } from '../next/deploy.js';
9
8
 
10
9
  export async function getAuth0Metadata(site, env) {
11
10
  try {
@@ -1,146 +1,72 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import { $ } from 'zx';
4
- import path from 'path';
5
4
  import { validateChangesets } from './validate.js';
6
- import fs from 'fs';
7
- import OpenAI from 'openai';
8
- import { zodResponseFormat } from 'openai/helpers/zod';
9
- import z from 'zod';
10
5
  import dotenv from 'dotenv';
11
- import { makeJiraRequest, updateComponentVersion } from '../next/jira.js';
6
+ import { isMonoRepo, setGitInfo } from '../next/util.js';
7
+ import { updateJiraWithVersion, versionCommand } from './version.js';
8
+ import { createChangeset } from './create.js';
9
+
12
10
  dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
13
- import { setGitInfo } from '../next/util.js';
14
11
 
15
12
  const program = new Command();
16
13
 
17
14
  const args = process.argv;
18
15
 
19
- async function createChangesetDirectory() {
20
- try {
21
- // Use path.join to build a safe path to `.changeset`
22
- const targetDir = path.join(process.cwd(), '.changeset');
16
+ async function commitTagCommand(releases) {
17
+ console.log('📌 Checking for updates to commit...');
23
18
 
24
- // Create the directory recursively if it doesn't exist
25
- await fs.promises.mkdir(targetDir, { recursive: true });
26
- } catch (error) {
27
- console.error('Error creating .changeset directory:', error);
19
+ // Check if there are changes to commit
20
+ const status = (await $`git status --porcelain`).stdout.trim();
21
+ if (!status) {
22
+ console.log('✅ No changes to commit. Exiting.');
23
+ return;
28
24
  }
29
- }
30
25
 
31
- function run(command) {
32
- return new Promise((resolve, reject) => {
33
- exec(command, { shell: true }, (error, stdout, stderr) => {
34
- if (error) {
35
- reject(error);
36
- } else {
37
- resolve({ stdout, stderr });
38
- }
39
- });
40
- });
41
- }
42
-
43
- async function fileExists(filePath) {
44
- try {
45
- await fs.promises.access(filePath);
46
- return true;
47
- } catch {
48
- return false;
49
- }
50
- }
26
+ console.log('📌 Committing and tagging the new version...');
27
+ await setGitInfo();
28
+ await $`git add .`;
51
29
 
52
- async function getMainPackage() {
53
- const mainModulePath = process.cwd();
54
- if (mainModulePath) {
55
- const packageJsonPath = path.join(mainModulePath, 'package.json');
56
- if (await fileExists(packageJsonPath)) {
57
- const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
58
- const packageJson = JSON.parse(fileContent);
59
- return packageJson;
60
- }
30
+ if (isMonoRepo()) {
31
+ await commitTagMono(releases);
32
+ } else {
33
+ await commitTag();
61
34
  }
62
- throw new Error('Main package.json not found');
63
35
  }
64
36
 
65
- const changeSetPackage = `{
66
- "name": "changeset-package",
67
- "version": "1.0.0",
68
- "description": "",
69
- "scripts": {
70
- },
71
- "type": "module",
72
- "keywords": [],
73
- "author": "",
74
- "license": "ISC",
75
- "dependencies": {},
76
- "devDependencies": {
77
- "@changesets/cli": "^2.27.10"
78
- }
37
+ export function getAppReleases(releases) {
38
+ const appReleases = releases.filter((release) =>
39
+ release.name.endsWith('-app'),
40
+ );
41
+ return appReleases;
79
42
  }
80
- `;
81
43
 
82
- async function versionCommand(closeVersion = false) {
83
- console.log('📦 Running Changeset versioning...');
84
- await setGitInfo();
85
- await $`mv package.json package.json.bak`;
86
- await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
87
- await fs.promises.writeFile('package.json', changeSetPackage);
88
- await $`pnpm install`;
89
- await $`rm package.json pnpm-lock.yaml`;
90
- await $`mv package.json.bak package.json`;
91
- await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
92
- if (closeVersion) {
93
- await $`pnpm changeset pre exit`;
94
- }
44
+ function getAppNameFromPackageName(packageName) {
45
+ const appName = packageName.includes('/')
46
+ ? packageName.split('/')[1]
47
+ : packageName;
95
48
 
96
- await $`pnpm changeset version`;
97
-
98
- // Read the updated package.json to get the new version and package name
99
- const packageJson = JSON.parse(
100
- await fs.promises.readFile('package.json', 'utf-8'),
101
- );
102
- const version = packageJson.version;
103
- const packageName = packageJson.name;
49
+ return appName;
50
+ }
104
51
 
105
- if (closeVersion) {
106
- return { version, packageName };
52
+ async function commitTagMono(releases) {
53
+ let versions = [];
54
+ for (const release of getAppReleases(releases)) {
55
+ const newVersion = release.newVersion;
56
+ const appName = getAppNameFromPackageName(release.name);
57
+ versions.push(`${appName}@${newVersion}`);
107
58
  }
108
-
109
- // Get the last commit message and extract Jira ticket
110
- const lastCommit = (await $`git log -1 --pretty=%B`).stdout.trim();
111
- console.log(`Last commit '${lastCommit}' being processed to get Jira ticket`);
112
-
113
- const jiraTicketMatch = lastCommit.match(/([A-Z]+-\d+)/);
114
- const jiraTicketId = jiraTicketMatch ? jiraTicketMatch[0] : null;
115
-
116
- // If we have all the necessary data, update the component version in Jira
117
- if (jiraTicketId && version && packageName) {
118
- try {
119
- await updateComponentVersion(jiraTicketId, packageName, version);
120
- } catch (error) {
121
- console.error(
122
- `Failed to update Jira component version: ${error.message}`,
123
- );
124
- }
59
+ await $`git commit -m "Version bump to ${versions.join(',')} and changelog"`;
60
+ await $`git push origin`;
61
+ for (const newVersion of versions) {
62
+ await $`git tag ${newVersion}`;
63
+ console.log(`✅ Version ${newVersion} tagged.`);
125
64
  }
126
-
127
- console.log('✅ Changeset versioning complete.');
128
- return { version, packageName };
65
+ await $`git push origin --tags`;
66
+ console.log(`✅ Version pushed.`);
129
67
  }
130
68
 
131
- async function commitTagCommand() {
132
- console.log('📌 Checking for updates to commit...');
133
-
134
- // Check if there are changes to commit
135
- const status = (await $`git status --porcelain`).stdout.trim();
136
- if (!status) {
137
- console.log('✅ No changes to commit. Exiting.');
138
- return;
139
- }
140
-
141
- console.log('📌 Committing and tagging the new version...');
142
- await setGitInfo();
143
- await $`git add .`;
69
+ async function commitTag() {
144
70
  const newVersion = (
145
71
  await $`node -p "require('./package.json').version"`
146
72
  ).stdout.trim();
@@ -163,7 +89,7 @@ program
163
89
  try {
164
90
  await validateChangesets();
165
91
  console.log('✅ Changeset validation passed.');
166
- } catch (error) {
92
+ } catch {
167
93
  console.error(
168
94
  '❌ 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',
169
95
  );
@@ -192,8 +118,9 @@ program
192
118
  .description('Run versioning and commit-and-tag in sequence')
193
119
  .action(async () => {
194
120
  console.log('📦 Running all steps...');
195
- await versionCommand();
196
- await commitTagCommand();
121
+ const releases = await versionCommand();
122
+ await updateJiraWithVersion(releases);
123
+ await commitTagCommand(releases);
197
124
  });
198
125
 
199
126
  program
@@ -201,15 +128,21 @@ program
201
128
  .description('Closes a version')
202
129
  .action(async () => {
203
130
  console.log('📦 Running all steps...');
204
- const { version } = await versionCommand(true);
205
- await commitTagCommand();
131
+ const releases = await versionCommand(true);
132
+ await commitTagCommand(releases);
206
133
 
207
- // Get current branch
208
134
  const { stdout: currentBranch } = await $`git rev-parse --abbrev-ref HEAD`;
209
135
 
210
- // Create and push release branch
211
- await $`git checkout -b release/${version}`;
212
- await $`git push origin release/${version}`;
136
+ if (isMonoRepo()) {
137
+ for (const release of getAppReleases(releases)) {
138
+ const appName = getAppNameFromPackageName(release.name);
139
+ await $`git checkout -b release/${appName}/${release.newVersion}`;
140
+ await $`git push origin release/${appName}/${release.newVersion}`;
141
+ }
142
+ } else {
143
+ await $`git checkout -b release/${releases[0].newVersion}`;
144
+ await $`git push origin release/${releases[0].newVersion}`;
145
+ }
213
146
 
214
147
  // Return to original branch
215
148
  await $`git checkout ${currentBranch.trim()}`;
@@ -227,100 +160,7 @@ program
227
160
  'Creates a changeset based on the current branch and Jira ticket information',
228
161
  )
229
162
  .action(async () => {
230
- const mainPackage = await getMainPackage();
231
- const componentName = mainPackage.name;
232
-
233
- try {
234
- // Step 1: Get the current branch name
235
- const branchName = (await $`git branch --show-current`).stdout.trim();
236
- console.log(`Current branch: ${branchName}`);
237
-
238
- // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
239
- const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
240
- if (!jiraTicketMatch) {
241
- throw new Error('No Jira ticket found in the branch name.');
242
- }
243
- const jiraTicketId = jiraTicketMatch[0];
244
-
245
- const jiraBaseUrl = 'https://docupacellc.atlassian.net';
246
- const jiraEmail = process.env.JIRA_API_EMAIL;
247
- const jiraApiKey = process.env.JIRA_API_KEY;
248
- const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
249
- const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
250
- const jiraResponse = await fetch(jiraUrl, {
251
- headers: {
252
- Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
253
- 'Content-Type': 'application/json',
254
- },
255
- });
256
-
257
- if (!jiraResponse.ok) {
258
- throw new Error(
259
- `Failed to fetch Jira ticket. Status: ${jiraResponse.status}`,
260
- );
261
- }
262
- const jiraTicketData = await jiraResponse.json();
263
-
264
- const jiraSummary = jiraTicketData.fields.summary;
265
-
266
- console.log(
267
- `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
268
- );
269
-
270
- const openaiClient = new OpenAI({
271
- apiKey: process.env['OPENAI_API_KEY'],
272
- });
273
-
274
- const ChangeRequestSchema = z.object({
275
- change_type: z.enum(['patch', 'minor']),
276
- summary: z.string(),
277
- jira_ticket_id: z.string(),
278
- });
279
-
280
- const openAiResponse = await openaiClient.chat.completions.create({
281
- model: 'gpt-4o-mini',
282
- messages: [
283
- {
284
- role: 'system',
285
- content: `Process JSON from a Jira ticket to generate simple maximum 2 sentence release note for the ticket and determine the change type for bug it should be a patch for new feature it should be a minor change`,
286
- },
287
- {
288
- role: 'user',
289
- content: JSON.stringify(jiraTicketData),
290
- },
291
- ],
292
- response_format: zodResponseFormat(
293
- ChangeRequestSchema,
294
- 'changeset_schema',
295
- ),
296
- temperature: 0,
297
- });
298
-
299
- const assistantResponse = openAiResponse.choices[0].message.content;
300
- const parsedResponse = JSON.parse(assistantResponse);
301
-
302
- const { change_type, summary } = parsedResponse;
303
- console.log(`Change type: ${change_type}`);
304
- console.log(`Release note: ${summary}`);
305
-
306
- // Step 5: Create a changeset .md file
307
- const changesetContent = `---
308
- "${componentName}": ${change_type}
309
- ---
310
-
311
- ${summary} [${jiraTicketId}]
312
- `;
313
- const changesetFile = `./.changeset/${jiraTicketId}.md`;
314
-
315
- await createChangesetDirectory();
316
- await fs.promises.writeFile(changesetFile, changesetContent);
317
- console.log(`Created changeset file at ${changesetFile}`);
318
-
319
- console.log('Done!');
320
- } catch (err) {
321
- console.error(`Error: ${err.message}`);
322
- process.exit(1);
323
- }
163
+ await createChangeset();
324
164
  });
325
165
 
326
166
  // Parse arguments