@ethima/semantic-release-configuration 2.0.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/LICENSE +19 -0
- package/README.md +137 -0
- package/package.json +26 -0
- package/src/index.js +43 -0
- package/src/versioned-templates.js +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2022 Joris Kraak <me@joriskraak.nl>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Semantic Release Configuration
|
|
2
|
+
|
|
3
|
+
A shareable [semantic release](https://semantic-release.gitbook.io)
|
|
4
|
+
configuration supporting a range of languages and platforms supported by the
|
|
5
|
+
@ethima organization.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Analyzes commits using
|
|
10
|
+
[`@semantic-release/commit-analyzer`][semantic-release-commit-analyzer-plugin-url].
|
|
11
|
+
- Generates release notes using
|
|
12
|
+
[`@semantic-release/release-notes-generator`][semantic-release-notes-generator-plugin-url].
|
|
13
|
+
- Updates templated content in a project's root-level `README.md` file
|
|
14
|
+
with updated version information using
|
|
15
|
+
[`@google/semantic-release-replace-plugin`][semantic-release-replace-plugin-url]
|
|
16
|
+
and [`@semantic-release/git`][semantic-release-git-plugin-url].
|
|
17
|
+
- Maintains a `CHANGELOG.md` from the generated release notes using
|
|
18
|
+
[`@semantic-release/changelog`][semantic-release-changelog-plugin-url] and
|
|
19
|
+
[`@semantic-release/git`][semantic-release-git-plugin-url].
|
|
20
|
+
- (Conditionally) maintains NPM package files, i.e. `package.json` and
|
|
21
|
+
publishes using [`@semantic-release/npm`][semantic-release-npm-plugin-url]
|
|
22
|
+
and [`@semantic-release/git`][semantic-release-git-plugin-url].
|
|
23
|
+
- Publishes releases to GitLab using
|
|
24
|
+
[`@semantic-release/gitlab`][semantic-release-gitlab-plugin-url].
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
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.
|
|
31
|
+
|
|
32
|
+
For improved security, _use a unique token for every project this
|
|
33
|
+
configuration is used in_!
|
|
34
|
+
|
|
35
|
+
- Use this shareable semantic release configuration by including it in the
|
|
36
|
+
[`extends`][semantic-release-extends-configuration-url] configuration for the
|
|
37
|
+
project to be semantically released.
|
|
38
|
+
|
|
39
|
+
### JavaScript Packages
|
|
40
|
+
|
|
41
|
+
JavaScript packages are detected based on the presence of a `package.json` file
|
|
42
|
+
in the root of the project.
|
|
43
|
+
|
|
44
|
+
- Create an [NPM token][npm-token-url] to be able to publish to an NPM
|
|
45
|
+
registry. Make the token available as an `NPM_TOKEN` CI/CD variable of the
|
|
46
|
+
project using the configuration.
|
|
47
|
+
|
|
48
|
+
See [the plugin's configuration
|
|
49
|
+
instructions][semantic-release-npm-plugin-configuration-url] for details and
|
|
50
|
+
alternatives.
|
|
51
|
+
|
|
52
|
+
### Templated Content in `README.md` Files
|
|
53
|
+
|
|
54
|
+
The configuration will look for `__NEXT_SEMANTIC_RELEASE_VERSION__` tokens in
|
|
55
|
+
templates in a project's root-level `README.md` and replace them with the
|
|
56
|
+
version that is being released. This is, for instance, useful for automatically
|
|
57
|
+
keeping installation instructions up-to-date.
|
|
58
|
+
|
|
59
|
+
Templated content is created using HTML comments and has the following
|
|
60
|
+
structure:
|
|
61
|
+
|
|
62
|
+
- A `<!-- START_VERSIONED_TEMPLATE` token,
|
|
63
|
+
- the template itself with one or more
|
|
64
|
+
`__NEXT_SEMANTIC_RELEASE_VERSION__` tokens,
|
|
65
|
+
- a comment closing tag `-->
|
|
66
|
+
|
|
67
|
+
` token,
|
|
68
|
+
- the template itself with one or more
|
|
69
|
+
`2.0.0` tokens,
|
|
70
|
+
- a comment closing tag `
|
|
71
|
+
|
|
72
|
+
<!-- END_VERSIONED_TEMPLATE -->`.
|
|
73
|
+
|
|
74
|
+
More concretely a section in a `README` that looks like
|
|
75
|
+
|
|
76
|
+
```markdown
|
|
77
|
+
<!-- START_VERSIONED_TEMPLATE
|
|
78
|
+
|
|
79
|
+
The next semantically released version will be v__NEXT_SEMANTIC_RELEASE_VERSION__!
|
|
80
|
+
|
|
81
|
+
-->
|
|
82
|
+
|
|
83
|
+
The next semantically released version will be v2.0.0!
|
|
84
|
+
|
|
85
|
+
<!-- END_VERSIONED_TEMPLATE -->
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
would, after a v1.2.3 release using the configuration has been triggered,
|
|
89
|
+
become
|
|
90
|
+
|
|
91
|
+
```markdown
|
|
92
|
+
<!-- START_VERSIONED_TEMPLATE
|
|
93
|
+
|
|
94
|
+
The next semantically released version will be v__NEXT_SEMANTIC_RELEASE_VERSION__!
|
|
95
|
+
|
|
96
|
+
-->
|
|
97
|
+
|
|
98
|
+
The next semantically released version will be v2.0.0!
|
|
99
|
+
|
|
100
|
+
<!-- END_VERSIONED_TEMPLATE -->
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Note that the `v` is in the template! The version as derived by the semantic
|
|
104
|
+
release tooling does not contain that prefix.
|
|
105
|
+
|
|
106
|
+
## Troubleshooting
|
|
107
|
+
|
|
108
|
+
### Publishing the initial release of a scoped JavaScript package
|
|
109
|
+
|
|
110
|
+
Creating the initial release of a scoped JavaScript may fail if the package is
|
|
111
|
+
intended to be public and the person creating the release not having paid for
|
|
112
|
+
private packages. This results in an error similar to
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
npm ERR! 402 Payment Required - PUT https://registry.npmjs.org/@<scope>%2f<package-name> -
|
|
116
|
+
You must sign up for private packages
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
When this happens, publish the initial release manually using `npm publish --access=public`
|
|
120
|
+
after making sure the local copy of the project to be released is up-to-date.
|
|
121
|
+
|
|
122
|
+
When this happens, it is typically also necessary to create the initial GitHub
|
|
123
|
+
release by hand from the tag and changelog that was created by the
|
|
124
|
+
[`semantic-release`][semantic-release-url] tooling.
|
|
125
|
+
|
|
126
|
+
[gitlab-pat-url]: https://gitlab.com/-/profile/personal_access_tokens
|
|
127
|
+
[npm-token-url]: https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website
|
|
128
|
+
[semantic-release-changelog-plugin-url]: https://github.com/semantic-release/changelog
|
|
129
|
+
[semantic-release-commit-analyzer-plugin-url]: https://github.com/semantic-release/commit-analyzer
|
|
130
|
+
[semantic-release-extends-configuration-url]: https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends
|
|
131
|
+
[semantic-release-git-plugin-url]: https://github.com/semantic-release/git
|
|
132
|
+
[semantic-release-gitlab-plugin-url]: https://github.com/semantic-release/gitlab
|
|
133
|
+
[semantic-release-notes-generator-plugin-url]: https://github.com/semantic-release/release-notes-generator
|
|
134
|
+
[semantic-release-npm-plugin-configuration-url]: https://github.com/semantic-release/npm#npm-registry-authentication
|
|
135
|
+
[semantic-release-npm-plugin-url]: https://www.npmjs.com/package/@semantic-release/npm
|
|
136
|
+
[semantic-release-replace-plugin-url]: https://github.com/google/semantic-release-replace-plugin
|
|
137
|
+
[semantic-release-url]: https://semantic-release.gitbook.io/
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ethima/semantic-release-configuration",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "A shareable semantic release configuration supporting a range of languages and platforms supported by the Ethima organization.",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+ssh://git@gitlab.com/ethima/semantic-release-configuration.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"Semantic",
|
|
12
|
+
"Release"
|
|
13
|
+
],
|
|
14
|
+
"author": "Joris Kraak <me@joriskraak.nl>",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://gitlab.com/ethima/semantic-release-configuration/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://gitlab.com/ethima/semantic-release-configuration#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@google/semantic-release-replace-plugin": "1.2.0",
|
|
22
|
+
"@semantic-release/changelog": "6.0.2",
|
|
23
|
+
"@semantic-release/git": "10.0.1",
|
|
24
|
+
"@semantic-release/gitlab": "9.5.1"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { accessSync } = require("node:fs");
|
|
2
|
+
const { env } = require("node:process");
|
|
3
|
+
|
|
4
|
+
const VersionedTemplatesConfiguration = require("./versioned-templates.js");
|
|
5
|
+
|
|
6
|
+
const CHANGELOG_FILENAME = "CHANGELOG.md";
|
|
7
|
+
const README_FILENAME = "README.md";
|
|
8
|
+
|
|
9
|
+
const GIT_ASSETS = [CHANGELOG_FILENAME, README_FILENAME];
|
|
10
|
+
|
|
11
|
+
// Ensure the NPM plugin gets added to the semantic release pipeline if a
|
|
12
|
+
// `package.json` file is detected
|
|
13
|
+
const NPM_PLUGIN = [];
|
|
14
|
+
try {
|
|
15
|
+
accessSync("package.json");
|
|
16
|
+
GIT_ASSETS.push("package.json");
|
|
17
|
+
NPM_PLUGIN.push("@semantic-release/npm");
|
|
18
|
+
} catch {}
|
|
19
|
+
|
|
20
|
+
const SEMANTIC_RELEASE_CONFIGURATION = {
|
|
21
|
+
branches: [env.CI_DEFAULT_BRANCH],
|
|
22
|
+
plugins: [
|
|
23
|
+
"@semantic-release/commit-analyzer",
|
|
24
|
+
"@semantic-release/release-notes-generator",
|
|
25
|
+
[
|
|
26
|
+
"@semantic-release/changelog",
|
|
27
|
+
{ changelogFile: CHANGELOG_FILENAME, changelogTitle: "# Changelog" },
|
|
28
|
+
],
|
|
29
|
+
VersionedTemplatesConfiguration(README_FILENAME),
|
|
30
|
+
...NPM_PLUGIN,
|
|
31
|
+
[
|
|
32
|
+
"@semantic-release/git",
|
|
33
|
+
{
|
|
34
|
+
assets: GIT_ASSETS,
|
|
35
|
+
message:
|
|
36
|
+
"chore(release): ${nextRelease.version}\n\n${nextRelease.notes}",
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
"@semantic-release/gitlab",
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = SEMANTIC_RELEASE_CONFIGURATION;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const BLOCK_COMMENT_END_PATTERN = "-->";
|
|
2
|
+
const BLOCK_COMMENT_START_PATTERN = "<!--";
|
|
3
|
+
const TEMPLATE_VERSION_PLACEHOLDER = "__NEXT_SEMANTIC_RELEASE_VERSION__";
|
|
4
|
+
|
|
5
|
+
const templateMatcher = new RegExp(
|
|
6
|
+
[
|
|
7
|
+
`(${BLOCK_COMMENT_START_PATTERN}\\s*START_VERSIONED_TEMPLATE\\s*)`,
|
|
8
|
+
"(.*?)", // The template to insert the version into
|
|
9
|
+
`(\\s*${BLOCK_COMMENT_END_PATTERN})`,
|
|
10
|
+
".*?", // The templated content, will be discarded
|
|
11
|
+
`(${BLOCK_COMMENT_START_PATTERN}\\s*END_VERSIONED_TEMPLATE\\s*${BLOCK_COMMENT_END_PATTERN})`,
|
|
12
|
+
].join(""),
|
|
13
|
+
"gms"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
function templateReplacer(
|
|
17
|
+
_,
|
|
18
|
+
templateStartMarker,
|
|
19
|
+
template,
|
|
20
|
+
templateEndMarker,
|
|
21
|
+
templateCloseMarker,
|
|
22
|
+
...args
|
|
23
|
+
) {
|
|
24
|
+
const context = args.pop();
|
|
25
|
+
|
|
26
|
+
return [
|
|
27
|
+
templateStartMarker,
|
|
28
|
+
template,
|
|
29
|
+
templateEndMarker,
|
|
30
|
+
`\n\n`,
|
|
31
|
+
template.replaceAll(
|
|
32
|
+
TEMPLATE_VERSION_PLACEHOLDER,
|
|
33
|
+
context.nextRelease.version
|
|
34
|
+
),
|
|
35
|
+
`\n\n`,
|
|
36
|
+
templateCloseMarker,
|
|
37
|
+
].join("");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function VersionedTemplatesConfiguration(files) {
|
|
41
|
+
return [
|
|
42
|
+
"@google/semantic-release-replace-plugin",
|
|
43
|
+
{
|
|
44
|
+
replacements: [
|
|
45
|
+
{
|
|
46
|
+
countMatches: true,
|
|
47
|
+
files,
|
|
48
|
+
from: templateMatcher,
|
|
49
|
+
to: templateReplacer,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = VersionedTemplatesConfiguration;
|