@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.
Files changed (68) hide show
  1. package/.prettierrc.cjs +12 -12
  2. package/README.md +136 -0
  3. package/bin/azuread_update_callbacks_for_app.sh +58 -0
  4. package/bin/next-changeset-validate.sh +8 -8
  5. package/bitbucket-pipelines.yml +60 -0
  6. package/eslint.config.js +49 -26
  7. package/jest.config.js +15 -0
  8. package/next/changeset.sh +75 -75
  9. package/next/copy.sh +34 -34
  10. package/next/deploy.sh +40 -40
  11. package/next/execute.sh +123 -117
  12. package/next/sonar.sh +23 -23
  13. package/package.json +23 -7
  14. package/src/auth0/alias.js +79 -0
  15. package/src/auth0/alias.test.js +172 -0
  16. package/src/auth0/cli.js +82 -0
  17. package/src/auth0/configure.js +902 -0
  18. package/src/auth0/configure.test.js +167 -0
  19. package/src/auth0/export.js +48 -0
  20. package/src/auth0/export.test.js +103 -0
  21. package/src/auth0/metadata.js +141 -0
  22. package/src/auth0/metadata.test.js +186 -0
  23. package/src/auth0/vault.js +60 -0
  24. package/src/auth0/vault.test.js +134 -0
  25. package/src/changeset/changelog-wiki.js +328 -0
  26. package/src/changeset/changeset-config.js +34 -0
  27. package/src/changeset/cli.js +237 -281
  28. package/src/changeset/create.js +215 -0
  29. package/src/changeset/package-util.js +87 -0
  30. package/src/changeset/util.js +43 -0
  31. package/src/changeset/validate.js +91 -47
  32. package/src/changeset/version.js +102 -0
  33. package/src/jenkins/setParams.groovy +58 -59
  34. package/src/lib/merge-driver.js +204 -0
  35. package/src/merge/cli-merge-all.js +507 -0
  36. package/src/merge/cli-merge.js +492 -0
  37. package/src/merge/cli-resolve.js +399 -0
  38. package/src/merge/cli.js +38 -0
  39. package/src/merge/merge-changelog.js +87 -0
  40. package/src/merge/merge-package.js +106 -0
  41. package/src/merge/merge-types.js +82 -0
  42. package/src/merge/pr.js +231 -0
  43. package/src/micro/cli.js +71 -0
  44. package/src/micro/ms-deploy.js +273 -0
  45. package/src/micro/ms-publish.js +186 -0
  46. package/src/next/alias.js +53 -0
  47. package/src/next/apache.js +81 -0
  48. package/src/next/cli.js +111 -15
  49. package/src/next/config.js +137 -72
  50. package/src/next/connect.js +226 -0
  51. package/src/next/copy.js +61 -30
  52. package/src/next/deploy.js +633 -312
  53. package/src/next/git-to-semver.js +79 -0
  54. package/src/next/haproxy.js +76 -0
  55. package/src/next/jenkins.js +123 -88
  56. package/src/next/jira.js +84 -0
  57. package/src/next/logger.js +17 -0
  58. package/src/next/pipline.js +114 -115
  59. package/src/next/publish.js +71 -48
  60. package/src/next/pull.js +7 -7
  61. package/src/next/sonar.js +23 -23
  62. package/src/next/test.js +5 -0
  63. package/src/next/util.js +93 -0
  64. package/src/next/vault.js +45 -0
  65. package/terraform/apply.sh +37 -0
  66. package/terraform/init.sh +72 -0
  67. package/terraform/plan.sh +76 -0
  68. package/terraform/validate.sh +17 -0
@@ -0,0 +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
+ }
@@ -0,0 +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,88 +1,123 @@
1
- import axios from 'axios';
2
-
3
- const JENKINS_URL = 'http://devops.corp.docupace.com';
4
- const JOB_NAME = 'auto-deploy-site';
5
- const USERNAME = process.env.CORE_JENKINS_USERNAME;
6
- const API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
7
-
8
- export async function deployCore(env, site, liquibase, gitBranch) {
9
- const parameters = {
10
- environment: env,
11
- site: site.toUpperCase(),
12
- runLiquibase: liquibase,
13
- gitBranch,
14
- };
15
-
16
- try {
17
- // Trigger the job
18
- console.log('Triggering Jenkins job...');
19
- const buildResponse = await axios.post(
20
- `${JENKINS_URL}/job/${JOB_NAME}/buildWithParameters`,
21
- new URLSearchParams(parameters),
22
- {
23
- auth: { username: USERNAME, password: API_TOKEN },
24
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
25
- validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
26
- },
27
- );
28
-
29
- const queueUrl = buildResponse.headers.location;
30
- console.log(`Job queued at: ${queueUrl}`);
31
-
32
- // Poll queue for executable URL
33
- let jobUrl = null;
34
- while (!jobUrl) {
35
- const queueResponse = await axios.get(`${queueUrl}api/json`, {
36
- auth: { username: USERNAME, password: API_TOKEN },
37
- });
38
- jobUrl = queueResponse.data.executable?.url || null;
39
-
40
- if (!jobUrl) {
41
- console.log('Waiting for job to start...');
42
- await new Promise((resolve) => setTimeout(resolve, 5000));
43
- }
44
- }
45
-
46
- jobUrl = jobUrl.replaceAll('https', 'http');
47
-
48
- console.log(`Job started at: ${jobUrl}`);
49
-
50
- // Stream console output
51
- const consoleUrl = `${jobUrl}consoleText`;
52
- let lastSize = 0;
53
-
54
- console.log('Streaming job output...');
55
- while (true) {
56
- const consoleResponse = await axios.get(consoleUrl, {
57
- auth: { username: USERNAME, password: API_TOKEN },
58
- responseType: 'text',
59
- });
60
-
61
- const consoleText = consoleResponse.data;
62
- const newOutput = consoleText.slice(lastSize);
63
- process.stdout.write(newOutput); // Write new output to console
64
- lastSize = consoleText.length;
65
-
66
- // Check job status
67
- const jobResponse = await axios.get(`${jobUrl}api/json`, {
68
- auth: { username: USERNAME, password: API_TOKEN },
69
- });
70
- const result = jobResponse.data.result;
71
-
72
- if (result) {
73
- console.log(`\nJob completed with result: ${result}`);
74
- if (result === 'SUCCESS') {
75
- process.exit(0);
76
- } else {
77
- process.exit(1);
78
- }
79
- }
80
-
81
- // Wait before polling again
82
- await new Promise((resolve) => setTimeout(resolve, 5000));
83
- }
84
- } catch (error) {
85
- console.error('Error:', error.message);
86
- process.exit(1);
87
- }
88
- }
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
+ }
@@ -0,0 +1,84 @@
1
+ import axios from 'axios';
2
+
3
+ // Create preconfigured axios instance for Jira
4
+ const jiraClient = axios.create({
5
+ baseURL: 'https://docupacellc.atlassian.net',
6
+ auth: {
7
+ username: process.env.JIRA_API_EMAIL,
8
+ password: process.env.JIRA_API_KEY,
9
+ },
10
+ headers: {
11
+ 'Content-Type': 'application/json',
12
+ },
13
+ });
14
+
15
+ /**
16
+ * Updates the component version custom field in Jira
17
+ * @param {string} issueKey - The Jira issue key
18
+ * @param {string} packageName - The package name
19
+ * @param {string} version - The version to set
20
+ */
21
+ export async function updateComponentVersion(issueKey, packageName, version) {
22
+ const component = packageName.includes('/')
23
+ ? packageName.split('/')[1]
24
+ : packageName;
25
+ console.log(
26
+ `Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
27
+ );
28
+ try {
29
+ // First get current field value
30
+ const response = await jiraClient.get(
31
+ `/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
32
+ );
33
+
34
+ let currentValue = response.data.fields.customfield_10458 || '';
35
+ let components = new Map();
36
+
37
+ try {
38
+ // Parse existing components
39
+ if (currentValue) {
40
+ currentValue.split(';').forEach((entry) => {
41
+ const [comp, ver] = entry.split(':');
42
+ components.set(comp, ver);
43
+ });
44
+ }
45
+ // Update or add new component version
46
+ } catch {
47
+ console.log('Patch version has incorrect data overriding');
48
+ }
49
+
50
+ components.set(component, version);
51
+
52
+ // Convert back to string format
53
+ const newValue = Array.from(components.entries())
54
+ .map(([comp, ver]) => `${comp}:${ver}`)
55
+ .join(';');
56
+
57
+ // Update the field
58
+ await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
59
+ fields: {
60
+ customfield_10458: newValue,
61
+ },
62
+ });
63
+
64
+ console.log(`Updated component versions for ${issueKey}: ${newValue}`);
65
+ } catch (error) {
66
+ console.error(`Error updating Jira component version: ${error.message}`);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Makes a request to the Jira API using preconfigured client
72
+ * @param {string} endpoint - The API endpoint (starting with /)
73
+ * @param {Object} options - Request options (method, body, etc)
74
+ * @returns {Promise<any>} The response data
75
+ */
76
+ export async function makeJiraRequest(endpoint, options = {}) {
77
+ try {
78
+ const response = await jiraClient.get(endpoint, options);
79
+ return response.data;
80
+ } catch (error) {
81
+ console.error(`Error making Jira request: ${error.message}`);
82
+ throw error;
83
+ }
84
+ }
@@ -0,0 +1,17 @@
1
+ import { $ as original$ } from 'zx';
2
+
3
+ // Wrapped version of $
4
+ export const $ = async (strings, ...values) => {
5
+ const command = strings.reduce(
6
+ (acc, str, i) => acc + str + (values[i] ?? ''),
7
+ '',
8
+ );
9
+ console.log(`Executing: ${command}`);
10
+ try {
11
+ const result = await original$(strings, ...values);
12
+ return result;
13
+ } catch (error) {
14
+ console.error(`Error executing: ${command}`, error);
15
+ throw error;
16
+ }
17
+ };