@ethima/semantic-release-configuration 3.1.0 → 3.2.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
@@ -23,16 +23,18 @@ configuration supporting a range of languages and platforms supported by the
23
23
  - (Conditionally) maintains NPM package files, i.e. `package.json` and
24
24
  publishes using [`@semantic-release/npm`][semantic-release-npm-plugin-url]
25
25
  and [`@semantic-release/git`][semantic-release-git-plugin-url].
26
- - Publishes releases to GitHub using
27
- [`@semantic-release/github`][semantic-release-github-plugin-url] when
28
- running from GitHub Actions and to GitLab using
29
- [`@semantic-release/gitlab`][semantic-release-gitlab-plugin-url] otherwise.
26
+ - Publishes releases to the relevant hosting platform, i.e. GitHub or GitLab,
27
+ using the platform-specific release plugins
28
+ [`@semantic-release/github`][semantic-release-github-plugin-url] or
29
+ [`@semantic-release/gitlab`][semantic-release-gitlab-plugin-url]
30
+ respectively.
30
31
 
31
32
  ## Usage
32
33
 
33
- - Create a [personal access token][gitlab-pat-url], with `api` and
34
- `write_repository` scopes. Make the token available as a `GITLAB_TOKEN` or
35
- `GL_TOKEN` CI/CD variable of the project using the configuration.
34
+ - Create the relevant secret token for the platform on which the project
35
+ using this configuration is hosted, e.g. `GH_TOKEN`, `GITLAB_TOKEN`. The
36
+ supported platforms are [GitHub][semantic-release-github-plugin-auth-url] and
37
+ [GitLab][semantic-release-gitlab-plugin-auth-url].
36
38
 
37
39
  For improved security, _use a unique token for every project this
38
40
  configuration is used in_!
@@ -41,17 +43,16 @@ configuration supporting a range of languages and platforms supported by the
41
43
  [`extends`][semantic-release-extends-configuration-url] configuration for the
42
44
  project to be semantically released.
43
45
 
44
- - When using this shareable semantic release configuration from GitHub Actions,
45
- ensure a `CI_DEFAULT_BRANCH` environment variable is set to the name of the
46
- branch from which releases should be created. Unfortunately, GitHub does not
47
- make this information readily available through, for instance, a similarly
48
- named environment variable.
46
+ - When using this shareable semantic release configuration on GitHub, be sure
47
+ to read the instructions below on the `primary_release_branch` configuration
48
+ and provide an appropriate value if necessary.
49
49
 
50
50
  ### Configuration
51
51
 
52
52
  The semantic release configuration has several configuration options itself.
53
- Some of this configuration, like sensitive tokens such as `GITLAB_TOKEN` and
54
- `NPM_TOKEN`, should be configured through environment variables.
53
+ Some of this configuration, like sensitive tokens such as `GH_TOKEN`,
54
+ `GITLAB_TOKEN` and `NPM_TOKEN`, should be configured through environment
55
+ variables.
55
56
 
56
57
  Other configuration options have more complex values and are not suitable for
57
58
  configuration through environment variables. These configuration options can be
@@ -60,7 +61,15 @@ for this purpose. This library will search for an `ethima` configuration file
60
61
  as explained in the introduction of its `README`, e.g. a JSON or YAML-formatted
61
62
  `.ethimarc` or `.config/ethimarc` file, JavaScript in a `.ethimarc.js`, etc.
62
63
 
63
- All configuration options are explained in more detail in the sections
64
+ Generic configuration options are:
65
+
66
+ - `primary_release_branch` a string indicating the "primary" release branch,
67
+ i.e. the branch from which new releases should be created. This may also be
68
+ specified as a `PRIMARY_RELEASE_BRANCH` environment variable and will default
69
+ to [the `CI_DEFAULT_BRANCH` on GitLab][gitlab-predefined-variables-url] and
70
+ to `main` on other platforms.
71
+
72
+ Other configuration options are explained in more detail in the sections
64
73
  describing the functionality they apply to.
65
74
 
66
75
  ### Changelog Maintenance
@@ -191,7 +200,7 @@ release by hand from the tag and changelog that was created by the
191
200
  [conventionalcommits-url]: https://www.conventionalcommits.org
192
201
  [conventionalcommits-preset-url]: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits
193
202
  [cosmiconfig-url]: https://www.npmjs.com/package/cosmiconfig
194
- [gitlab-pat-url]: https://gitlab.com/-/profile/personal_access_tokens
203
+ [gitlab-predefined-variables-url]: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
195
204
  [npm-token-url]: https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website
196
205
  [replace-in-file-url]: https://www.npmjs.com/package/replace-in-file
197
206
  [semantic-release-changelog-plugin-url]: https://github.com/semantic-release/changelog
@@ -199,7 +208,9 @@ release by hand from the tag and changelog that was created by the
199
208
  [semantic-release-extends-configuration-url]: https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends
200
209
  [semantic-release-git-plugin-url]: https://github.com/semantic-release/git
201
210
  [semantic-release-github-plugin-url]: https://github.com/semantic-release/github
211
+ [semantic-release-github-plugin-auth-url]: https://github.com/semantic-release/github#github-authentication
202
212
  [semantic-release-gitlab-plugin-url]: https://github.com/semantic-release/gitlab
213
+ [semantic-release-gitlab-plugin-auth-url]: https://github.com/semantic-release/gitlab#gitlab-authentication
203
214
  [semantic-release-notes-generator-plugin-url]: https://github.com/semantic-release/release-notes-generator
204
215
  [semantic-release-npm-plugin-configuration-url]: https://github.com/semantic-release/npm#npm-registry-authentication
205
216
  [semantic-release-npm-plugin-url]: https://www.npmjs.com/package/@semantic-release/npm
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethima/semantic-release-configuration",
3
- "version": "3.1.0",
3
+ "version": "3.2.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": {
@@ -1,8 +1,15 @@
1
1
  const { cosmiconfigSync } = require("cosmiconfig");
2
+ const { env } = require("node:process");
2
3
 
3
4
  const CONFIGURATION_DEFAULTS = {
4
5
  changelog_filename: "CHANGELOG.md",
5
6
  files_with_versioned_templates: ["README.md"],
7
+ // The `PRIMARY_RELEASE_BRANCH` environment variable is used as a platform
8
+ // independent mechanism for specifying the primary release branch. On GitLab
9
+ // this defaults to the "default" branch. Given that the "default" branch is
10
+ // not readily available on GitHub `main` is used as a fallback
11
+ primary_release_branch:
12
+ env.PRIMARY_RELEASE_BRANCH || env.CI_DEFAULT_BRANCH || "main",
6
13
  };
7
14
 
8
15
  const ethimaConfig = cosmiconfigSync("ethima").search();
package/src/index.js CHANGED
@@ -9,7 +9,26 @@ const GIT_ASSETS = [
9
9
  ...CONFIGURATION.files_with_versioned_templates,
10
10
  ];
11
11
 
12
- const IS_GITHUB = env.GITHUB_ACTIONS === "true";
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
+ /*
19
+ * Determines whether the provided plugin should be added to the semantic
20
+ * release configuration based on the presence of select environment variables.
21
+ *
22
+ * @param {Array} token_names An array of strings specifying the names of the
23
+ * environment variables to detect.
24
+ * @param {string} plugin The name of the NPM package providing the plugin.
25
+ *
26
+ * @return {Array} References the plugin if any of the `token_names` are
27
+ * detected and is empty otherwise.
28
+ */
29
+ function platformSpecificReleasePlugin(token_names, plugin) {
30
+ return token_names.some((token_name) => env[token_name]) ? [plugin] : [];
31
+ }
13
32
 
14
33
  // Ensure the NPM plugin gets added to the semantic release pipeline if a
15
34
  // `package.json` file is detected
@@ -21,7 +40,7 @@ try {
21
40
  } catch {}
22
41
 
23
42
  const SEMANTIC_RELEASE_CONFIGURATION = {
24
- branches: [env.CI_DEFAULT_BRANCH],
43
+ branches: [CONFIGURATION.primary_release_branch],
25
44
  plugins: [
26
45
  ["@semantic-release/commit-analyzer", { preset: "conventionalcommits" }],
27
46
  "@semantic-release/release-notes-generator",
@@ -44,7 +63,14 @@ const SEMANTIC_RELEASE_CONFIGURATION = {
44
63
  "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}",
45
64
  },
46
65
  ],
47
- IS_GITHUB ? "@semantic-release/github" : "@semantic-release/gitlab",
66
+ ...platformSpecificReleasePlugin(
67
+ GITHUB_TOKEN_NAMES,
68
+ "semantic-release/github"
69
+ ),
70
+ ...platformSpecificReleasePlugin(
71
+ GITLAB_TOKEN_NAMES,
72
+ "semantic-release/gitlab"
73
+ ),
48
74
  ],
49
75
  };
50
76