@docupace/pipeline 1.0.66 → 1.0.68

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.
@@ -7,6 +7,8 @@ import { appInfo, environmentConfig, getRepUrl } from './config.js';
7
7
  import { copy2 } from './copy.js';
8
8
  import axios from 'axios';
9
9
  import { deployConnect, deployCore } from './jenkins.js';
10
+ import { gitDescribeToSemver } from './git-to-semver.js';
11
+ import semver from 'semver';
10
12
 
11
13
  /**
12
14
  * Clone the repository, read the YAML file, and return the parsed data and file paths.
@@ -377,24 +379,27 @@ async function getAppInfo(coreUrl) {
377
379
  return await axios.get(url);
378
380
  }
379
381
 
380
- function getBranchNameFromVersion(version) {
381
- const match = version.match(/(\d+\.\d+\.[^\-]+)(?:-(\d+)-g([a-f0-9]+))?/);
382
-
383
- if (!match) {
384
- throw new Error(`Invalid version format: ${version}`);
385
- }
386
-
387
- const fullVersion = match[1]; // e.g., 24.19.19, 24.20.alpha3, etc.
388
- const customBranch = match[2]; // e.g., 4, 58, or 0
389
- const commitHash = match[3]; // e.g., 668edef58e, 634cf6c904, etc.
390
-
391
- // If "alpha" is in the version or customBranch is non-zero, use the commit hash
392
- if (fullVersion.includes('alpha') || (customBranch && customBranch !== '0')) {
393
- return commitHash;
382
+ export function getBranchNameFromVersion(version) {
383
+ let parsed;
384
+ try {
385
+ const semverVersion = gitDescribeToSemver(version);
386
+ parsed = semver.parse(semverVersion);
387
+ let newVersion;
388
+ if (parsed.prerelease.length > 0) {
389
+ newVersion = parsed.build[1].slice(1);
390
+ } else if (parsed.build[0] != '0') {
391
+ console.error(`❌ This version is a custom branch. Deployment canceled.`);
392
+ process.exit(1);
393
+ } else {
394
+ newVersion = 'v' + parsed.version;
395
+ }
396
+ console.log(`Extracted version ${newVersion} from ${version}`);
397
+ return newVersion;
398
+ } catch {
399
+ console.log(`Error parsing version : ${version}`);
400
+ console.log('Parsed Object:');
401
+ console.log(parsed);
394
402
  }
395
-
396
- // Otherwise, use the full version
397
- return 'v' + fullVersion;
398
403
  }
399
404
 
400
405
  async function getCoreBranchName(fromEnv, fromSite) {
@@ -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
+ }
@@ -1,7 +1,7 @@
1
1
  import axios from 'axios';
2
2
 
3
- const CORE_JENKINS_URL = 'http://devops.corp.docupace.com';
4
- const CORE_JOB_NAME = 'auto-deploy-site';
3
+ const CORE_JENKINS_URL = process.env.CORE_JENKINS_URL;
4
+ const CORE_JOB_NAME = process.env.CORE_JENKINS_JOB_NAME;
5
5
  const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
6
6
  const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
7
7
 
@@ -0,0 +1,5 @@
1
+ import { getBranchNameFromVersion } from './deploy.js';
2
+
3
+ getBranchNameFromVersion('25.2.0-alpha.18-3-g4e0e088aa0');
4
+ getBranchNameFromVersion('25.1.13-0-g7798cf7138');
5
+ getBranchNameFromVersion('25.1.13-3-g7798cf7138');