@ethima/semantic-release-configuration 4.0.0 → 4.1.0

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/README.md CHANGED
@@ -35,9 +35,12 @@ configuration supporting a range of languages and platforms supported by the
35
35
 
36
36
  ## Usage
37
37
 
38
- - Create the relevant secret token for the platform on which the project
39
- using this configuration is hosted, e.g. `GH_TOKEN`, `GITLAB_TOKEN`. The
40
- supported platforms are [GitHub][semantic-release-github-plugin-auth-url] and
38
+ - Create the [relevant authentication
39
+ token][semantic-release-authentication-url] for the platform on which the
40
+ project using this configuration is hosted. This secret will be used by the
41
+ main `semantic-release` tool for pushing tags as well as the
42
+ platform-specific plugin i.e.
43
+ [GitHub][semantic-release-github-plugin-auth-url] or
41
44
  [GitLab][semantic-release-gitlab-plugin-auth-url].
42
45
 
43
46
  For improved security, _use a unique token for every project this
@@ -65,16 +68,85 @@ for this purpose. This library will search for an `ethima` configuration file
65
68
  as explained in the introduction of its `README`, e.g. a JSON or YAML-formatted
66
69
  `.ethimarc` or `.config/ethimarc` file, JavaScript in a `.ethimarc.js`, etc.
67
70
 
68
- Generic configuration options are:
71
+ The available configuration options are explained in detail in the sections
72
+ describing the functionality they apply to.
69
73
 
70
- - `primary_release_branch` a string indicating the "primary" release branch,
71
- i.e. the branch from which new releases should be created. This may also be
72
- specified as a `PRIMARY_RELEASE_BRANCH` environment variable and will default
73
- to [the `CI_DEFAULT_BRANCH` on GitLab][gitlab-predefined-variables-url] and
74
- to `main` on other platforms.
74
+ ### Branches
75
+
76
+ By default, `semantic-release` accepts [_at most_ 3 "release
77
+ branches"][semantic-release-branches-url]. This configuration provides a
78
+ mechanism to work around this limitation by detecting the type of the active
79
+ branch and only configuring `semantic-release` to act on the primary release
80
+ branch and the active branch, enabling the use of more "release branches". The
81
+ primary release branch is _always_ configured as `semantic-release` requires at
82
+ least one "release branch" to be defined.
83
+
84
+ Additionally, this configuration extends the allowed patterns for "maintenance"
85
+ and "prerelease" branches. Specifically `semantic-release` only supports
86
+ [`N.N.x`, `N.x.x` and `N.x` patterns][semantic-release-branch-patterns-url]
87
+ where `N` is a number. When using this configuration `N`, `N.N`, `N.y`, `N.y.z`
88
+ and `N.N.z` (suffix) patterns are also supported.
89
+
90
+ The configuration distinguishes three types of branches:
91
+
92
+ - The "primary release branch" which is the branch from which the most
93
+ up-to-date release gets cut.
94
+ - "Maintenance branches" which represent a specific subset of releases that can
95
+ be used for maintenance releases after the "primary release branch" has moved
96
+ ahead to a newer version. For instance, a `release-2` branch when the primary
97
+ release branch targets releases for version 3 or up, or a `release-1.2`
98
+ branch for releases within the v1.2.z range after the `release-1` branch has
99
+ started to target v1.3.z.
100
+ - "Prerelease branches" which can be used to "gate" releases, e.g. to
101
+ accumulate a number of changes to release at once instead of releasing on
102
+ every single merge into a "release branch", i.e. the "primary release branch"
103
+ or a "maintenance branch". These branches typically follow the naming
104
+ convention of the other "release branches" but with a different prefix, e.g.
105
+ `next-2` corresponds to prereleases for `release-2`, `next-1.2.z` corresponds
106
+ to releases for `release-1.2.z`, etc. The "prerelease branch" for the
107
+ "primary release branch" is a special case which only consists of the prefix
108
+ used to indicate "prerelease branches", e.g. `next`. The tags associated with
109
+ a "prerelease branch" receive an additional suffix.
110
+
111
+ Note that "breaking" or "feature" "prerelease branches" will accept
112
+ prereleases for the next "breaking" or "feature" version as, according to the
113
+ [semantic versioning
114
+ specification][semantic-versioning-prerelease-precedence-url], these versions
115
+ technically fall within the upper bounded version range represented by the
116
+ "prerelease branch". For instance, a feature commit on the `next-3.1` branch
117
+ will be accepted and results in the publication of `3.2.0-rc.1` from that
118
+ branch. If that same commit would have been made on the `release-3.1` branch
119
+ it would not have been accepted.
120
+
121
+ Various aspects of branch and tag naming can be configured through the
122
+ mechanisms [outlined above](#configuration). The folowing branch-related
123
+ configuration options are available:
124
+
125
+ | Configuration option | Description | Environment Variable |
126
+ | --------------------------- | ----------------------------------------------------------------------------------- | --------------------------- |
127
+ | `branch_prefix_separator` | Specifies the character(s) used to separate the branch prefixes from version ranges | `BRANCH_PREFIX_SEPARATOR` |
128
+ | `maintenance_branch_prefix` | Specifies the prefix used for "maintenance branches" | `MAINTENANCE_BRANCH_PREFIX` |
129
+ | `prerelease_branch_prefix` | Specifies the prefix used for "prerelease branches" | `PRERELEASE_BRANCH_PREFIX` |
130
+ | `prerelease_branch_prefix` | Specifies the suffix used for tags created from "prerelease branches" | `PRERELEASE_TAG_SUFFIX` |
131
+ | `primary_release_branch` | Indicates the name of the "primary release branch" | `PRIMARY_RELEASE_BRANCH` |
132
+
133
+ The default configuration is
134
+
135
+ ```js
136
+ {
137
+ branch_prefix_separator: "-",
138
+ maintenance_branch_prefix: "release"
139
+ prerelease_branch_prefix: "next",
140
+ prerelease_tag_suffix: "rc",
141
+ primary_release_branch: env.CI_DEFAULT_BRANCH || "main",
142
+ }
143
+ ```
75
144
 
76
- Other configuration options are explained in more detail in the sections
77
- describing the functionality they apply to.
145
+ The branch for which a release is intended to be triggered should be provided
146
+ as a `CURRENT_BRANCH` environment variable before instantiating this
147
+ configuration. For common platforms, i.e. GitLab CI and GitHub Actions, this
148
+ value will be automatically derived from known environment variables specific
149
+ to each platform.
78
150
 
79
151
  ### Changelog Maintenance
80
152
 
@@ -228,6 +300,9 @@ release by hand from the tag and changelog that was created by the
228
300
  [juliahub-register-package-url]: https://juliahub.com/ui/Registrator
229
301
  [npm-token-url]: https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website
230
302
  [replace-in-file-url]: https://www.npmjs.com/package/replace-in-file
303
+ [semantic-release-authentication-url]: https://semantic-release.gitbook.io/semantic-release/usage/ci-configuration#authentication
304
+ [semantic-release-branch-patterns-url]: https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#range
305
+ [semantic-release-branches-url]: https://semantic-release.gitbook.io/semantic-release/usage/workflow-configuration#release-branches
231
306
  [semantic-release-changelog-plugin-url]: https://github.com/semantic-release/changelog
232
307
  [semantic-release-commit-analyzer-plugin-url]: https://github.com/semantic-release/commit-analyzer
233
308
  [semantic-release-extends-configuration-url]: https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends
@@ -241,3 +316,4 @@ release by hand from the tag and changelog that was created by the
241
316
  [semantic-release-npm-plugin-url]: https://www.npmjs.com/package/@semantic-release/npm
242
317
  [semantic-release-replace-plugin-url]: https://github.com/google/semantic-release-replace-plugin
243
318
  [semantic-release-url]: https://semantic-release.gitbook.io/
319
+ [semantic-versioning-prerelease-precedence-url]: https://semver.org/#spec-item-9
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@ethima/semantic-release-configuration",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
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": {
7
7
  "type": "git",
8
8
  "url": "git+ssh://git@gitlab.com/ethima/semantic-release-configuration.git"
9
9
  },
10
+ "scripts": {
11
+ "test": "ava"
12
+ },
10
13
  "keywords": [
11
14
  "Semantic",
12
15
  "Release"
@@ -21,9 +24,12 @@
21
24
  "@google/semantic-release-replace-plugin": "1.2.0",
22
25
  "@semantic-release/changelog": "6.0.3",
23
26
  "@semantic-release/git": "10.0.1",
24
- "@semantic-release/github": "8.0.7",
25
- "@semantic-release/gitlab": "12.0.1",
26
- "conventional-changelog-conventionalcommits": "5.0.0",
27
- "cosmiconfig": "8.1.3"
27
+ "@semantic-release/github": "9.0.3",
28
+ "@semantic-release/gitlab": "12.0.3",
29
+ "conventional-changelog-conventionalcommits": "6.1.0",
30
+ "cosmiconfig": "8.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "ava": "5.3.1"
28
34
  }
29
35
  }
@@ -2,8 +2,17 @@ const { cosmiconfigSync } = require("cosmiconfig");
2
2
  const { env } = require("node:process");
3
3
 
4
4
  const CONFIGURATION_DEFAULTS = {
5
+ // The character(s) to use to separate the prefix for maintenance and
6
+ // prerelease branches from the version pattern
7
+ branch_prefix_separator: env.BRANCH_PREFIX_SEPARATOR || "-",
5
8
  changelog_filename: "CHANGELOG.md",
6
9
  files_with_versioned_templates: ["README.md"],
10
+ // The branch prefix for patterned maintenance branches
11
+ maintenance_branch_prefix: env.MAINTENANCE_BRANCH_PREFIX || "release",
12
+ // The branch prefix for patterned prerelease branches
13
+ prerelease_branch_prefix: env.PRERELEASE_BRANCH_PREFIX || "next",
14
+ // The tag suffix to use for tags created from prerelease branches
15
+ prerelease_tag_suffix: env.PRERELEASE_TAG_SUFFIX || "rc",
7
16
  // The `PRIMARY_RELEASE_BRANCH` environment variable is used as a platform
8
17
  // independent mechanism for specifying the primary release branch. On GitLab
9
18
  // this defaults to the "default" branch. Given that the "default" branch is
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const { accessSync } = require("node:fs");
2
2
  const { env } = require("node:process");
3
3
 
4
+ const BranchesConfiguration = require("./branches.js");
4
5
  const CONFIGURATION = require("./configuration.js");
5
6
  const VersionedTemplatesConfiguration = require("./versioned-templates.js");
6
7
 
@@ -9,25 +10,19 @@ const GIT_ASSETS = [
9
10
  ...CONFIGURATION.files_with_versioned_templates,
10
11
  ];
11
12
 
12
- // Used to detect whether configuration for either the
13
- // `semantic-release/github`, `semantic-release/gitlab` or both platform
14
- // release plugins has been provided through the environment
15
- const GITHUB_TOKEN_NAMES = ["GH_TOKEN", "GITHUB_TOKEN"];
16
- const GITLAB_TOKEN_NAMES = ["GL_TOKEN", "GITLAB_TOKEN"];
17
-
18
13
  /*
19
14
  * Determines whether the provided plugin should be added to the semantic
20
15
  * release configuration based on the presence of select environment variables.
21
16
  *
22
- * @param {Array} token_names An array of strings specifying the names of the
23
- * environment variables to detect.
17
+ * @param {string} environment_variable The environment variable to verify the
18
+ * existence of (and equality to `"true"`) to include the specified `plugin`.
24
19
  * @param {string} plugin The name of the NPM package providing the plugin.
25
20
  *
26
- * @return {Array} References the plugin if any of the `token_names` are
27
- * detected and is empty otherwise.
21
+ * @return {Array} References the plugin if the `environment_variable` was set
22
+ * to `"true"` and is empty otherwise.
28
23
  */
29
- function platformSpecificReleasePlugin(token_names, plugin) {
30
- return token_names.some((token_name) => env[token_name]) ? [plugin] : [];
24
+ function platformSpecificReleasePlugin(environment_variable, plugin) {
25
+ return env[environment_variable] === "true" ? [plugin] : [];
31
26
  }
32
27
 
33
28
  // Ensure the NPM plugin gets added to the semantic release pipeline if a
@@ -75,8 +70,14 @@ try {
75
70
  ]);
76
71
  } catch {}
77
72
 
73
+ // Determine the current branch based off well-known environment variables
74
+ // typically available in CI, i.e. Ethima specific configuration, GitLab CI,
75
+ // and GitHub Actions
76
+ const current_branch =
77
+ env.CURRENT_BRANCH ?? env.CI_COMMIT_REF_NAME ?? env.GITHUB_REF_NAME;
78
+
78
79
  const SEMANTIC_RELEASE_CONFIGURATION = {
79
- branches: [CONFIGURATION.primary_release_branch],
80
+ branches: BranchesConfiguration(current_branch, CONFIGURATION),
80
81
  plugins: [
81
82
  ["@semantic-release/commit-analyzer", { preset: "conventionalcommits" }],
82
83
  "@semantic-release/release-notes-generator",
@@ -101,13 +102,10 @@ const SEMANTIC_RELEASE_CONFIGURATION = {
101
102
  },
102
103
  ],
103
104
  ...platformSpecificReleasePlugin(
104
- GITHUB_TOKEN_NAMES,
105
+ "GITHUB_ACTIONS",
105
106
  "@semantic-release/github"
106
107
  ),
107
- ...platformSpecificReleasePlugin(
108
- GITLAB_TOKEN_NAMES,
109
- "@semantic-release/gitlab"
110
- ),
108
+ ...platformSpecificReleasePlugin("GITLAB_CI", "@semantic-release/gitlab"),
111
109
  ],
112
110
  };
113
111