@ethima/semantic-release-configuration 4.1.0 → 4.1.1

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/branches.js +82 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethima/semantic-release-configuration",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "A shareable semantic release configuration supporting a range of languages and platforms supported by the Ethima organization.",
5
5
  "main": "./src/index.js",
6
6
  "repository": {
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "homepage": "https://gitlab.com/ethima/semantic-release-configuration#readme",
23
23
  "dependencies": {
24
- "@google/semantic-release-replace-plugin": "1.2.0",
24
+ "@google/semantic-release-replace-plugin": "1.2.5",
25
25
  "@semantic-release/changelog": "6.0.3",
26
26
  "@semantic-release/git": "10.0.1",
27
27
  "@semantic-release/github": "9.0.3",
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Determines the type of branch for the provided `branch`, i.e. whether it
3
+ * represents a "maintenance" or a "prerelease" branch.
4
+ *
5
+ * @return object The `branch_prefix` and whether it `is_prerelease`.
6
+ */
7
+ function determinePrefixedBranchType(
8
+ branch,
9
+ { maintenance_branch_prefix, prerelease_branch_prefix }
10
+ ) {
11
+ if (branch.startsWith(maintenance_branch_prefix)) {
12
+ return { branch_prefix: maintenance_branch_prefix, is_prerelease: false };
13
+ } else {
14
+ return { branch_prefix: prerelease_branch_prefix, is_prerelease: true };
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Determines the "branches" for a semantic-release configuration given the
20
+ * provided `configuration` for the shareable configuration. This ensures more
21
+ * (patterned) release branches can be supported than would typically be the
22
+ * case.
23
+ *
24
+ * The function is capable of dealing with "primary release branches", the
25
+ * corresponding "prerelease branch", and patterned "maintenance" and
26
+ * "prerelease" branches.
27
+ *
28
+ * @return array An array containing the determined branch configuration as the
29
+ * sole entry.
30
+ */
31
+ function BranchesConfiguration(branch, configuration) {
32
+ if (configuration.primary_release_branch === branch) {
33
+ return [branch];
34
+ }
35
+
36
+ if (configuration.prerelease_branch_prefix === branch) {
37
+ return [
38
+ configuration.primary_release_branch,
39
+ { name: branch, prerelease: configuration.prerelease_tag_suffix },
40
+ ];
41
+ }
42
+
43
+ const { branch_prefix, is_prerelease } = determinePrefixedBranchType(
44
+ branch,
45
+ configuration
46
+ );
47
+
48
+ // The matching pattern is configured to match all allowed permutations of
49
+ // version specifications as closely as possible to ensure other permutations
50
+ // that look valid, e.g. `N.z.q`, do not also accidentally match
51
+ const branch_prefix_separator = configuration.branch_prefix_separator ?? "-";
52
+ const version_branch_matcher = new RegExp(
53
+ `^${branch_prefix}${branch_prefix_separator}(?<major>\\d+)(?<minor>\\.(\\d+|x|y))?(\\.(x|z))?$`
54
+ );
55
+ if (version_branch_matcher.test(branch)) {
56
+ let {
57
+ groups: { major, minor },
58
+ } = branch.match(version_branch_matcher);
59
+
60
+ // Remove minor parts not representing digits, so they are not included in
61
+ // the returned `range`
62
+ const version_part_matcher = new RegExp("\\.\\d+");
63
+ if (!version_part_matcher.test(minor)) {
64
+ minor = "";
65
+ }
66
+
67
+ return [
68
+ configuration.primary_release_branch,
69
+ {
70
+ name: branch,
71
+ ...(is_prerelease
72
+ ? { prerelease: configuration.prerelease_tag_suffix }
73
+ : {}),
74
+ range: `${major}${minor}.x`,
75
+ },
76
+ ];
77
+ }
78
+
79
+ return [];
80
+ }
81
+
82
+ module.exports = BranchesConfiguration;