@docupace/pipeline 1.0.61-alpha.1 → 1.0.62
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/bitbucket-pipelines.yml +28 -0
- package/eslint.config.js +12 -0
- package/package.json +11 -8
- package/src/auth0/configure.js +88 -54
- package/src/changeset/cli.js +0 -46
- package/src/changeset/create.js +5 -15
- package/src/changeset/package-util.js +1 -2
- package/src/changeset/util.js +6 -6
- package/src/changeset/validate.js +24 -23
- package/src/micro/deploy-microservice.js +140 -0
- package/src/micro/publish-ms.js +188 -0
- package/src/next/apache.js +2 -2
- package/src/next/cli.js +9 -1
- package/src/next/connect.js +1 -2
- package/src/changeset/changelog-wiki.js +0 -313
- package/src/lib/merge-driver.js +0 -204
- package/src/merge/cli-merge-all.js +0 -472
- package/src/merge/cli-merge.js +0 -492
- package/src/merge/cli-resolve.js +0 -395
- package/src/merge/cli.js +0 -38
- package/src/merge/merge-changelog.js +0 -87
- package/src/merge/merge-package.js +0 -106
- package/src/merge/merge-types.js +0 -82
- package/src/merge/pr.js +0 -85
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { $ } from '../next/logger.js';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export async function deployMicroservice(
|
|
6
|
+
appName,
|
|
7
|
+
helmPath,
|
|
8
|
+
environment = 'dev',
|
|
9
|
+
tag = null,
|
|
10
|
+
) {
|
|
11
|
+
if (!appName || !helmPath) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
'Missing required parameters. Usage: deployMicroservice(appName, helmPath, [environment], [tag])',
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let deployTag = tag;
|
|
18
|
+
if (!deployTag) {
|
|
19
|
+
deployTag =
|
|
20
|
+
process.env.VERSION_TAG ||
|
|
21
|
+
process.env.BITBUCKET_TAG ||
|
|
22
|
+
(process.env.BITBUCKET_BUILD_NUMBER
|
|
23
|
+
? `build-${process.env.BITBUCKET_BUILD_NUMBER}`
|
|
24
|
+
: null);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!deployTag) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
'No tag specified and no default tag available from environment variables',
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const repoName = `gitops-${environment}`;
|
|
34
|
+
const filePath = `dp/${helmPath}/${appName}.values.yaml`;
|
|
35
|
+
|
|
36
|
+
const gitopsBranch =
|
|
37
|
+
environment === 'dev' || environment === 'uat'
|
|
38
|
+
? process.env.GITOPS_BRANCH || 'master'
|
|
39
|
+
: process.env.GITOPS_BRANCH || 'main';
|
|
40
|
+
|
|
41
|
+
let repoUrl;
|
|
42
|
+
if (environment === 'dev' && process.env.GITOPS_REP_TOKEN) {
|
|
43
|
+
repoUrl = `https://x-token-auth:${process.env.GITOPS_REP_TOKEN}@bitbucket.org/dp-cloud/${repoName}.git`;
|
|
44
|
+
} else if (
|
|
45
|
+
process.env.BITBUCKET_USERNAME &&
|
|
46
|
+
process.env.BITBUCKET_APP_PASSWORD
|
|
47
|
+
) {
|
|
48
|
+
repoUrl = `https://${process.env.BITBUCKET_USERNAME}:${process.env.BITBUCKET_APP_PASSWORD}@bitbucket.org/dp-cloud/${repoName}.git`;
|
|
49
|
+
} else {
|
|
50
|
+
throw new Error(
|
|
51
|
+
'No authentication credentials found for GitOps repository',
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log('=========================================');
|
|
56
|
+
console.log('Microservice Deployment Configuration');
|
|
57
|
+
console.log('=========================================');
|
|
58
|
+
console.log(`Application: ${appName}`);
|
|
59
|
+
console.log(`Environment: ${environment}`);
|
|
60
|
+
console.log(`Tag: ${deployTag}`);
|
|
61
|
+
console.log(`GitOps Repo: ${repoName}`);
|
|
62
|
+
console.log(`Values File: ${filePath}`);
|
|
63
|
+
console.log(`Branch: ${gitopsBranch}`);
|
|
64
|
+
console.log('=========================================');
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
console.log('Cloning GitOps repository...');
|
|
68
|
+
await $`git clone --depth 1 ${repoUrl} ${repoName}`;
|
|
69
|
+
|
|
70
|
+
console.log('Checking if directory exists...');
|
|
71
|
+
await $`ls -la ${repoName}`;
|
|
72
|
+
|
|
73
|
+
console.log(`Changing to directory: ${repoName}`);
|
|
74
|
+
const originalDir = process.cwd();
|
|
75
|
+
process.chdir(repoName);
|
|
76
|
+
|
|
77
|
+
console.log('Verifying directory change...');
|
|
78
|
+
const newDir = process.cwd();
|
|
79
|
+
console.log(`Original: ${originalDir}`);
|
|
80
|
+
console.log(`New: ${newDir}`);
|
|
81
|
+
|
|
82
|
+
await $`cd ${repoName} && git config user.email "pipeline@bitbucket.org"`;
|
|
83
|
+
await $`cd ${repoName} && git config user.name "Bitbucket Pipeline"`;
|
|
84
|
+
|
|
85
|
+
console.log(`Attempting to checkout branch: ${gitopsBranch}`);
|
|
86
|
+
await $`cd ${repoName} && git checkout ${gitopsBranch}`;
|
|
87
|
+
|
|
88
|
+
const fullFilePath = path.resolve(filePath);
|
|
89
|
+
console.log(`Looking for file at: ${fullFilePath}`);
|
|
90
|
+
if (!fs.existsSync(fullFilePath)) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Values file ${filePath} does not exist in ${repoName} on branch ${gitopsBranch}`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
console.log(`Updating image tag to ${deployTag}...`);
|
|
97
|
+
|
|
98
|
+
let fileContent = fs.readFileSync(fullFilePath, 'utf8');
|
|
99
|
+
|
|
100
|
+
const tagRegex = /^ {2}tag: .*/gm;
|
|
101
|
+
const newContent = fileContent.replace(tagRegex, ` tag: ${deployTag}`);
|
|
102
|
+
|
|
103
|
+
if (fileContent === newContent) {
|
|
104
|
+
console.log(`No changes detected - tag is already ${deployTag}`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
fs.writeFileSync(fullFilePath, newContent, 'utf8');
|
|
109
|
+
|
|
110
|
+
console.log('Changes to be committed:');
|
|
111
|
+
await $`cd ${repoName} && git diff ${filePath}`;
|
|
112
|
+
|
|
113
|
+
await $`cd ${repoName} && git add ${filePath}`;
|
|
114
|
+
await $`cd ${repoName} && git commit -m "Update ${appName} image tag to ${deployTag} in ${environment} environment"`;
|
|
115
|
+
|
|
116
|
+
console.log('Pushing changes to GitOps repository...');
|
|
117
|
+
await $`cd ${repoName} && git push origin ${gitopsBranch}`;
|
|
118
|
+
|
|
119
|
+
console.log('=========================================');
|
|
120
|
+
console.log(
|
|
121
|
+
`✅ Successfully deployed ${appName}:${deployTag} to ${environment}`,
|
|
122
|
+
);
|
|
123
|
+
console.log('=========================================');
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Error during microservice deployment:', error.message);
|
|
126
|
+
throw error;
|
|
127
|
+
} finally {
|
|
128
|
+
try {
|
|
129
|
+
process.chdir('..');
|
|
130
|
+
await $`rm -rf ${repoName}`;
|
|
131
|
+
} catch (cleanupError) {
|
|
132
|
+
console.warn(
|
|
133
|
+
'Warning: Failed to clean up temporary directory:',
|
|
134
|
+
cleanupError.message,
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export default deployMicroservice;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { $ } from '../next/logger.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Publish Docker images for microservices with flexible naming
|
|
5
|
+
* @param {string} gitSha - Git commit SHA
|
|
6
|
+
* @param {Object} options - Configuration options
|
|
7
|
+
* @param {string} options.imageName - Docker image name (e.g., 'swp')
|
|
8
|
+
* @param {string} options.registryUrl - JFrog registry URL
|
|
9
|
+
* @param {string} options.repoName - Repository name in JFrog
|
|
10
|
+
* @param {string} options.username - JFrog username
|
|
11
|
+
* @param {string} options.password - JFrog password
|
|
12
|
+
* @param {string} options.buildNumber - Build number
|
|
13
|
+
*/
|
|
14
|
+
export async function publishMicroservice(gitSha, options = {}) {
|
|
15
|
+
// Use environment variables as defaults, but allow overrides
|
|
16
|
+
const config = {
|
|
17
|
+
imageName:
|
|
18
|
+
options.imageName || process.env.IMAGE_NAME || process.env.APP_NAME,
|
|
19
|
+
registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
|
|
20
|
+
repoName: options.repoName || process.env.JF_REGISTRY_REPO_NAME,
|
|
21
|
+
username: options.username || process.env.JF_REGISTRY_USER_DEV,
|
|
22
|
+
password: options.password || process.env.JF_REGISTRY_PASSWORD_DEV,
|
|
23
|
+
buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
|
|
24
|
+
tag:
|
|
25
|
+
options.tag ||
|
|
26
|
+
process.env.TAG ||
|
|
27
|
+
process.env.BITBUCKET_TAG ||
|
|
28
|
+
process.env.VERSION_TAG,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Validate required fields
|
|
32
|
+
if (!config.imageName) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
'Image name is required. Set IMAGE_NAME or APP_NAME environment variable.',
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log('=== Docker Image Publishing Configuration ===');
|
|
39
|
+
console.log(`Image Name: ${config.imageName}`);
|
|
40
|
+
console.log(`Git SHA: ${gitSha}`);
|
|
41
|
+
console.log(`Build Number: ${config.buildNumber}`);
|
|
42
|
+
console.log(`Version Tag: ${config.tag || 'none'}`);
|
|
43
|
+
console.log(`Registry: ${config.registryUrl}/${config.repoName}`);
|
|
44
|
+
console.log('==========================================');
|
|
45
|
+
|
|
46
|
+
const registryPath = `${config.registryUrl}/${config.repoName}`;
|
|
47
|
+
const SHA_IMAGE_NAME = `${config.imageName}:sha-${gitSha}`;
|
|
48
|
+
|
|
49
|
+
// Docker login
|
|
50
|
+
await $`echo ${config.password} | docker login --username ${config.username} --password-stdin ${config.registryUrl}`;
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
// Build the image if it doesn't exist locally
|
|
54
|
+
const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
|
|
55
|
+
if (!imageExists) {
|
|
56
|
+
console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
|
|
57
|
+
await $`docker build -t ${SHA_IMAGE_NAME} .`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Array to track all tags we're pushing
|
|
61
|
+
const tagsToPush = [];
|
|
62
|
+
|
|
63
|
+
// 1. Push SHA tag
|
|
64
|
+
const shaTag = `${registryPath}/${SHA_IMAGE_NAME}`;
|
|
65
|
+
console.log(`Tagging and pushing SHA: ${shaTag}`);
|
|
66
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${shaTag}`;
|
|
67
|
+
await $`docker push ${shaTag}`;
|
|
68
|
+
tagsToPush.push(SHA_IMAGE_NAME);
|
|
69
|
+
|
|
70
|
+
// 2. Push build number tag
|
|
71
|
+
if (config.buildNumber) {
|
|
72
|
+
const BUILD_IMAGE_NAME = `${config.imageName}:build-${config.buildNumber}`;
|
|
73
|
+
const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
|
|
74
|
+
console.log(`Tagging and pushing build: ${buildTag}`);
|
|
75
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
|
|
76
|
+
await $`docker push ${buildTag}`;
|
|
77
|
+
tagsToPush.push(BUILD_IMAGE_NAME);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 3. Push version tag (this is what ArgoCD needs!)
|
|
81
|
+
if (config.tag) {
|
|
82
|
+
// Handle various tag formats
|
|
83
|
+
let version = config.tag;
|
|
84
|
+
|
|
85
|
+
// If tag contains @, extract version after it
|
|
86
|
+
if (version.includes('@')) {
|
|
87
|
+
version = 'v' + version.split('@')[1];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Ensure version starts with 'v' if it's a semver without it
|
|
91
|
+
if (/^\d+\.\d+\.\d+/.test(version) && !version.startsWith('v')) {
|
|
92
|
+
version = 'v' + version;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const VERSION_IMAGE_NAME = `${config.imageName}:${version}`;
|
|
96
|
+
const versionTag = `${registryPath}/${VERSION_IMAGE_NAME}`;
|
|
97
|
+
|
|
98
|
+
console.log(`Tagging and pushing version: ${versionTag}`);
|
|
99
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${versionTag}`;
|
|
100
|
+
await $`docker push ${versionTag}`;
|
|
101
|
+
tagsToPush.push(VERSION_IMAGE_NAME);
|
|
102
|
+
|
|
103
|
+
// Also push 'latest' tag when we have a version
|
|
104
|
+
const LATEST_IMAGE_NAME = `${config.imageName}:latest`;
|
|
105
|
+
const latestTag = `${registryPath}/${LATEST_IMAGE_NAME}`;
|
|
106
|
+
console.log(`Tagging and pushing latest: ${latestTag}`);
|
|
107
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${latestTag}`;
|
|
108
|
+
await $`docker push ${latestTag}`;
|
|
109
|
+
tagsToPush.push(LATEST_IMAGE_NAME);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 4. Check for git tags at current commit
|
|
113
|
+
try {
|
|
114
|
+
const gitTags = (await $`git tag --points-at HEAD`).stdout
|
|
115
|
+
.trim()
|
|
116
|
+
.split('\n')
|
|
117
|
+
.filter(Boolean);
|
|
118
|
+
|
|
119
|
+
if (gitTags.length > 0) {
|
|
120
|
+
console.log(`Found git tags at HEAD: ${gitTags.join(', ')}`);
|
|
121
|
+
|
|
122
|
+
for (const gitTag of gitTags) {
|
|
123
|
+
// Skip if we already handled this tag above
|
|
124
|
+
if (gitTag === config.tag) continue;
|
|
125
|
+
|
|
126
|
+
let version = gitTag;
|
|
127
|
+
if (version.includes('@')) {
|
|
128
|
+
version = 'v' + version.split('@')[1];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const TAG_IMAGE_NAME = `${config.imageName}:${version}`;
|
|
132
|
+
const gitTagPath = `${registryPath}/${TAG_IMAGE_NAME}`;
|
|
133
|
+
|
|
134
|
+
console.log(`Tagging and pushing git tag: ${gitTagPath}`);
|
|
135
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${gitTagPath}`;
|
|
136
|
+
await $`docker push ${gitTagPath}`;
|
|
137
|
+
tagsToPush.push(TAG_IMAGE_NAME);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} catch (e) {
|
|
141
|
+
console.log('No git tags found at HEAD or error checking tags', e);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
console.log('\n✅ Docker image published successfully!');
|
|
145
|
+
console.log('=== Summary of pushed tags ===');
|
|
146
|
+
tagsToPush.forEach((tag) => console.log(` ✓ ${tag}`));
|
|
147
|
+
console.log('==============================\n');
|
|
148
|
+
|
|
149
|
+
// Verify the version tag if we expect one
|
|
150
|
+
if (config.tag) {
|
|
151
|
+
const version = config.tag.includes('@')
|
|
152
|
+
? 'v' + config.tag.split('@')[1]
|
|
153
|
+
: config.tag;
|
|
154
|
+
const expectedTag = `${registryPath}/${config.imageName}:${version}`;
|
|
155
|
+
console.log(`Verifying version tag exists: ${expectedTag}`);
|
|
156
|
+
try {
|
|
157
|
+
await $`docker manifest inspect ${expectedTag}`;
|
|
158
|
+
console.log('✅ Version tag verified in registry!');
|
|
159
|
+
} catch (e) {
|
|
160
|
+
console.error('❌ WARNING: Could not verify version tag in registry!');
|
|
161
|
+
console.error('ArgoCD may fail to pull this image.', e);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error('Error during image publishing:', error);
|
|
166
|
+
throw error;
|
|
167
|
+
} finally {
|
|
168
|
+
// Always logout
|
|
169
|
+
await $`docker logout ${config.registryUrl}`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function checkLocalImage(imageName) {
|
|
174
|
+
try {
|
|
175
|
+
$.verbose = false;
|
|
176
|
+
await $`docker image inspect ${imageName}`;
|
|
177
|
+
return true;
|
|
178
|
+
} catch {
|
|
179
|
+
return false;
|
|
180
|
+
} finally {
|
|
181
|
+
$.verbose = true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Backward compatibility wrapper
|
|
186
|
+
export async function publishWithDefaults(gitSha) {
|
|
187
|
+
return publishMicroservice(gitSha);
|
|
188
|
+
}
|
package/src/next/apache.js
CHANGED
|
@@ -8,7 +8,7 @@ function log(msg) {
|
|
|
8
8
|
export async function addApacheSite() {
|
|
9
9
|
if (
|
|
10
10
|
!process.env.ENVIRONMENT ||
|
|
11
|
-
!['dev', 'qa', 'uat', 'stage','www3'].includes(process.env.ENVIRONMENT)
|
|
11
|
+
!['dev', 'qa', 'uat', 'stage', 'www3'].includes(process.env.ENVIRONMENT)
|
|
12
12
|
) {
|
|
13
13
|
log('Error: wront ENVIRONMENT');
|
|
14
14
|
process.exit(1);
|
|
@@ -69,7 +69,7 @@ export async function addApacheSite() {
|
|
|
69
69
|
apacheEnvHostMap[process.env.ENVIRONMENT].host1,
|
|
70
70
|
`/root/repo/${apacheEnvHostMap[process.env.ENVIRONMENT].repo}/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`,
|
|
71
71
|
);
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
await sshCmd(
|
|
74
74
|
apacheEnvHostMap[process.env.ENVIRONMENT].host2,
|
|
75
75
|
`/root/tomcat_repo_sync.sh`,
|
package/src/next/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Command } from 'commander';
|
|
|
4
4
|
import { pull } from './pull.js';
|
|
5
5
|
import { sonar } from './sonar.js';
|
|
6
6
|
import { publish } from './publish.js';
|
|
7
|
+
import { publishMicroservice } from '../micro/publish-ms.js';
|
|
7
8
|
import {
|
|
8
9
|
deployAppWithTag,
|
|
9
10
|
deployFromSite,
|
|
@@ -82,6 +83,14 @@ program
|
|
|
82
83
|
await publish(GIT_SHA);
|
|
83
84
|
});
|
|
84
85
|
|
|
86
|
+
// Add the new publish-microservice command
|
|
87
|
+
program
|
|
88
|
+
.command('publish-microservice')
|
|
89
|
+
.description('Publish a microservice Docker image with version tags')
|
|
90
|
+
.action(async () => {
|
|
91
|
+
await publishMicroservice(GIT_SHA);
|
|
92
|
+
});
|
|
93
|
+
|
|
85
94
|
program
|
|
86
95
|
.command('deploy-from-site')
|
|
87
96
|
.description('Deploy an application for a specific site')
|
|
@@ -123,7 +132,6 @@ program
|
|
|
123
132
|
await deployTemplate(env, site, deployTag, 'siteConfigRemoteBranch');
|
|
124
133
|
});
|
|
125
134
|
|
|
126
|
-
|
|
127
135
|
program
|
|
128
136
|
.command('deploy-app <application>')
|
|
129
137
|
.description('Deploy an application for a specific site')
|
package/src/next/connect.js
CHANGED
|
@@ -20,7 +20,6 @@ const connectUIEnvMap = {
|
|
|
20
20
|
prod: 'prod-www3',
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
24
23
|
const siteSettingsEnvMap = {
|
|
25
24
|
dev: 'dev',
|
|
26
25
|
preprod: 'preprod',
|
|
@@ -158,7 +157,7 @@ export async function connectClone() {
|
|
|
158
157
|
try {
|
|
159
158
|
// Execute the shell command
|
|
160
159
|
const result =
|
|
161
|
-
|
|
160
|
+
await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
162
161
|
await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
|
|
163
162
|
await $`cd ${cloneTo} && git remote -v`;
|
|
164
163
|
await $`cd ${cloneTo} && git branch`;
|
|
@@ -1,313 +0,0 @@
|
|
|
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
|
-
const release = releases.find(
|
|
302
|
-
(release) => release.name == packageName.name,
|
|
303
|
-
);
|
|
304
|
-
await upsertReleaseNotesFromFile({
|
|
305
|
-
version: toShortVersion(release.newVersion),
|
|
306
|
-
component: packageName.content.changelog?.component,
|
|
307
|
-
markdownFile: path.join(packageName.path, 'CHANGELOG.md'),
|
|
308
|
-
group: packageName.content.changelog?.group,
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
await Promise.all(promises);
|
|
313
|
-
}
|