@docupace/pipeline 1.0.1 → 1.0.2-3.tes2
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/.prettierrc.cjs +12 -0
- package/eslint.config.js +26 -0
- package/package.json +20 -4
- package/src/auth0/alias.js +75 -0
- package/src/auth0/cli.js +41 -0
- package/src/auth0/configure.js +715 -0
- package/src/auth0/vault.js +107 -0
- package/src/changeset/cli.js +215 -169
- package/src/changeset/validate.js +36 -33
- package/src/jenkins/setParams.groovy +59 -0
- package/src/next/alias.js +53 -0
- package/src/next/apache.js +40 -0
- package/src/next/cli.js +148 -31
- package/src/next/config.js +84 -0
- package/src/next/connect.js +199 -0
- package/src/next/copy.js +19 -16
- package/src/next/deploy.js +368 -63
- package/src/next/haproxy.js +50 -0
- package/src/next/jenkins.js +122 -0
- package/src/next/pipline.js +115 -0
- package/src/next/publish.js +42 -40
- package/src/next/pull.js +4 -4
- package/src/next/sonar.js +11 -11
- package/src/next/vault.js +43 -0
- package/terraform/apply.sh +26 -0
- package/terraform/init.sh +48 -0
- package/terraform/plan.sh +54 -0
- package/terraform/validate.sh +17 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetch secrets from Vault.
|
|
5
|
+
* @param {string} vaultPath - The path in Vault to fetch secrets from.
|
|
6
|
+
* @returns {Promise<Object>} - The secret data as a JSON object.
|
|
7
|
+
*/
|
|
8
|
+
export async function getVaultSecrets(vaultPath) {
|
|
9
|
+
if (!vaultPath) {
|
|
10
|
+
console.error("Error: VAULT_PATH is required.");
|
|
11
|
+
throw new Error("VAULT_PATH is required.");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const vaultToken = process.env.VAULT_TOKEN;
|
|
15
|
+
const vaultAddr = process.env.VAULT_ADDR;
|
|
16
|
+
|
|
17
|
+
if (!vaultToken || !vaultAddr) {
|
|
18
|
+
console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
|
|
19
|
+
throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
// Disable SSL verification globally by setting environment variable
|
|
24
|
+
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
25
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Fetch the secret from Vault
|
|
29
|
+
const response = await axios.get(`${vaultAddr}/v1/${vaultPath}`, {
|
|
30
|
+
headers: {
|
|
31
|
+
'X-Vault-Token': vaultToken,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Validate the response contains JSON data
|
|
36
|
+
const data = response.data;
|
|
37
|
+
if (data && typeof data === 'object') {
|
|
38
|
+
// console.log(`Secrets fetched successfully from Vault at ${JSON.stringify(data.data.data)})`);
|
|
39
|
+
return data.data.data;
|
|
40
|
+
} else {
|
|
41
|
+
console.error("Error: Invalid JSON received from Vault.");
|
|
42
|
+
throw new Error("Invalid JSON received from Vault.");
|
|
43
|
+
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error.response) {
|
|
46
|
+
console.error(
|
|
47
|
+
`Error: Failed to connect to Vault server at ${vaultAddr}. Response: ${error.response.status} ${error.response.statusText}`
|
|
48
|
+
);
|
|
49
|
+
} else {
|
|
50
|
+
console.error(`Error: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
// throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Update a secret in Vault.
|
|
58
|
+
* @param {string} vaultPath - The path in Vault where the secret should be updated.
|
|
59
|
+
* @param {Object} secretData - The secret data to be stored (as a JSON object).
|
|
60
|
+
* @returns {Promise<Object>} - The response from Vault as a JSON object.
|
|
61
|
+
*/
|
|
62
|
+
export async function updateVaultSecrets(vaultPath, secretData) {
|
|
63
|
+
if (!vaultPath || !secretData) {
|
|
64
|
+
console.error("Usage: updateVaultSecret(vaultPath, secretData)");
|
|
65
|
+
throw new Error("Both vaultPath and secretData are required.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const vaultToken = process.env.VAULT_TOKEN;
|
|
69
|
+
const vaultAddr = process.env.VAULT_ADDR;
|
|
70
|
+
|
|
71
|
+
if (!vaultToken || !vaultAddr) {
|
|
72
|
+
console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
|
|
73
|
+
throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
// Disable SSL verification globally if VAULT_SKIP_VERIFY is set
|
|
78
|
+
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
79
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Make the POST request to update the Vault secret
|
|
83
|
+
const response = await axios.post(
|
|
84
|
+
`${vaultAddr}/v1/${vaultPath}`,
|
|
85
|
+
secretData,
|
|
86
|
+
{
|
|
87
|
+
headers: {
|
|
88
|
+
'X-Vault-Token': vaultToken,
|
|
89
|
+
'Content-Type': 'application/json',
|
|
90
|
+
},
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Return the response from Vault
|
|
95
|
+
console.log(response.data);
|
|
96
|
+
return response.data;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (error.response) {
|
|
99
|
+
console.error(
|
|
100
|
+
`Error: Failed to update secret at ${vaultPath}. Response: ${error.response.status} ${error.response.statusText}`
|
|
101
|
+
);
|
|
102
|
+
} else {
|
|
103
|
+
console.error(`Error: ${error.message}`);
|
|
104
|
+
}
|
|
105
|
+
// throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/changeset/cli.js
CHANGED
|
@@ -2,47 +2,71 @@
|
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { $ } from 'zx';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import {validateChangesets} from
|
|
5
|
+
import { validateChangesets } from './validate.js';
|
|
6
6
|
import fs from 'fs';
|
|
7
|
-
import OpenAI from
|
|
8
|
-
import {zodResponseFormat} from
|
|
9
|
-
import z from 'zod'
|
|
7
|
+
import OpenAI from 'openai';
|
|
8
|
+
import { zodResponseFormat } from 'openai/helpers/zod';
|
|
9
|
+
import z from 'zod';
|
|
10
10
|
import dotenv from 'dotenv';
|
|
11
|
-
dotenv.config({path
|
|
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
|
|
|
15
16
|
const args = process.argv;
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
async function createChangesetDirectory() {
|
|
19
|
+
try {
|
|
20
|
+
// Use path.join to build a safe path to `.changeset`
|
|
21
|
+
const targetDir = path.join(process.cwd(), '.changeset');
|
|
22
|
+
|
|
23
|
+
// Create the directory recursively if it doesn't exist
|
|
24
|
+
await fs.promises.mkdir(targetDir, { recursive: true });
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error('Error creating .changeset directory:', error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
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
|
+
}
|
|
18
42
|
|
|
19
43
|
async function fileExists(filePath) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
44
|
+
try {
|
|
45
|
+
await fs.promises.access(filePath);
|
|
46
|
+
return true;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
26
50
|
}
|
|
27
51
|
|
|
28
52
|
async function getMainPackage() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
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;
|
|
37
60
|
}
|
|
38
|
-
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Main package.json not found');
|
|
39
63
|
}
|
|
40
64
|
|
|
41
65
|
// Helper function to set Git info
|
|
42
66
|
async function setGitInfo() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
await $`git config --global user.email "gitops@docupace.com"`;
|
|
68
|
+
await $`git config --global user.name "Gitops"`;
|
|
69
|
+
await $`git remote set-url origin https://${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
|
|
46
70
|
}
|
|
47
71
|
|
|
48
72
|
const changeSetPackage = `{
|
|
@@ -60,176 +84,198 @@ const changeSetPackage = `{
|
|
|
60
84
|
"@changesets/cli": "^2.27.10"
|
|
61
85
|
}
|
|
62
86
|
}
|
|
63
|
-
|
|
87
|
+
`;
|
|
64
88
|
|
|
65
89
|
async function versionCommand() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
console.log('📦 Running Changeset versioning...');
|
|
91
|
+
await setGitInfo();
|
|
92
|
+
await $`mv package.json package.json.bak`;
|
|
93
|
+
await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
|
|
94
|
+
await fs.promises.writeFile('package.json', changeSetPackage);
|
|
95
|
+
await $`pnpm install`;
|
|
96
|
+
await $`rm package.json pnpm-lock.yaml`;
|
|
97
|
+
await $`mv package.json.bak package.json`;
|
|
98
|
+
await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
|
|
99
|
+
await $`pnpm changeset version`;
|
|
100
|
+
console.log('✅ Changeset versioning complete.');
|
|
77
101
|
}
|
|
78
102
|
|
|
79
103
|
async function commitTagCommand() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
104
|
+
console.log('📌 Checking for updates to commit...');
|
|
105
|
+
|
|
106
|
+
// Check if there are changes to commit
|
|
107
|
+
const status = (await $`git status --porcelain`).stdout.trim();
|
|
108
|
+
if (!status) {
|
|
109
|
+
console.log('✅ No changes to commit. Exiting.');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.log('📌 Committing and tagging the new version...');
|
|
114
|
+
await setGitInfo();
|
|
115
|
+
await $`git add .`;
|
|
116
|
+
const newVersion = (
|
|
117
|
+
await $`node -p "require('./package.json').version"`
|
|
118
|
+
).stdout.trim();
|
|
119
|
+
await $`git commit -m "Version bump to ${newVersion} and changelog"`;
|
|
120
|
+
await $`git push origin`;
|
|
121
|
+
await $`git tag v${newVersion}`;
|
|
122
|
+
await $`git push origin --tags`;
|
|
123
|
+
console.log(`✅ Version ${newVersion} tagged and pushed.`);
|
|
89
124
|
}
|
|
90
125
|
|
|
91
126
|
// Command: validate
|
|
92
127
|
program
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
128
|
+
.command('validate <path>')
|
|
129
|
+
.description('Validate changesets for the provided PR')
|
|
130
|
+
.action(async (path) => {
|
|
131
|
+
if (!process.env.BITBUCKET_PR_ID) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
console.log('🔍 Validating changesets...');
|
|
135
|
+
try {
|
|
136
|
+
await validateChangesets(path);
|
|
137
|
+
console.log('✅ Changeset validation passed.');
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error(
|
|
140
|
+
'❌ 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',
|
|
141
|
+
);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
110
145
|
// Command: version
|
|
111
146
|
program
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
147
|
+
.command('version')
|
|
148
|
+
.description('Run Changeset versioning')
|
|
149
|
+
.action(async () => {
|
|
150
|
+
await versionCommand();
|
|
151
|
+
});
|
|
117
152
|
|
|
118
153
|
// Command: commit-and-tag
|
|
119
154
|
program
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
155
|
+
.command('commit-tag')
|
|
156
|
+
.description('Commit and tag the new version')
|
|
157
|
+
.action(async () => {
|
|
158
|
+
await commitTagCommand();
|
|
159
|
+
});
|
|
125
160
|
|
|
126
161
|
// Command: all
|
|
127
162
|
program
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
163
|
+
.command('version-commit-tag')
|
|
164
|
+
.description('Run versioning and commit-and-tag in sequence')
|
|
165
|
+
.action(async () => {
|
|
166
|
+
console.log('📦 Running all steps...');
|
|
167
|
+
await versionCommand();
|
|
168
|
+
await commitTagCommand();
|
|
169
|
+
});
|
|
135
170
|
|
|
136
171
|
program
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
172
|
+
.name('create-changeset')
|
|
173
|
+
.description(
|
|
174
|
+
'Creates a changeset based on the current branch and Jira ticket information',
|
|
175
|
+
)
|
|
176
|
+
.action(async () => {
|
|
177
|
+
const mainPackage = await getMainPackage();
|
|
178
|
+
const componentName = mainPackage.name;
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
// Step 1: Get the current branch name
|
|
182
|
+
const { stdout: branchStdout } = await run(`git branch --show-current`);
|
|
183
|
+
const branchName = branchStdout.trim();
|
|
184
|
+
console.log(`Current branch: ${branchName}`);
|
|
185
|
+
|
|
186
|
+
// Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
|
|
187
|
+
const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
|
|
188
|
+
if (!jiraTicketMatch) {
|
|
189
|
+
throw new Error('No Jira ticket found in the branch name.');
|
|
190
|
+
}
|
|
191
|
+
const jiraTicketId = jiraTicketMatch[0];
|
|
192
|
+
|
|
193
|
+
// Step 3: Fetch Jira ticket information
|
|
194
|
+
const jiraBaseUrl = 'https://docupacellc.atlassian.net';
|
|
195
|
+
const jiraEmail = process.env.JIRA_API_EMAIL;
|
|
196
|
+
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
197
|
+
const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
|
|
198
|
+
const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
|
|
199
|
+
const jiraResponse = await fetch(jiraUrl, {
|
|
200
|
+
headers: {
|
|
201
|
+
Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
|
|
202
|
+
'Content-Type': 'application/json',
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (!jiraResponse.ok) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
const jiraTicketData = await jiraResponse.json();
|
|
212
|
+
|
|
213
|
+
if (jiraTicketData.fields.customfield_10107?.value !== 'Product') {
|
|
214
|
+
throw new Error('Issue Type of Work must be Product');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const jiraSummary = jiraTicketData.fields.summary;
|
|
218
|
+
|
|
219
|
+
console.log(
|
|
220
|
+
`Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// Step 4: Use OpenAI to generate release notes
|
|
224
|
+
const openaiClient = new OpenAI({
|
|
225
|
+
apiKey: process.env['OPENAI_API_KEY'],
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const ChangeRequestSchema = z.object({
|
|
229
|
+
change_type: z.enum(['patch', 'minor']),
|
|
230
|
+
summary: z.string(),
|
|
231
|
+
jira_ticket_id: z.string(),
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const openAiResponse = await openaiClient.chat.completions.create({
|
|
235
|
+
model: 'gpt-4o-mini',
|
|
236
|
+
messages: [
|
|
237
|
+
{
|
|
238
|
+
role: 'system',
|
|
239
|
+
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`,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
role: 'user',
|
|
243
|
+
content: JSON.stringify(jiraTicketData),
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
response_format: zodResponseFormat(
|
|
247
|
+
ChangeRequestSchema,
|
|
248
|
+
'changeset_schema',
|
|
249
|
+
),
|
|
250
|
+
temperature: 0,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const assistantResponse = openAiResponse.choices[0].message.content;
|
|
254
|
+
const parsedResponse = JSON.parse(assistantResponse);
|
|
255
|
+
|
|
256
|
+
const { change_type, summary } = parsedResponse;
|
|
257
|
+
console.log(`Change type: ${change_type}`);
|
|
258
|
+
console.log(`Release note: ${summary}`);
|
|
259
|
+
|
|
260
|
+
// Step 5: Create a changeset .md file
|
|
261
|
+
const changesetContent = `---
|
|
216
262
|
"${componentName}": ${change_type}
|
|
217
263
|
---
|
|
218
264
|
|
|
219
265
|
${summary} [${jiraTicketId}]
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
await $`mkdir -p ./.changeset`;
|
|
224
|
-
await fs.promises.writeFile(changesetFile, changesetContent);
|
|
225
|
-
console.log(`Created changeset file at ${changesetFile}`);
|
|
266
|
+
`;
|
|
267
|
+
const changesetFile = `./.changeset/${jiraTicketId}.md`;
|
|
226
268
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
});
|
|
269
|
+
await createChangesetDirectory();
|
|
270
|
+
await fs.promises.writeFile(changesetFile, changesetContent);
|
|
271
|
+
console.log(`Created changeset file at ${changesetFile}`);
|
|
232
272
|
|
|
273
|
+
console.log('Done!');
|
|
274
|
+
} catch (err) {
|
|
275
|
+
console.error(`Error: ${err.message}`);
|
|
276
|
+
process.exit(1);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
233
279
|
|
|
234
280
|
// Parse arguments
|
|
235
281
|
program.parse(args);
|
|
@@ -2,43 +2,46 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
|
|
4
4
|
export async function validateChangesets(directoryPath) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
try {
|
|
6
|
+
// Step 1: Read the directory for md files excluding README.md
|
|
7
|
+
const allFiles = fs.readdirSync(directoryPath);
|
|
8
|
+
const mdFiles = allFiles.filter(
|
|
9
|
+
(file) => file.endsWith('.md') && file !== 'README.md',
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
// Step 2: Check for pre.json and parse it
|
|
13
|
+
const preJsonPath = path.join(directoryPath, 'pre.json');
|
|
14
|
+
let preJson;
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
|
|
17
|
+
throw new Error('Error: No pre.json and no md files found.');
|
|
18
|
+
}
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
if (fs.existsSync(preJsonPath)) {
|
|
21
|
+
preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (preJson.mode == 'pre') {
|
|
24
|
+
// Step 4a: Get list of changesets from pre.json
|
|
25
|
+
const changesets = preJson.changesets || [];
|
|
26
|
+
const changesetNames = changesets.map((change) => change);
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
// Step 4b: Match files with the list of changesets
|
|
29
|
+
const mdFileNamesWithoutExt = mdFiles.map((file) =>
|
|
30
|
+
path.basename(file, '.md'),
|
|
31
|
+
);
|
|
32
|
+
const unmatchedFiles = mdFileNamesWithoutExt.filter(
|
|
33
|
+
(fileName) => !changesetNames.includes(fileName),
|
|
34
|
+
);
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
36
|
+
if (unmatchedFiles.length == 0) {
|
|
37
|
+
throw new Error('Error: No new MD files found:');
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
console.log("Validation successful.");
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.log(error.message);
|
|
39
|
-
throw(error);
|
|
39
|
+
}
|
|
40
40
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
41
|
|
|
42
|
+
console.log('Validation successful.');
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.log(error.message);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|