@ethima/semantic-release-configuration 3.0.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
@@ -7,7 +7,10 @@ configuration supporting a range of languages and platforms supported by the
7
7
  ## Features
8
8
 
9
9
  - Analyzes commits using
10
- [`@semantic-release/commit-analyzer`][semantic-release-commit-analyzer-plugin-url].
10
+ [`@semantic-release/commit-analyzer`][semantic-release-commit-analyzer-plugin-url]
11
+ and the [`conventional-changelog-conventionalcommits`
12
+ preset][conventionalcommits-preset-url] implementing the [Conventional
13
+ Commits specification][conventionalcommits-url].
11
14
  - Generates release notes using
12
15
  [`@semantic-release/release-notes-generator`][semantic-release-notes-generator-plugin-url].
13
16
  - Updates templated content in a project's root-level `README.md` file
@@ -20,14 +23,18 @@ configuration supporting a range of languages and platforms supported by the
20
23
  - (Conditionally) maintains NPM package files, i.e. `package.json` and
21
24
  publishes using [`@semantic-release/npm`][semantic-release-npm-plugin-url]
22
25
  and [`@semantic-release/git`][semantic-release-git-plugin-url].
23
- - Publishes releases to GitLab using
24
- [`@semantic-release/gitlab`][semantic-release-gitlab-plugin-url].
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.
25
31
 
26
32
  ## Usage
27
33
 
28
- - Create a [personal access token][gitlab-pat-url], with `api` and
29
- `write_repository` scopes. Make the token available as a `GITLAB_TOKEN` or
30
- `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].
31
38
 
32
39
  For improved security, _use a unique token for every project this
33
40
  configuration is used in_!
@@ -36,11 +43,16 @@ configuration supporting a range of languages and platforms supported by the
36
43
  [`extends`][semantic-release-extends-configuration-url] configuration for the
37
44
  project to be semantically released.
38
45
 
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
+
39
50
  ### Configuration
40
51
 
41
52
  The semantic release configuration has several configuration options itself.
42
- Some of this configuration, like sensitive tokens such as `GITLAB_TOKEN` and
43
- `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.
44
56
 
45
57
  Other configuration options have more complex values and are not suitable for
46
58
  configuration through environment variables. These configuration options can be
@@ -49,7 +61,15 @@ for this purpose. This library will search for an `ethima` configuration file
49
61
  as explained in the introduction of its `README`, e.g. a JSON or YAML-formatted
50
62
  `.ethimarc` or `.config/ethimarc` file, JavaScript in a `.ethimarc.js`, etc.
51
63
 
52
- 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
53
73
  describing the functionality they apply to.
54
74
 
55
75
  ### Changelog Maintenance
@@ -177,15 +197,20 @@ When this happens, it is typically also necessary to create the initial GitHub
177
197
  release by hand from the tag and changelog that was created by the
178
198
  [`semantic-release`][semantic-release-url] tooling.
179
199
 
200
+ [conventionalcommits-url]: https://www.conventionalcommits.org
201
+ [conventionalcommits-preset-url]: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-conventionalcommits
180
202
  [cosmiconfig-url]: https://www.npmjs.com/package/cosmiconfig
181
- [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
182
204
  [npm-token-url]: https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website
183
205
  [replace-in-file-url]: https://www.npmjs.com/package/replace-in-file
184
206
  [semantic-release-changelog-plugin-url]: https://github.com/semantic-release/changelog
185
207
  [semantic-release-commit-analyzer-plugin-url]: https://github.com/semantic-release/commit-analyzer
186
208
  [semantic-release-extends-configuration-url]: https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends
187
209
  [semantic-release-git-plugin-url]: https://github.com/semantic-release/git
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
188
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
189
214
  [semantic-release-notes-generator-plugin-url]: https://github.com/semantic-release/release-notes-generator
190
215
  [semantic-release-npm-plugin-configuration-url]: https://github.com/semantic-release/npm#npm-registry-authentication
191
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.0.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": {
@@ -21,6 +21,7 @@
21
21
  "@google/semantic-release-replace-plugin": "1.2.0",
22
22
  "@semantic-release/changelog": "6.0.2",
23
23
  "@semantic-release/git": "10.0.1",
24
+ "@semantic-release/github": "8.0.7",
24
25
  "@semantic-release/gitlab": "9.5.1",
25
26
  "conventional-changelog-conventionalcommits": "5.0.0",
26
27
  "cosmiconfig": "8.0.0"
@@ -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,6 +9,27 @@ const GIT_ASSETS = [
9
9
  ...CONFIGURATION.files_with_versioned_templates,
10
10
  ];
11
11
 
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
+ }
32
+
12
33
  // Ensure the NPM plugin gets added to the semantic release pipeline if a
13
34
  // `package.json` file is detected
14
35
  const NPM_PLUGIN = [];
@@ -19,7 +40,7 @@ try {
19
40
  } catch {}
20
41
 
21
42
  const SEMANTIC_RELEASE_CONFIGURATION = {
22
- branches: [env.CI_DEFAULT_BRANCH],
43
+ branches: [CONFIGURATION.primary_release_branch],
23
44
  plugins: [
24
45
  ["@semantic-release/commit-analyzer", { preset: "conventionalcommits" }],
25
46
  "@semantic-release/release-notes-generator",
@@ -42,7 +63,14 @@ const SEMANTIC_RELEASE_CONFIGURATION = {
42
63
  "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}",
43
64
  },
44
65
  ],
45
- "@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
+ ),
46
74
  ],
47
75
  };
48
76