@docupace/pipeline 1.0.77-alpha.2 → 1.0.77
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 +135 -135
- package/bin/azuread_update_callbacks_for_app.sh +58 -58
- package/bin/next-changeset-validate.sh +8 -8
- package/bitbucket-pipelines.yml +59 -59
- package/eslint.config.js +49 -49
- package/jest.config.js +15 -15
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +123 -123
- package/next/sonar.sh +23 -23
- package/package.json +1 -1
- package/src/auth0/alias.js +79 -79
- package/src/auth0/alias.test.js +172 -172
- package/src/auth0/cli.js +82 -82
- package/src/auth0/configure.js +902 -902
- package/src/auth0/configure.test.js +167 -167
- package/src/auth0/export.js +48 -48
- package/src/auth0/export.test.js +103 -103
- package/src/auth0/metadata.js +141 -141
- package/src/auth0/metadata.test.js +186 -186
- package/src/auth0/vault.js +60 -60
- package/src/auth0/vault.test.js +134 -134
- package/src/changeset/changelog-wiki.js +328 -328
- package/src/changeset/changeset-config.js +34 -34
- package/src/changeset/cli.js +237 -237
- package/src/changeset/create.js +215 -215
- package/src/changeset/package-util.js +87 -87
- package/src/changeset/util.js +43 -43
- package/src/changeset/validate.js +91 -91
- package/src/changeset/version.js +102 -102
- package/src/jenkins/setParams.groovy +58 -58
- package/src/lib/merge-driver.js +204 -204
- package/src/merge/cli-merge-all.js +507 -507
- package/src/merge/cli-merge.js +492 -492
- package/src/merge/cli-resolve.js +399 -399
- package/src/merge/cli.js +38 -38
- package/src/merge/merge-changelog.js +87 -87
- package/src/merge/merge-package.js +106 -106
- package/src/merge/merge-types.js +82 -82
- package/src/merge/pr.js +231 -231
- package/src/micro/cli.js +71 -0
- package/src/micro/ms-deploy.js +271 -0
- package/src/micro/{publish-ms.js → ms-publish.js} +6 -8
- package/src/next/alias.js +53 -53
- package/src/next/apache.js +81 -81
- package/src/next/cli.js +1 -10
- package/src/next/config.js +137 -137
- package/src/next/connect.js +226 -226
- package/src/next/copy.js +61 -61
- package/src/next/deploy.js +633 -633
- package/src/next/git-to-semver.js +79 -79
- package/src/next/haproxy.js +76 -76
- package/src/next/jenkins.js +123 -123
- package/src/next/jira.js +84 -84
- package/src/next/logger.js +17 -17
- package/src/next/pipline.js +114 -114
- package/src/next/publish.js +71 -71
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/src/next/test.js +5 -5
- package/src/next/util.js +93 -95
- package/src/next/vault.js +45 -45
- package/terraform/apply.sh +37 -37
- package/terraform/init.sh +72 -72
- package/terraform/plan.sh +76 -76
- package/terraform/validate.sh +17 -17
- package/src/micro/deploy-microservice.js +0 -153
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts git describe output to semantic versioning format
|
|
3
|
-
*
|
|
4
|
-
* Logic based on dash count:
|
|
5
|
-
* - 2 dashes: Released version with commits (v1.2.3-4-g1234567 -> 1.2.3+4.g1234567)
|
|
6
|
-
* - 3 dashes: Pre-release with commits (v1.2.3-rc.1-4-g1234567 -> 1.2.3-rc.1+4.g1234567)
|
|
7
|
-
* - 1 dash: Pre-release tag only (v1.2.3-rc.1 -> 1.2.3-rc.1)
|
|
8
|
-
* - 0 dashes: Clean tag (v1.2.3 -> 1.2.3)
|
|
9
|
-
*
|
|
10
|
-
* @param {string} gitDescribe - The output from git describe
|
|
11
|
-
* @return {string} Semver compatible version string
|
|
12
|
-
*/
|
|
13
|
-
export function gitDescribeToSemver(gitDescribe) {
|
|
14
|
-
if (!gitDescribe || typeof gitDescribe !== 'string') {
|
|
15
|
-
throw new Error('Invalid input: git describe string required');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Remove leading 'v' if present
|
|
19
|
-
let version = gitDescribe.trim();
|
|
20
|
-
if (version.startsWith('v') || version.startsWith('V')) {
|
|
21
|
-
version = version.substring(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Count dashes to determine format
|
|
25
|
-
const dashCount = (version.match(/-/g) || []).length;
|
|
26
|
-
|
|
27
|
-
switch (dashCount) {
|
|
28
|
-
case 0:
|
|
29
|
-
// Clean tag: 1.2.3
|
|
30
|
-
return version;
|
|
31
|
-
|
|
32
|
-
case 1:
|
|
33
|
-
// Pre-release tag only: 1.2.3-rc.1
|
|
34
|
-
return version;
|
|
35
|
-
|
|
36
|
-
case 2: {
|
|
37
|
-
// Released version with commits: 1.2.3-4-g1234567
|
|
38
|
-
// Split: [1.2.3, 4, g1234567]
|
|
39
|
-
const parts = version.split('-');
|
|
40
|
-
const baseVersion = parts[0];
|
|
41
|
-
const commits = parts[1];
|
|
42
|
-
const hash = parts[2];
|
|
43
|
-
return `${baseVersion}+${commits}.${hash}`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
case 3: {
|
|
47
|
-
// Pre-release with commits: 1.2.3-rc.1-4-g1234567
|
|
48
|
-
// Split: [1.2.3, rc.1, 4, g1234567]
|
|
49
|
-
const parts = version.split('-');
|
|
50
|
-
const baseVersion = parts[0];
|
|
51
|
-
const prerelease = parts[1];
|
|
52
|
-
const commits = parts[2];
|
|
53
|
-
const hash = parts[3];
|
|
54
|
-
return `${baseVersion}-${prerelease}+${commits}.${hash}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
default: {
|
|
58
|
-
// More than 3 dashes - handle complex pre-release tags
|
|
59
|
-
// e.g., 1.2.3-rc-1-beta-4-g1234567
|
|
60
|
-
// Assume last two parts are commits-hash
|
|
61
|
-
const parts = version.split('-');
|
|
62
|
-
if (
|
|
63
|
-
parts.length >= 3 &&
|
|
64
|
-
/^\d+$/.test(parts[parts.length - 2]) &&
|
|
65
|
-
/^g[a-f0-9]+$/.test(parts[parts.length - 1])
|
|
66
|
-
) {
|
|
67
|
-
// Has commits and hash at the end
|
|
68
|
-
const commits = parts[parts.length - 2];
|
|
69
|
-
const hash = parts[parts.length - 1];
|
|
70
|
-
const versionParts = parts.slice(0, -2);
|
|
71
|
-
const baseVersion = versionParts[0];
|
|
72
|
-
const prerelease = versionParts.slice(1).join('-');
|
|
73
|
-
return `${baseVersion}-${prerelease}+${commits}.${hash}`;
|
|
74
|
-
}
|
|
75
|
-
// No commits/hash pattern found, treat as complex pre-release
|
|
76
|
-
return version;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Converts git describe output to semantic versioning format
|
|
3
|
+
*
|
|
4
|
+
* Logic based on dash count:
|
|
5
|
+
* - 2 dashes: Released version with commits (v1.2.3-4-g1234567 -> 1.2.3+4.g1234567)
|
|
6
|
+
* - 3 dashes: Pre-release with commits (v1.2.3-rc.1-4-g1234567 -> 1.2.3-rc.1+4.g1234567)
|
|
7
|
+
* - 1 dash: Pre-release tag only (v1.2.3-rc.1 -> 1.2.3-rc.1)
|
|
8
|
+
* - 0 dashes: Clean tag (v1.2.3 -> 1.2.3)
|
|
9
|
+
*
|
|
10
|
+
* @param {string} gitDescribe - The output from git describe
|
|
11
|
+
* @return {string} Semver compatible version string
|
|
12
|
+
*/
|
|
13
|
+
export function gitDescribeToSemver(gitDescribe) {
|
|
14
|
+
if (!gitDescribe || typeof gitDescribe !== 'string') {
|
|
15
|
+
throw new Error('Invalid input: git describe string required');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Remove leading 'v' if present
|
|
19
|
+
let version = gitDescribe.trim();
|
|
20
|
+
if (version.startsWith('v') || version.startsWith('V')) {
|
|
21
|
+
version = version.substring(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Count dashes to determine format
|
|
25
|
+
const dashCount = (version.match(/-/g) || []).length;
|
|
26
|
+
|
|
27
|
+
switch (dashCount) {
|
|
28
|
+
case 0:
|
|
29
|
+
// Clean tag: 1.2.3
|
|
30
|
+
return version;
|
|
31
|
+
|
|
32
|
+
case 1:
|
|
33
|
+
// Pre-release tag only: 1.2.3-rc.1
|
|
34
|
+
return version;
|
|
35
|
+
|
|
36
|
+
case 2: {
|
|
37
|
+
// Released version with commits: 1.2.3-4-g1234567
|
|
38
|
+
// Split: [1.2.3, 4, g1234567]
|
|
39
|
+
const parts = version.split('-');
|
|
40
|
+
const baseVersion = parts[0];
|
|
41
|
+
const commits = parts[1];
|
|
42
|
+
const hash = parts[2];
|
|
43
|
+
return `${baseVersion}+${commits}.${hash}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
case 3: {
|
|
47
|
+
// Pre-release with commits: 1.2.3-rc.1-4-g1234567
|
|
48
|
+
// Split: [1.2.3, rc.1, 4, g1234567]
|
|
49
|
+
const parts = version.split('-');
|
|
50
|
+
const baseVersion = parts[0];
|
|
51
|
+
const prerelease = parts[1];
|
|
52
|
+
const commits = parts[2];
|
|
53
|
+
const hash = parts[3];
|
|
54
|
+
return `${baseVersion}-${prerelease}+${commits}.${hash}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
default: {
|
|
58
|
+
// More than 3 dashes - handle complex pre-release tags
|
|
59
|
+
// e.g., 1.2.3-rc-1-beta-4-g1234567
|
|
60
|
+
// Assume last two parts are commits-hash
|
|
61
|
+
const parts = version.split('-');
|
|
62
|
+
if (
|
|
63
|
+
parts.length >= 3 &&
|
|
64
|
+
/^\d+$/.test(parts[parts.length - 2]) &&
|
|
65
|
+
/^g[a-f0-9]+$/.test(parts[parts.length - 1])
|
|
66
|
+
) {
|
|
67
|
+
// Has commits and hash at the end
|
|
68
|
+
const commits = parts[parts.length - 2];
|
|
69
|
+
const hash = parts[parts.length - 1];
|
|
70
|
+
const versionParts = parts.slice(0, -2);
|
|
71
|
+
const baseVersion = versionParts[0];
|
|
72
|
+
const prerelease = versionParts.slice(1).join('-');
|
|
73
|
+
return `${baseVersion}-${prerelease}+${commits}.${hash}`;
|
|
74
|
+
}
|
|
75
|
+
// No commits/hash pattern found, treat as complex pre-release
|
|
76
|
+
return version;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/next/haproxy.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { $ } from 'zx';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
export async function haproxySync() {
|
|
6
|
-
const cluster = process.env.HAPROXY_CLUSTER;
|
|
7
|
-
if (cluster !== 'preprod' && cluster !== 'stage' && cluster !== 'prod-www3') {
|
|
8
|
-
console.log('Error: Cluster must be preprod or stage');
|
|
9
|
-
process.exit(1);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const repoPath = '/root/repo/docupace-ansible';
|
|
13
|
-
const inventory = path.join(repoPath, `inventories/${cluster}/inventory`);
|
|
14
|
-
|
|
15
|
-
// Create haproxy.sh
|
|
16
|
-
const cluserHostMap = {
|
|
17
|
-
preprod: {
|
|
18
|
-
host: '10.10.28.198',
|
|
19
|
-
branch: 'master',
|
|
20
|
-
},
|
|
21
|
-
stage: {
|
|
22
|
-
host: '10.12.28.10',
|
|
23
|
-
branch: 'master',
|
|
24
|
-
},
|
|
25
|
-
'prod-www2': {
|
|
26
|
-
host: ' 10.13.28.43',
|
|
27
|
-
branch: 'master',
|
|
28
|
-
},
|
|
29
|
-
'prod-www3': {
|
|
30
|
-
host: '10.13.28.45',
|
|
31
|
-
branch: 'master',
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const scriptContent = `
|
|
36
|
-
#!/bin/bash
|
|
37
|
-
|
|
38
|
-
[[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
|
|
39
|
-
cd ${repoPath}
|
|
40
|
-
pwd
|
|
41
|
-
git reset --hard
|
|
42
|
-
git clean -fd
|
|
43
|
-
git fetch --all
|
|
44
|
-
git pull origin master
|
|
45
|
-
git checkout ${cluserHostMap[cluster].branch}
|
|
46
|
-
git submodule update --remote
|
|
47
|
-
git submodule foreach --recursive git checkout master
|
|
48
|
-
git submodule foreach --recursive git pull origin master
|
|
49
|
-
|
|
50
|
-
ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster} -e build=true"
|
|
51
|
-
|
|
52
|
-
echo "proceeding"
|
|
53
|
-
echo "committing changes"
|
|
54
|
-
git add ${cluster}-haproxy.cfg
|
|
55
|
-
git commit -m "Sync haproxy"
|
|
56
|
-
git push origin master
|
|
57
|
-
`;
|
|
58
|
-
|
|
59
|
-
await fs.writeFile('haproxy.sh', scriptContent);
|
|
60
|
-
|
|
61
|
-
// Private key
|
|
62
|
-
const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
|
|
63
|
-
if (!haproxyPrivateKey) {
|
|
64
|
-
console.log('Error: HAPROXY_PRIVATE_KEY not set.');
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
|
|
69
|
-
await fs.chmod('private.key', 0o600);
|
|
70
|
-
|
|
71
|
-
// Copy script to remote
|
|
72
|
-
await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
|
|
73
|
-
|
|
74
|
-
// Execute script on remote
|
|
75
|
-
await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
|
|
76
|
-
}
|
|
1
|
+
import { $ } from 'zx';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export async function haproxySync() {
|
|
6
|
+
const cluster = process.env.HAPROXY_CLUSTER;
|
|
7
|
+
if (cluster !== 'preprod' && cluster !== 'stage' && cluster !== 'prod-www3') {
|
|
8
|
+
console.log('Error: Cluster must be preprod or stage');
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const repoPath = '/root/repo/docupace-ansible';
|
|
13
|
+
const inventory = path.join(repoPath, `inventories/${cluster}/inventory`);
|
|
14
|
+
|
|
15
|
+
// Create haproxy.sh
|
|
16
|
+
const cluserHostMap = {
|
|
17
|
+
preprod: {
|
|
18
|
+
host: '10.10.28.198',
|
|
19
|
+
branch: 'master',
|
|
20
|
+
},
|
|
21
|
+
stage: {
|
|
22
|
+
host: '10.12.28.10',
|
|
23
|
+
branch: 'master',
|
|
24
|
+
},
|
|
25
|
+
'prod-www2': {
|
|
26
|
+
host: ' 10.13.28.43',
|
|
27
|
+
branch: 'master',
|
|
28
|
+
},
|
|
29
|
+
'prod-www3': {
|
|
30
|
+
host: '10.13.28.45',
|
|
31
|
+
branch: 'master',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const scriptContent = `
|
|
36
|
+
#!/bin/bash
|
|
37
|
+
|
|
38
|
+
[[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
|
|
39
|
+
cd ${repoPath}
|
|
40
|
+
pwd
|
|
41
|
+
git reset --hard
|
|
42
|
+
git clean -fd
|
|
43
|
+
git fetch --all
|
|
44
|
+
git pull origin master
|
|
45
|
+
git checkout ${cluserHostMap[cluster].branch}
|
|
46
|
+
git submodule update --remote
|
|
47
|
+
git submodule foreach --recursive git checkout master
|
|
48
|
+
git submodule foreach --recursive git pull origin master
|
|
49
|
+
|
|
50
|
+
ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster} -e build=true"
|
|
51
|
+
|
|
52
|
+
echo "proceeding"
|
|
53
|
+
echo "committing changes"
|
|
54
|
+
git add ${cluster}-haproxy.cfg
|
|
55
|
+
git commit -m "Sync haproxy"
|
|
56
|
+
git push origin master
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
await fs.writeFile('haproxy.sh', scriptContent);
|
|
60
|
+
|
|
61
|
+
// Private key
|
|
62
|
+
const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
|
|
63
|
+
if (!haproxyPrivateKey) {
|
|
64
|
+
console.log('Error: HAPROXY_PRIVATE_KEY not set.');
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
|
|
69
|
+
await fs.chmod('private.key', 0o600);
|
|
70
|
+
|
|
71
|
+
// Copy script to remote
|
|
72
|
+
await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
|
|
73
|
+
|
|
74
|
+
// Execute script on remote
|
|
75
|
+
await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
|
|
76
|
+
}
|
package/src/next/jenkins.js
CHANGED
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
const CORE_JENKINS_URL = process.env.CORE_JENKINS_URL;
|
|
4
|
-
const CORE_JOB_NAME = process.env.CORE_JENKINS_JOB_NAME;
|
|
5
|
-
const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
|
-
const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
|
-
|
|
8
|
-
const CONNECT_JENKINS_URL = 'http://usdoc-s-buildui.corp.docupace.com/jenkins';
|
|
9
|
-
const CONNECT_JOB_NAME = 'docupace_build_and_run_site_v2';
|
|
10
|
-
const CONNECT_USERNAME = process.env.CONNECT_JENKINS_USERNAME;
|
|
11
|
-
const CONNECT_API_TOKEN = process.env.CONNECT_JENKINS_API_TOKEN;
|
|
12
|
-
|
|
13
|
-
export async function deployCore(env, site, liquibase, gitBranch) {
|
|
14
|
-
const parameters = {
|
|
15
|
-
environment: env,
|
|
16
|
-
site: site.toUpperCase(),
|
|
17
|
-
runLiquibase: liquibase,
|
|
18
|
-
gitBranch,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return callJenkinsJob({
|
|
22
|
-
jenkinsUrl: CORE_JENKINS_URL,
|
|
23
|
-
jobName: CORE_JOB_NAME,
|
|
24
|
-
auth: { username: CORE_USERNAME, password: CORE_API_TOKEN },
|
|
25
|
-
parameters,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line no-unused-vars
|
|
30
|
-
export async function deployConnect(env, site, liquibase, branch) {
|
|
31
|
-
const parameters = {
|
|
32
|
-
BUILD_ENVIRONMENT: env,
|
|
33
|
-
BUILD_SITE: site,
|
|
34
|
-
RUN_LIQUIBASE: liquibase,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return callJenkinsJob({
|
|
38
|
-
jenkinsUrl: CONNECT_JENKINS_URL,
|
|
39
|
-
jobName: CONNECT_JOB_NAME,
|
|
40
|
-
auth: { username: CONNECT_USERNAME, password: CONNECT_API_TOKEN },
|
|
41
|
-
parameters,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function callJenkinsJob({
|
|
46
|
-
jenkinsUrl,
|
|
47
|
-
jobName,
|
|
48
|
-
auth,
|
|
49
|
-
parameters,
|
|
50
|
-
}) {
|
|
51
|
-
try {
|
|
52
|
-
// Trigger the job
|
|
53
|
-
console.log('Triggering Jenkins job...');
|
|
54
|
-
const buildResponse = await axios.post(
|
|
55
|
-
`${jenkinsUrl}/job/${jobName}/buildWithParameters`,
|
|
56
|
-
new URLSearchParams(parameters),
|
|
57
|
-
{
|
|
58
|
-
auth,
|
|
59
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
60
|
-
validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
|
|
61
|
-
},
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const queueUrl = buildResponse.headers.location;
|
|
65
|
-
console.log(`Job queued at: ${queueUrl}`);
|
|
66
|
-
|
|
67
|
-
// Poll queue for executable URL
|
|
68
|
-
let jobUrl = null;
|
|
69
|
-
while (!jobUrl) {
|
|
70
|
-
const queueResponse = await axios.get(`${queueUrl}api/json`, {
|
|
71
|
-
auth,
|
|
72
|
-
});
|
|
73
|
-
jobUrl = queueResponse.data.executable?.url || null;
|
|
74
|
-
|
|
75
|
-
if (!jobUrl) {
|
|
76
|
-
console.log('Waiting for job to start...');
|
|
77
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
jobUrl = jobUrl.replaceAll('https', 'http');
|
|
82
|
-
|
|
83
|
-
console.log(`Job started at: ${jobUrl}`);
|
|
84
|
-
|
|
85
|
-
// Stream console output
|
|
86
|
-
const consoleUrl = `${jobUrl}consoleText`;
|
|
87
|
-
let lastSize = 0;
|
|
88
|
-
|
|
89
|
-
console.log('Streaming job output...');
|
|
90
|
-
while (true) {
|
|
91
|
-
const consoleResponse = await axios.get(consoleUrl, {
|
|
92
|
-
auth,
|
|
93
|
-
responseType: 'text',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const consoleText = consoleResponse.data;
|
|
97
|
-
const newOutput = consoleText.slice(lastSize);
|
|
98
|
-
process.stdout.write(newOutput); // Write new output to console
|
|
99
|
-
lastSize = consoleText.length;
|
|
100
|
-
|
|
101
|
-
// Check job status
|
|
102
|
-
const jobResponse = await axios.get(`${jobUrl}api/json`, {
|
|
103
|
-
auth,
|
|
104
|
-
});
|
|
105
|
-
const result = jobResponse.data.result;
|
|
106
|
-
|
|
107
|
-
if (result) {
|
|
108
|
-
console.log(`\nJob completed with result: ${result}`);
|
|
109
|
-
if (result === 'SUCCESS') {
|
|
110
|
-
return;
|
|
111
|
-
} else {
|
|
112
|
-
throw new Error('Jenkins job failed');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Wait before polling again
|
|
117
|
-
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
118
|
-
}
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.error('Error:', error.message);
|
|
121
|
-
throw error;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
const CORE_JENKINS_URL = process.env.CORE_JENKINS_URL;
|
|
4
|
+
const CORE_JOB_NAME = process.env.CORE_JENKINS_JOB_NAME;
|
|
5
|
+
const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
|
+
const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
|
+
|
|
8
|
+
const CONNECT_JENKINS_URL = 'http://usdoc-s-buildui.corp.docupace.com/jenkins';
|
|
9
|
+
const CONNECT_JOB_NAME = 'docupace_build_and_run_site_v2';
|
|
10
|
+
const CONNECT_USERNAME = process.env.CONNECT_JENKINS_USERNAME;
|
|
11
|
+
const CONNECT_API_TOKEN = process.env.CONNECT_JENKINS_API_TOKEN;
|
|
12
|
+
|
|
13
|
+
export async function deployCore(env, site, liquibase, gitBranch) {
|
|
14
|
+
const parameters = {
|
|
15
|
+
environment: env,
|
|
16
|
+
site: site.toUpperCase(),
|
|
17
|
+
runLiquibase: liquibase,
|
|
18
|
+
gitBranch,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return callJenkinsJob({
|
|
22
|
+
jenkinsUrl: CORE_JENKINS_URL,
|
|
23
|
+
jobName: CORE_JOB_NAME,
|
|
24
|
+
auth: { username: CORE_USERNAME, password: CORE_API_TOKEN },
|
|
25
|
+
parameters,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line no-unused-vars
|
|
30
|
+
export async function deployConnect(env, site, liquibase, branch) {
|
|
31
|
+
const parameters = {
|
|
32
|
+
BUILD_ENVIRONMENT: env,
|
|
33
|
+
BUILD_SITE: site,
|
|
34
|
+
RUN_LIQUIBASE: liquibase,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return callJenkinsJob({
|
|
38
|
+
jenkinsUrl: CONNECT_JENKINS_URL,
|
|
39
|
+
jobName: CONNECT_JOB_NAME,
|
|
40
|
+
auth: { username: CONNECT_USERNAME, password: CONNECT_API_TOKEN },
|
|
41
|
+
parameters,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function callJenkinsJob({
|
|
46
|
+
jenkinsUrl,
|
|
47
|
+
jobName,
|
|
48
|
+
auth,
|
|
49
|
+
parameters,
|
|
50
|
+
}) {
|
|
51
|
+
try {
|
|
52
|
+
// Trigger the job
|
|
53
|
+
console.log('Triggering Jenkins job...');
|
|
54
|
+
const buildResponse = await axios.post(
|
|
55
|
+
`${jenkinsUrl}/job/${jobName}/buildWithParameters`,
|
|
56
|
+
new URLSearchParams(parameters),
|
|
57
|
+
{
|
|
58
|
+
auth,
|
|
59
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
60
|
+
validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const queueUrl = buildResponse.headers.location;
|
|
65
|
+
console.log(`Job queued at: ${queueUrl}`);
|
|
66
|
+
|
|
67
|
+
// Poll queue for executable URL
|
|
68
|
+
let jobUrl = null;
|
|
69
|
+
while (!jobUrl) {
|
|
70
|
+
const queueResponse = await axios.get(`${queueUrl}api/json`, {
|
|
71
|
+
auth,
|
|
72
|
+
});
|
|
73
|
+
jobUrl = queueResponse.data.executable?.url || null;
|
|
74
|
+
|
|
75
|
+
if (!jobUrl) {
|
|
76
|
+
console.log('Waiting for job to start...');
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
jobUrl = jobUrl.replaceAll('https', 'http');
|
|
82
|
+
|
|
83
|
+
console.log(`Job started at: ${jobUrl}`);
|
|
84
|
+
|
|
85
|
+
// Stream console output
|
|
86
|
+
const consoleUrl = `${jobUrl}consoleText`;
|
|
87
|
+
let lastSize = 0;
|
|
88
|
+
|
|
89
|
+
console.log('Streaming job output...');
|
|
90
|
+
while (true) {
|
|
91
|
+
const consoleResponse = await axios.get(consoleUrl, {
|
|
92
|
+
auth,
|
|
93
|
+
responseType: 'text',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const consoleText = consoleResponse.data;
|
|
97
|
+
const newOutput = consoleText.slice(lastSize);
|
|
98
|
+
process.stdout.write(newOutput); // Write new output to console
|
|
99
|
+
lastSize = consoleText.length;
|
|
100
|
+
|
|
101
|
+
// Check job status
|
|
102
|
+
const jobResponse = await axios.get(`${jobUrl}api/json`, {
|
|
103
|
+
auth,
|
|
104
|
+
});
|
|
105
|
+
const result = jobResponse.data.result;
|
|
106
|
+
|
|
107
|
+
if (result) {
|
|
108
|
+
console.log(`\nJob completed with result: ${result}`);
|
|
109
|
+
if (result === 'SUCCESS') {
|
|
110
|
+
return;
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error('Jenkins job failed');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Wait before polling again
|
|
117
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error('Error:', error.message);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|