@docupace/pipeline 1.0.5-4.ervins → 1.0.5-alpha.0

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 (46) hide show
  1. package/.prettierrc.cjs +12 -12
  2. package/bin/next-changeset-validate.sh +8 -8
  3. package/eslint.config.js +1 -1
  4. package/next/changeset.sh +75 -75
  5. package/next/copy.sh +34 -34
  6. package/next/deploy.sh +40 -40
  7. package/next/execute.sh +117 -123
  8. package/next/sonar.sh +23 -23
  9. package/package.json +35 -50
  10. package/src/changeset/cli.js +254 -200
  11. package/src/changeset/validate.js +47 -84
  12. package/src/next/cli.js +72 -228
  13. package/src/next/config.js +0 -96
  14. package/src/next/copy.js +30 -61
  15. package/src/next/deploy.js +249 -595
  16. package/src/next/publish.js +48 -71
  17. package/src/next/pull.js +7 -7
  18. package/src/next/sonar.js +23 -23
  19. package/README.md +0 -136
  20. package/bin/azuread_update_callbacks_for_app.sh +0 -58
  21. package/src/auth0/alias.js +0 -72
  22. package/src/auth0/cli.js +0 -76
  23. package/src/auth0/configure.js +0 -783
  24. package/src/auth0/export.js +0 -43
  25. package/src/auth0/metadata.js +0 -132
  26. package/src/auth0/vault.js +0 -107
  27. package/src/changeset/changeset-config.js +0 -34
  28. package/src/changeset/create.js +0 -205
  29. package/src/changeset/package-util.js +0 -86
  30. package/src/changeset/util.js +0 -43
  31. package/src/changeset/version.js +0 -102
  32. package/src/jenkins/setParams.groovy +0 -58
  33. package/src/next/alias.js +0 -53
  34. package/src/next/apache.js +0 -73
  35. package/src/next/connect.js +0 -227
  36. package/src/next/haproxy.js +0 -71
  37. package/src/next/jenkins.js +0 -123
  38. package/src/next/jira.js +0 -84
  39. package/src/next/logger.js +0 -17
  40. package/src/next/pipline.js +0 -114
  41. package/src/next/util.js +0 -93
  42. package/src/next/vault.js +0 -45
  43. package/terraform/apply.sh +0 -37
  44. package/terraform/init.sh +0 -72
  45. package/terraform/plan.sh +0 -76
  46. package/terraform/validate.sh +0 -17
package/package.json CHANGED
@@ -1,50 +1,35 @@
1
- {
2
- "name": "@docupace/pipeline",
3
- "version": "1.0.54.ervins",
4
- "description": "",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "test-deploy-core": "dp-next-cli deploy-core-pipeline dev template",
9
- "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",
10
- "test-run-pipline": "dp-next-cli run-pipeline -r docupace-next-e2e -b master -p run-tests-qa",
11
- "test-validate": "dp-changset-cli validate",
12
- "test-create": "dp-changset-cli create-changeset"
13
- },
14
- "bin": {
15
- "dp-changeset-cli": "src/changeset/cli.js",
16
- "dp-next-cli": "src/next/cli.js",
17
- "dp-auth0-cli": "src/auth0/cli.js"
18
- },
19
- "keywords": [
20
- "bash"
21
- ],
22
- "author": "",
23
- "license": "ISC",
24
- "dependencies": {
25
- "@changesets/cli": "^2.27.10",
26
- "@docupace/core-client": "^0.1.59",
27
- "@docupace/pipeline": "^1.0.33-alpha-2",
28
- "auth0-deploy-cli": "^8.8.0",
29
- "axios": "^1.7.9",
30
- "commander": "^12.1.0",
31
- "dotenv": "^16.4.7",
32
- "fs-extra": "^11.3.0",
33
- "inquirer": "^12.6.1",
34
- "js-yaml": "^4.1.0",
35
- "lodash": "^4.17.21",
36
- "openai": "^4.76.3",
37
- "semver": "^7.7.2",
38
- "zod": "^3.24.1",
39
- "zx": "^8.3.0"
40
- },
41
- "devDependencies": {
42
- "@eslint/js": "^9.17.0",
43
- "esbuild": "^0.24.0",
44
- "eslint": "^9.17.0",
45
- "eslint-config-prettier": "^9.1.0",
46
- "eslint-plugin-prettier": "^5.2.1",
47
- "globals": "^15.14.0",
48
- "prettier": "^3.4.2"
49
- }
50
- }
1
+ {
2
+ "name": "@docupace/pipeline",
3
+ "version": "1.0.5-alpha.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "dp-changeset-cli": "src/changeset/cli.js",
9
+ "dp-next-cli": "src/next/cli.js"
10
+ },
11
+ "keywords": [
12
+ "bash"
13
+ ],
14
+ "author": "",
15
+ "license": "ISC",
16
+ "dependencies": {
17
+ "@changesets/cli": "^2.27.10",
18
+ "commander": "^12.1.0",
19
+ "dotenv": "^16.4.7",
20
+ "js-yaml": "^4.1.0",
21
+ "lodash": "^4.17.21",
22
+ "openai": "^4.76.3",
23
+ "zod": "^3.24.1",
24
+ "zx": "^8.2.4"
25
+ },
26
+ "devDependencies": {
27
+ "@eslint/js": "^9.17.0",
28
+ "esbuild": "^0.24.0",
29
+ "eslint": "^9.17.0",
30
+ "eslint-config-prettier": "^9.1.0",
31
+ "eslint-plugin-prettier": "^5.2.1",
32
+ "globals": "^15.14.0",
33
+ "prettier": "^3.4.2"
34
+ }
35
+ }
@@ -1,200 +1,254 @@
1
- #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { $ } from 'zx';
4
- import { validateChangesets } from './validate.js';
5
- import dotenv from 'dotenv';
6
- import { isMonoRepo, setGitInfo } from '../next/util.js';
7
- import {
8
- toShortVersion,
9
- updateJiraWithVersion,
10
- versionCommand,
11
- } from './version.js';
12
- import { createChangeset } from './create.js';
13
-
14
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
15
-
16
- const program = new Command();
17
-
18
- const args = process.argv;
19
-
20
- async function commitTagCommand(releases) {
21
- console.log('📌 Checking for updates to commit...');
22
-
23
- // Check if there are changes to commit
24
- const status = (await $`git status --porcelain`).stdout.trim();
25
- if (!status) {
26
- console.log('✅ No changes to commit. Exiting.');
27
- return;
28
- }
29
-
30
- console.log('📌 Committing and tagging the new version...');
31
- await setGitInfo();
32
- await $`git add .`;
33
-
34
- if (isMonoRepo()) {
35
- await commitTagMono(releases);
36
- } else {
37
- await commitTag();
38
- }
39
- }
40
-
41
- export function getAppReleases(releases) {
42
- const appReleases = releases.filter(
43
- (release) =>
44
- release.name.endsWith('-app') || release.name.endsWith('-template'),
45
- );
46
- return appReleases;
47
- }
48
-
49
- function getAppNameFromPackageName(packageName) {
50
- const appName = packageName.includes('/')
51
- ? packageName.split('/')[1]
52
- : packageName;
53
-
54
- return appName;
55
- }
56
-
57
- async function commitTagMono(releases) {
58
- let versions = [];
59
- for (const release of getAppReleases(releases)) {
60
- const newVersion = release.newVersion;
61
- const appName = getAppNameFromPackageName(release.name);
62
- versions.push(`${appName}@${newVersion}`);
63
- }
64
-
65
- const defaultBranch = process.env.BITBUCKET_BRANCH;
66
-
67
- if (!process.env.IS_DEV) {
68
- await $`git commit -m "Version bump to ${versions.join(',')} and changelog"`;
69
- await $`git push origin ${defaultBranch}`;
70
- } else {
71
- console.log(`Simulate Version bump to ${versions.join(',')} and changelog`);
72
- }
73
-
74
- for (const newVersion of versions) {
75
- if (!process.env.IS_DEV) {
76
- await $`git tag ${newVersion}`;
77
- console.log(`✅ Version ${newVersion} tagged.`);
78
- } else {
79
- console.log(`✅ Simulate Version ${newVersion} tagged.`);
80
- }
81
- }
82
-
83
- if (!process.env.IS_DEV) {
84
- await $`git push origin --tags`;
85
- console.log(`✅ Version pushed.`);
86
- } else {
87
- console.log(`✅ Simulate Version pushed.`);
88
- }
89
- }
90
-
91
- async function commitTag() {
92
- const newVersion = (
93
- await $`node -p "require('./package.json').version"`
94
- ).stdout.trim();
95
-
96
- const defaultBranch = process.env.BITBUCKET_BRANCH;
97
-
98
- await $`git commit -m "Version bump to ${newVersion} and changelog"`;
99
- await $`git push origin ${defaultBranch}`;
100
- await $`git tag v${newVersion}`;
101
- await $`git push origin --tags`;
102
- console.log(`✅ Version ${newVersion} tagged and pushed.`);
103
- }
104
-
105
- // Command: validate
106
- program
107
- .command('validate')
108
- .description('Validate changesets for the provided PR')
109
- .action(async () => {
110
- if (!process.env.BITBUCKET_PR_ID) {
111
- return;
112
- }
113
- console.log('🔍 Validating changesets...');
114
- try {
115
- await validateChangesets();
116
- console.log('✅ Changeset validation passed.');
117
- } catch {
118
- console.error(
119
- '❌ 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',
120
- );
121
- process.exit(1);
122
- }
123
- });
124
- // Command: version
125
- program
126
- .command('version')
127
- .description('Run Changeset versioning')
128
- .action(async () => {
129
- await versionCommand();
130
- });
131
-
132
- // Command: commit-and-tag
133
- program
134
- .command('commit-tag')
135
- .description('Commit and tag the new version')
136
- .action(async () => {
137
- await commitTagCommand();
138
- });
139
-
140
- // Command: all
141
- program
142
- .command('version-commit-tag')
143
- .description('Run versioning and commit-and-tag in sequence')
144
- .action(async () => {
145
- console.log('📦 Running all steps...');
146
- const releases = await versionCommand();
147
- await updateJiraWithVersion(releases);
148
- await commitTagCommand(releases);
149
- });
150
-
151
- program
152
- .command('close-version')
153
- .description('Closes a version')
154
- .action(async () => {
155
- console.log('📦 Running all steps...');
156
- const releases = await versionCommand(true);
157
- await commitTagCommand(releases);
158
-
159
- const { stdout: currentBranch } = await $`git rev-parse --abbrev-ref HEAD`;
160
-
161
- if (isMonoRepo()) {
162
- for (const release of getAppReleases(releases)) {
163
- const appName = getAppNameFromPackageName(release.name);
164
- const newVersion = toShortVersion(release.newVersion);
165
- if (!newVersion) {
166
- throw new Error('Error calculating branch name');
167
- }
168
- await $`git checkout -b release/${appName}/${newVersion}`;
169
- await $`git push origin release/${appName}/${newVersion}`;
170
- }
171
- } else {
172
- const newVersion = toShortVersion(releases[0].newVersion);
173
- if (!newVersion) {
174
- throw new Error('Error calculating branch name');
175
- }
176
- await $`git checkout -b release/${newVersion}`;
177
- await $`git push origin release/${newVersion}`;
178
- }
179
-
180
- // Return to original branch
181
- await $`git checkout ${currentBranch.trim()}`;
182
-
183
- // Open next alpha version
184
- await $`pnpm changeset pre enter alpha`;
185
- await $`git add .`;
186
- await $`git commit -m "Open next alpha version"`;
187
- await $`git push origin`;
188
- });
189
-
190
- program
191
- .name('create-changeset')
192
- .description(
193
- 'Creates a changeset based on the current branch and Jira ticket information',
194
- )
195
- .action(async () => {
196
- await createChangeset();
197
- });
198
-
199
- // Parse arguments
200
- program.parse(args);
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { $ } from 'zx';
4
+ import path from 'path';
5
+ 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
+ import dotenv from 'dotenv';
11
+ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
12
+
13
+ const program = new Command();
14
+
15
+ const args = process.argv;
16
+
17
+ const DIR = path.resolve(process.cwd());
18
+
19
+ async function fileExists(filePath) {
20
+ try {
21
+ await fs.promises.access(filePath);
22
+ return true;
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
27
+
28
+ async function getMainPackage() {
29
+ const mainModulePath = process.cwd();
30
+ if (mainModulePath) {
31
+ const packageJsonPath = path.join(mainModulePath, 'package.json');
32
+ if (await fileExists(packageJsonPath)) {
33
+ const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
34
+ const packageJson = JSON.parse(fileContent);
35
+ return packageJson;
36
+ }
37
+ }
38
+ throw new Error('Main package.json not found');
39
+ }
40
+
41
+ // Helper function to set Git info
42
+ async function setGitInfo() {
43
+ await $`git config --global user.email "gitops@docupace.com"`;
44
+ await $`git config --global user.name "Gitops"`;
45
+ await $`git remote set-url origin https://${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
46
+ }
47
+
48
+ const changeSetPackage = `{
49
+ "name": "changeset-package",
50
+ "version": "1.0.0",
51
+ "description": "",
52
+ "scripts": {
53
+ },
54
+ "type": "module",
55
+ "keywords": [],
56
+ "author": "",
57
+ "license": "ISC",
58
+ "dependencies": {},
59
+ "devDependencies": {
60
+ "@changesets/cli": "^2.27.10"
61
+ }
62
+ }
63
+ `;
64
+
65
+ async function versionCommand() {
66
+ console.log('📦 Running Changeset versioning...');
67
+ await setGitInfo();
68
+ await $`mv package.json package.json.bak`;
69
+ await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
70
+ await fs.promises.writeFile('package.json', changeSetPackage);
71
+ await $`pnpm install`;
72
+ await $`rm package.json pnpm-lock.yaml`;
73
+ await $`mv package.json.bak package.json`;
74
+ await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
75
+ await $`pnpm changeset version`;
76
+ console.log('✅ Changeset versioning complete.');
77
+ }
78
+
79
+ async function commitTagCommand() {
80
+ console.log('📌 Checking for updates to commit...');
81
+
82
+ // Check if there are changes to commit
83
+ const status = (await $`git status --porcelain`).stdout.trim();
84
+ if (!status) {
85
+ console.log('✅ No changes to commit. Exiting.');
86
+ return;
87
+ }
88
+
89
+ console.log('📌 Committing and tagging the new version...');
90
+ await setGitInfo();
91
+ await $`git add .`;
92
+ const newVersion = (
93
+ await $`node -p "require('./package.json').version"`
94
+ ).stdout.trim();
95
+ await $`git commit -m "Version bump to ${newVersion} and changelog"`;
96
+ await $`git push origin`;
97
+ await $`git tag v${newVersion}`;
98
+ await $`git push origin --tags`;
99
+ console.log(`✅ Version ${newVersion} tagged and pushed.`);
100
+ }
101
+
102
+ // Command: validate
103
+ program
104
+ .command('validate <path>')
105
+ .description('Validate changesets for the provided PR')
106
+ .action(async (path) => {
107
+ if (!process.env.BITBUCKET_PR_ID) {
108
+ return;
109
+ }
110
+ console.log('🔍 Validating changesets...');
111
+ try {
112
+ await validateChangesets(path);
113
+ console.log('✅ Changeset validation passed.');
114
+ } catch (error) {
115
+ console.error(
116
+ '❌ 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',
117
+ );
118
+ process.exit(1);
119
+ }
120
+ });
121
+ // Command: version
122
+ program
123
+ .command('version')
124
+ .description('Run Changeset versioning')
125
+ .action(async () => {
126
+ await versionCommand();
127
+ });
128
+
129
+ // Command: commit-and-tag
130
+ program
131
+ .command('commit-tag')
132
+ .description('Commit and tag the new version')
133
+ .action(async () => {
134
+ await commitTagCommand();
135
+ });
136
+
137
+ // Command: all
138
+ program
139
+ .command('version-commit-tag')
140
+ .description('Run versioning and commit-and-tag in sequence')
141
+ .action(async () => {
142
+ console.log('📦 Running all steps...');
143
+ await versionCommand();
144
+ await commitTagCommand();
145
+ });
146
+
147
+ program
148
+ .name('create-changeset')
149
+ .description(
150
+ 'Creates a changeset based on the current branch and Jira ticket information',
151
+ )
152
+ .action(async () => {
153
+ const mainPackage = await getMainPackage();
154
+ const componentName = mainPackage.name;
155
+
156
+ try {
157
+ // Step 1: Get the current branch name
158
+ const branchName = (await $`git branch --show-current`).stdout.trim();
159
+ console.log(`Current branch: ${branchName}`);
160
+
161
+ // Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
162
+ const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
163
+ if (!jiraTicketMatch) {
164
+ throw new Error('No Jira ticket found in the branch name.');
165
+ }
166
+ const jiraTicketId = jiraTicketMatch[0];
167
+
168
+ // Step 3: Fetch Jira ticket information
169
+ const jiraBaseUrl = 'https://docupacellc.atlassian.net';
170
+ const jiraEmail = process.env.JIRA_API_EMAIL;
171
+ const jiraApiKey = process.env.JIRA_API_KEY;
172
+ const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
173
+ const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
174
+ const jiraResponse = await fetch(jiraUrl, {
175
+ headers: {
176
+ Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
177
+ 'Content-Type': 'application/json',
178
+ },
179
+ });
180
+
181
+ if (!jiraResponse.ok) {
182
+ throw new Error(
183
+ `Failed to fetch Jira ticket. Status: ${jiraResponse.status}`,
184
+ );
185
+ }
186
+ const jiraTicketData = await jiraResponse.json();
187
+
188
+ if (jiraTicketData.fields.customfield_10107?.value !== 'Product') {
189
+ throw new Error('Issue Type of Work must be Product');
190
+ }
191
+
192
+ const jiraSummary = jiraTicketData.fields.summary;
193
+
194
+ console.log(
195
+ `Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
196
+ );
197
+
198
+ const openaiClient = new OpenAI({
199
+ apiKey: process.env['OPENAI_API_KEY'],
200
+ });
201
+
202
+ const ChangeRequestSchema = z.object({
203
+ change_type: z.enum(['patch', 'minor']),
204
+ summary: z.string(),
205
+ jira_ticket_id: z.string(),
206
+ });
207
+
208
+ const openAiResponse = await openaiClient.chat.completions.create({
209
+ model: 'gpt-4o-mini',
210
+ messages: [
211
+ {
212
+ role: 'system',
213
+ 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`,
214
+ },
215
+ {
216
+ role: 'user',
217
+ content: JSON.stringify(jiraTicketData),
218
+ },
219
+ ],
220
+ response_format: zodResponseFormat(
221
+ ChangeRequestSchema,
222
+ 'changeset_schema',
223
+ ),
224
+ temperature: 0,
225
+ });
226
+
227
+ const assistantResponse = openAiResponse.choices[0].message.content;
228
+ const parsedResponse = JSON.parse(assistantResponse);
229
+
230
+ const { change_type, summary } = parsedResponse;
231
+ console.log(`Change type: ${change_type}`);
232
+ console.log(`Release note: ${summary}`);
233
+
234
+ // Step 5: Create a changeset using pnpm
235
+ const changesetContent = `---
236
+ "${componentName}": ${change_type}
237
+ ---
238
+
239
+ ${summary} [${jiraTicketId}]
240
+ `;
241
+ const changesetFile = `./.changeset/${jiraTicketId}.md`;
242
+
243
+ await $`mkdir -p ./.changeset`;
244
+ await fs.promises.writeFile(changesetFile, changesetContent);
245
+ console.log(`Created changeset file at ${changesetFile}`);
246
+
247
+ console.log('Done!');
248
+ } catch (err) {
249
+ console.error(`Error: ${err.message}`);
250
+ }
251
+ });
252
+
253
+ // Parse arguments
254
+ program.parse(args);