@docupace/pipeline 1.0.6 → 1.0.7-7.micro-cli2
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 -12
- package/README.md +136 -0
- package/bin/azuread_update_callbacks_for_app.sh +58 -0
- package/bin/next-changeset-validate.sh +8 -8
- package/bitbucket-pipelines.yml +60 -0
- package/eslint.config.js +49 -26
- package/jest.config.js +15 -0
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +123 -117
- package/next/sonar.sh +23 -23
- package/package.json +23 -7
- package/src/auth0/alias.js +79 -0
- package/src/auth0/alias.test.js +172 -0
- package/src/auth0/cli.js +82 -0
- package/src/auth0/configure.js +902 -0
- package/src/auth0/configure.test.js +167 -0
- package/src/auth0/export.js +48 -0
- package/src/auth0/export.test.js +103 -0
- package/src/auth0/metadata.js +141 -0
- package/src/auth0/metadata.test.js +186 -0
- package/src/auth0/vault.js +60 -0
- package/src/auth0/vault.test.js +134 -0
- package/src/changeset/changelog-wiki.js +328 -0
- package/src/changeset/changeset-config.js +34 -0
- package/src/changeset/cli.js +237 -281
- package/src/changeset/create.js +215 -0
- package/src/changeset/package-util.js +87 -0
- package/src/changeset/util.js +43 -0
- package/src/changeset/validate.js +91 -47
- package/src/changeset/version.js +102 -0
- package/src/jenkins/setParams.groovy +58 -59
- package/src/lib/merge-driver.js +204 -0
- package/src/merge/cli-merge-all.js +507 -0
- package/src/merge/cli-merge.js +492 -0
- package/src/merge/cli-resolve.js +399 -0
- package/src/merge/cli.js +38 -0
- package/src/merge/merge-changelog.js +87 -0
- package/src/merge/merge-package.js +106 -0
- package/src/merge/merge-types.js +82 -0
- package/src/merge/pr.js +231 -0
- package/src/micro/cli.js +71 -0
- package/src/micro/ms-deploy.js +273 -0
- package/src/micro/ms-publish.js +186 -0
- package/src/next/alias.js +53 -0
- package/src/next/apache.js +81 -0
- package/src/next/cli.js +111 -15
- package/src/next/config.js +137 -72
- package/src/next/connect.js +226 -0
- package/src/next/copy.js +61 -30
- package/src/next/deploy.js +633 -312
- package/src/next/git-to-semver.js +79 -0
- package/src/next/haproxy.js +76 -0
- package/src/next/jenkins.js +123 -88
- package/src/next/jira.js +84 -0
- package/src/next/logger.js +17 -0
- package/src/next/pipline.js +114 -115
- package/src/next/publish.js +71 -48
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/src/next/test.js +5 -0
- package/src/next/util.js +93 -0
- package/src/next/vault.js +45 -0
- package/terraform/apply.sh +37 -0
- package/terraform/init.sh +72 -0
- package/terraform/plan.sh +76 -0
- package/terraform/validate.sh +17 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/auth0/vault.js
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
export async function getVaultSecrets(vaultPath) {
|
|
5
|
+
if (!vaultPath) throw new Error('VAULT_PATH is required.');
|
|
6
|
+
|
|
7
|
+
const token = process.env.VAULT_TOKEN;
|
|
8
|
+
const addr = process.env.VAULT_ADDR;
|
|
9
|
+
if (!token || !addr)
|
|
10
|
+
throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
11
|
+
|
|
12
|
+
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
13
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const response = await axios.get(`${addr}/v1/${vaultPath}`, {
|
|
18
|
+
headers: { 'X-Vault-Token': token },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const data = response.data;
|
|
22
|
+
if (data && typeof data === 'object') return data.data.data;
|
|
23
|
+
throw new Error('Invalid JSON received from Vault.');
|
|
24
|
+
} catch (err) {
|
|
25
|
+
console.error(
|
|
26
|
+
'Vault GET error:',
|
|
27
|
+
err?.message || err?.response?.statusText || err,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function updateVaultSecrets(vaultPath, secretData) {
|
|
33
|
+
if (!vaultPath || !secretData)
|
|
34
|
+
throw new Error('Both vaultPath and secretData are required.');
|
|
35
|
+
|
|
36
|
+
const token = process.env.VAULT_TOKEN;
|
|
37
|
+
const addr = process.env.VAULT_ADDR;
|
|
38
|
+
if (!token || !addr)
|
|
39
|
+
throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
40
|
+
|
|
41
|
+
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
42
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const response = await axios.post(`${addr}/v1/${vaultPath}`, secretData, {
|
|
47
|
+
headers: {
|
|
48
|
+
'X-Vault-Token': token,
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return response.data;
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error(
|
|
56
|
+
'Vault POST error:',
|
|
57
|
+
err?.message || err?.response?.statusText || err,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/auth0/vault.test.js
|
|
2
|
+
import { jest } from '@jest/globals';
|
|
3
|
+
|
|
4
|
+
// ESM-compatible mocking
|
|
5
|
+
jest.unstable_mockModule('axios', () => ({
|
|
6
|
+
default: {
|
|
7
|
+
get: jest.fn(),
|
|
8
|
+
post: jest.fn(),
|
|
9
|
+
},
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe('Vault Utilities', () => {
|
|
13
|
+
let axios;
|
|
14
|
+
let getVaultSecrets;
|
|
15
|
+
let updateVaultSecrets;
|
|
16
|
+
const OLD_ENV = process.env;
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
// Dynamic import AFTER mocking
|
|
20
|
+
axios = (await import('axios')).default;
|
|
21
|
+
const vault = await import('./vault.js');
|
|
22
|
+
getVaultSecrets = vault.getVaultSecrets;
|
|
23
|
+
updateVaultSecrets = vault.updateVaultSecrets;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
jest.resetModules();
|
|
28
|
+
process.env = { ...OLD_ENV };
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterAll(() => {
|
|
33
|
+
process.env = OLD_ENV;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('getVaultSecrets', () => {
|
|
37
|
+
it('should fetch secrets from Vault successfully', async () => {
|
|
38
|
+
process.env.VAULT_TOKEN = 'test-token';
|
|
39
|
+
process.env.VAULT_ADDR = 'https://vault.example.com';
|
|
40
|
+
|
|
41
|
+
axios.get.mockResolvedValueOnce({
|
|
42
|
+
data: {
|
|
43
|
+
data: {
|
|
44
|
+
data: {
|
|
45
|
+
username: 'admin',
|
|
46
|
+
password: 'secret',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const result = await getVaultSecrets('secret/data/myapp');
|
|
53
|
+
expect(result).toEqual({ username: 'admin', password: 'secret' });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should throw error if vaultPath is missing', async () => {
|
|
57
|
+
await expect(getVaultSecrets()).rejects.toThrow(
|
|
58
|
+
'VAULT_PATH is required.',
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should throw error if env vars are missing', async () => {
|
|
63
|
+
delete process.env.VAULT_TOKEN;
|
|
64
|
+
delete process.env.VAULT_ADDR;
|
|
65
|
+
|
|
66
|
+
await expect(getVaultSecrets('secret/data/myapp')).rejects.toThrow(
|
|
67
|
+
'VAULT_TOKEN and VAULT_ADDR must be set.',
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should handle Vault error response', async () => {
|
|
72
|
+
process.env.VAULT_TOKEN = 'token';
|
|
73
|
+
process.env.VAULT_ADDR = 'https://vault.example.com';
|
|
74
|
+
|
|
75
|
+
axios.get.mockRejectedValueOnce({
|
|
76
|
+
response: { status: 403, statusText: 'Forbidden' },
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const result = await getVaultSecrets('secret/data/myapp');
|
|
80
|
+
expect(result).toBeUndefined();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('updateVaultSecrets', () => {
|
|
85
|
+
it('should update secrets in Vault successfully', async () => {
|
|
86
|
+
process.env.VAULT_TOKEN = 'test-token';
|
|
87
|
+
process.env.VAULT_ADDR = 'https://vault.example.com';
|
|
88
|
+
|
|
89
|
+
const secretData = {
|
|
90
|
+
data: {
|
|
91
|
+
apiKey: '123456',
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
axios.post.mockResolvedValueOnce({
|
|
96
|
+
data: {
|
|
97
|
+
success: true,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const result = await updateVaultSecrets('secret/data/myapp', secretData);
|
|
102
|
+
expect(result).toEqual({ success: true });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should throw error if vaultPath or secretData is missing', async () => {
|
|
106
|
+
await expect(updateVaultSecrets()).rejects.toThrow(
|
|
107
|
+
'Both vaultPath and secretData are required.',
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should throw error if env vars are missing', async () => {
|
|
112
|
+
delete process.env.VAULT_TOKEN;
|
|
113
|
+
delete process.env.VAULT_ADDR;
|
|
114
|
+
|
|
115
|
+
await expect(updateVaultSecrets('secret/data/myapp', {})).rejects.toThrow(
|
|
116
|
+
'VAULT_TOKEN and VAULT_ADDR must be set.',
|
|
117
|
+
);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should handle Vault error response', async () => {
|
|
121
|
+
process.env.VAULT_TOKEN = 'token';
|
|
122
|
+
process.env.VAULT_ADDR = 'https://vault.example.com';
|
|
123
|
+
|
|
124
|
+
axios.post.mockRejectedValueOnce({
|
|
125
|
+
response: { status: 500, statusText: 'Internal Server Error' },
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const result = await updateVaultSecrets('secret/data/myapp', {
|
|
129
|
+
data: {},
|
|
130
|
+
});
|
|
131
|
+
expect(result).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
// npm i axios
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
import { getPackageNames } from './package-util.js';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { toShortVersion } from './version.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Required env:
|
|
10
|
+
* CONFLUENCE_BASE_URL e.g. "https://docupacellc.atlassian.net/wiki"
|
|
11
|
+
* CONFLUENCE_EMAIL e.g. "you@docupace.com"
|
|
12
|
+
* CONFLUENCE_API_TOKEN Atlassian API token
|
|
13
|
+
*/
|
|
14
|
+
const BASE_URL = process.env.CONFLUENCE_BASE_URL;
|
|
15
|
+
const EMAIL = process.env.CONFLUENCE_EMAIL;
|
|
16
|
+
const API_TOKEN = process.env.CONFLUENCE_API_TOKEN;
|
|
17
|
+
|
|
18
|
+
const getHttpService = () =>
|
|
19
|
+
axios.create({
|
|
20
|
+
baseURL: BASE_URL.replace(/\/+$/, ''),
|
|
21
|
+
auth: { username: EMAIL, password: API_TOKEN },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/** ---------- ADF builder: Markdown macro ---------- */
|
|
25
|
+
function adfMarkdown(markdown) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'doc',
|
|
28
|
+
version: 1,
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: 'extension',
|
|
32
|
+
attrs: {
|
|
33
|
+
layout: 'default',
|
|
34
|
+
extensionType: 'com.atlassian.confluence.macro.core',
|
|
35
|
+
extensionKey: 'markdown',
|
|
36
|
+
parameters: {
|
|
37
|
+
macroParams: {
|
|
38
|
+
sourceType: { value: 'MacroBody' },
|
|
39
|
+
darkmode: { value: 'auto' },
|
|
40
|
+
syntax: { value: 'Markdown' },
|
|
41
|
+
attachmentPageId: { value: '' },
|
|
42
|
+
attachmentId: { value: '' },
|
|
43
|
+
url: { value: '' },
|
|
44
|
+
__bodyContent: { value: markdown },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** ---------- API helpers (v2) ---------- */
|
|
54
|
+
|
|
55
|
+
// get a page (v2) by id
|
|
56
|
+
async function getPage(pageId) {
|
|
57
|
+
const { data } = await getHttpService().get(`/api/v2/pages/${pageId}`);
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// list child pages (paginated) and return *all* children
|
|
62
|
+
async function listChildPages(parentId) {
|
|
63
|
+
const all = [];
|
|
64
|
+
let next = `/api/v2/pages/${parentId}/children?limit=200`;
|
|
65
|
+
|
|
66
|
+
while (next) {
|
|
67
|
+
const { data } = await getHttpService().get(next);
|
|
68
|
+
if (Array.isArray(data.results)) all.push(...data.results);
|
|
69
|
+
next = data?._links?.next || null;
|
|
70
|
+
}
|
|
71
|
+
return all;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// find a direct child page by exact title
|
|
75
|
+
async function findChildByTitle(parentId, title) {
|
|
76
|
+
const kids = await listChildPages(parentId);
|
|
77
|
+
return kids.find((p) => (p.title || '').trim() === title.trim()) || null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// create a child page under a parent
|
|
81
|
+
async function createChildPage({
|
|
82
|
+
parentId,
|
|
83
|
+
spaceId,
|
|
84
|
+
title,
|
|
85
|
+
adf,
|
|
86
|
+
message = 'Create via API',
|
|
87
|
+
}) {
|
|
88
|
+
const payload = {
|
|
89
|
+
status: 'current',
|
|
90
|
+
title,
|
|
91
|
+
spaceId,
|
|
92
|
+
parentId,
|
|
93
|
+
body: {
|
|
94
|
+
atlas_doc_format: {
|
|
95
|
+
value: adf,
|
|
96
|
+
representation: 'atlas_doc_format',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
version: { number: 1, message, minorEdit: false },
|
|
100
|
+
};
|
|
101
|
+
const { data } = await getHttpService().post(`/api/v2/pages`, payload);
|
|
102
|
+
return data;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// update an existing page (replace body + optionally title)
|
|
106
|
+
async function updatePage({
|
|
107
|
+
page,
|
|
108
|
+
title = page.title,
|
|
109
|
+
adf,
|
|
110
|
+
message = 'Update via API',
|
|
111
|
+
}) {
|
|
112
|
+
if (!page.version) {
|
|
113
|
+
page = await getPage(page.id);
|
|
114
|
+
}
|
|
115
|
+
const payload = {
|
|
116
|
+
id: page.id,
|
|
117
|
+
status: 'current',
|
|
118
|
+
title,
|
|
119
|
+
spaceId: page.spaceId,
|
|
120
|
+
body: {
|
|
121
|
+
atlas_doc_format: {
|
|
122
|
+
value: adf,
|
|
123
|
+
representation: 'atlas_doc_format',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
version: {
|
|
127
|
+
number: page.version.number + 1,
|
|
128
|
+
message,
|
|
129
|
+
minorEdit: false,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const { data } = await getHttpService().put(
|
|
133
|
+
`/api/v2/pages/${page.id}`,
|
|
134
|
+
payload,
|
|
135
|
+
);
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const childPagesAdf = {
|
|
140
|
+
type: 'doc',
|
|
141
|
+
version: 1,
|
|
142
|
+
content: [
|
|
143
|
+
{
|
|
144
|
+
type: 'extension',
|
|
145
|
+
attrs: {
|
|
146
|
+
extensionType: 'com.atlassian.confluence.macro.core',
|
|
147
|
+
extensionKey: 'children',
|
|
148
|
+
layout: 'default',
|
|
149
|
+
parameters: {
|
|
150
|
+
macroParams: {
|
|
151
|
+
allChildren: { value: 'true' },
|
|
152
|
+
},
|
|
153
|
+
macroMetadata: {
|
|
154
|
+
macroId: { value: '9ea4beb6-ac0a-42d7-baf1-e8e6eca01bfd' },
|
|
155
|
+
schemaVersion: { value: '2' },
|
|
156
|
+
title: { value: 'Child pages' },
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
localId: '4890f00c-c519-4947-a60c-0c3b7e1c7b72',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/** ---------- Main upsert workflow ---------- */
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Upsert release notes at: Versions(parent) -> Version(title) -> Component(title)
|
|
169
|
+
*
|
|
170
|
+
* @param {object} args
|
|
171
|
+
* @param {string} args.versionsParentId - Page ID of the "Versions" page
|
|
172
|
+
* @param {string} args.versionTitle - e.g. "Version 1"
|
|
173
|
+
* @param {string} args.componentTitle - e.g. "Component A"
|
|
174
|
+
* @param {string} args.markdown - Release notes markdown for the component page
|
|
175
|
+
*
|
|
176
|
+
* @returns {Promise<{versionPage:any, componentPage:any}>}
|
|
177
|
+
*/
|
|
178
|
+
export async function upsertReleaseNotes({
|
|
179
|
+
versionsParentId,
|
|
180
|
+
version,
|
|
181
|
+
component,
|
|
182
|
+
markdown,
|
|
183
|
+
group,
|
|
184
|
+
}) {
|
|
185
|
+
if (!BASE_URL || !EMAIL || !API_TOKEN) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
'Missing required env: CONFLUENCE_BASE_URL, CONFLUENCE_EMAIL, CONFLUENCE_API_TOKEN',
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!versionsParentId || !version || !component) {
|
|
192
|
+
throw new Error(
|
|
193
|
+
'versionsParentId, versionTitle, and componentTitle are required',
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!markdown || markdown.trim() === '') {
|
|
198
|
+
throw new Error('markdown content is required and cannot be empty');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 1) fetch the parent to get spaceId
|
|
202
|
+
const parent = await getPage(versionsParentId);
|
|
203
|
+
const spaceId = parent.spaceId;
|
|
204
|
+
|
|
205
|
+
const versionTitle = `Docupace ${group} - Version ${version}`;
|
|
206
|
+
// 2) ensure Version page under parent
|
|
207
|
+
let versionPage = await findChildByTitle(parent.id, versionTitle);
|
|
208
|
+
if (!versionPage) {
|
|
209
|
+
versionPage = await createChildPage({
|
|
210
|
+
parentId: parent.id,
|
|
211
|
+
spaceId,
|
|
212
|
+
title: versionTitle,
|
|
213
|
+
adf: JSON.stringify(childPagesAdf),
|
|
214
|
+
message: `Create version page ${versionTitle}`,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const componentTitle = `${versionTitle} - ${component} Changelog`;
|
|
219
|
+
|
|
220
|
+
// 3) ensure Component page under Version
|
|
221
|
+
let componentPage = await findChildByTitle(versionPage.id, componentTitle);
|
|
222
|
+
const adf = adfMarkdown(markdown);
|
|
223
|
+
|
|
224
|
+
if (!componentPage) {
|
|
225
|
+
componentPage = await createChildPage({
|
|
226
|
+
parentId: versionPage.id,
|
|
227
|
+
spaceId,
|
|
228
|
+
title: componentTitle,
|
|
229
|
+
adf: JSON.stringify(adf),
|
|
230
|
+
message: `Create component page ${componentTitle}`,
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
// update existing component page with new markdown
|
|
234
|
+
componentPage = await updatePage({
|
|
235
|
+
page: componentPage,
|
|
236
|
+
title: componentTitle,
|
|
237
|
+
adf: JSON.stringify(adf),
|
|
238
|
+
message: `Update component page ${componentTitle}`,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return { versionPage, componentPage };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Upsert release notes from a markdown file
|
|
247
|
+
*
|
|
248
|
+
* @param {object} args
|
|
249
|
+
* @param {string} args.versionTitle - e.g. "Version 1"
|
|
250
|
+
* @param {string} args.componentTitle - e.g. "Component A"
|
|
251
|
+
* @param {string} args.markdownFile - Path to markdown file
|
|
252
|
+
*
|
|
253
|
+
* @returns {Promise<{versionPage:any, componentPage:any}>}
|
|
254
|
+
*/
|
|
255
|
+
export async function upsertReleaseNotesFromFile({
|
|
256
|
+
version,
|
|
257
|
+
component,
|
|
258
|
+
markdownFile,
|
|
259
|
+
group,
|
|
260
|
+
}) {
|
|
261
|
+
if (!group) {
|
|
262
|
+
throw new Error('changelog.group must be specified in package.json');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const versionsParentId =
|
|
266
|
+
process.env[`CONFLUENCE_${group.toUpperCase()}_PARENT_ID`];
|
|
267
|
+
|
|
268
|
+
if (!versionsParentId) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`CONFLUENCE_${group.toUpperCase()}_PARENT_ID environment variable is required`,
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!markdownFile) {
|
|
275
|
+
throw new Error('markdownFile is required');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Read markdown content from file
|
|
279
|
+
const markdown = readFileSync(markdownFile, 'utf8');
|
|
280
|
+
|
|
281
|
+
return upsertReleaseNotes({
|
|
282
|
+
versionsParentId,
|
|
283
|
+
version,
|
|
284
|
+
component,
|
|
285
|
+
markdown,
|
|
286
|
+
group,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export async function updateWikiWithVersion(releases) {
|
|
291
|
+
const packageNames = getPackageNames();
|
|
292
|
+
console.log(releases);
|
|
293
|
+
|
|
294
|
+
const promises = packageNames
|
|
295
|
+
.filter(
|
|
296
|
+
(packageName) =>
|
|
297
|
+
releases.find((release) => release.name == packageName.name) &&
|
|
298
|
+
packageName.content?.changelog?.component,
|
|
299
|
+
)
|
|
300
|
+
.map(async (packageName) => {
|
|
301
|
+
try {
|
|
302
|
+
const release = releases.find(
|
|
303
|
+
(release) => release.name == packageName.name,
|
|
304
|
+
);
|
|
305
|
+
await upsertReleaseNotesFromFile({
|
|
306
|
+
version: toShortVersion(release.newVersion),
|
|
307
|
+
component: packageName.content.changelog?.component,
|
|
308
|
+
markdownFile: path.join(packageName.path, 'CHANGELOG.md'),
|
|
309
|
+
group: packageName.content.changelog?.group,
|
|
310
|
+
});
|
|
311
|
+
console.log(`✅ Successfully updated wiki for ${packageName.name}`);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
console.error(
|
|
314
|
+
`❌ Failed to update wiki for ${packageName.name}:`,
|
|
315
|
+
error.message,
|
|
316
|
+
);
|
|
317
|
+
// Continue with other packages instead of stopping the build
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
await Promise.all(promises);
|
|
323
|
+
console.log('✅ Wiki update process completed');
|
|
324
|
+
} catch (error) {
|
|
325
|
+
console.error('❌ Error during wiki update process:', error.message);
|
|
326
|
+
// Don't throw the error to prevent build failure
|
|
327
|
+
}
|
|
328
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
// Get absolute path to .changeset/config.json using current working directory
|
|
5
|
+
const configPath = path.join(process.cwd(), '.changeset', 'config.json');
|
|
6
|
+
|
|
7
|
+
// Function to update baseBranch to BITBUCKET_BRANCH
|
|
8
|
+
export function updateBaseBranch() {
|
|
9
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
10
|
+
if (!process.env.BITBUCKET_BRANCH) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
let originalbaseBranch = config.baseBranch;
|
|
14
|
+
config.baseBranch = process.env.BITBUCKET_BRANCH;
|
|
15
|
+
|
|
16
|
+
if (!config.baseBranch) {
|
|
17
|
+
throw new Error('BITBUCKET_BRANCH environment variable is not set.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
21
|
+
console.log(`baseBranch updated to ${process.env.BITBUCKET_BRANCH}`);
|
|
22
|
+
|
|
23
|
+
return originalbaseBranch;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Function to revert baseBranch to original value
|
|
27
|
+
export function revertBaseBranch(originalBaseBranch) {
|
|
28
|
+
if (!originalBaseBranch) return;
|
|
29
|
+
|
|
30
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
31
|
+
config.baseBranch = originalBaseBranch;
|
|
32
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
33
|
+
console.log(`baseBranch reverted to ${originalBaseBranch}`);
|
|
34
|
+
}
|