Skip to content

Commit ee2cda1

Browse files
committedJun 23, 2023
feat: removed commitlint from semantic-releases
BREAKING CHANGE: removed commitlint from semantic-releases and added all rules to the new commitlint-config package Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent 5af5299 commit ee2cda1

File tree

4 files changed

+48
-76
lines changed

4 files changed

+48
-76
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { Linter } from "eslint";
2+
3+
import { createConfig } from "../../utils/create-config";
4+
5+
const config: Linter.Config = createConfig("all", {
6+
plugins: ["regexp"],
7+
extends: ["plugin:regexp/recommended"],
8+
});
9+
10+
export default config;

‎packages/semantic-release-preset/README.md

+36-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# Semantic-release shareable configuration
2-
3-
Semantic-release shareable configuration to publish GitHub projects.
4-
51
<div align="center">
2+
<h1>Shareable semantic-release configuration</h1>
3+
4+
A shareable [semantic-release](https://github.com/semantic-release/semantic-release) configuration, for enforcing consistent GitHub/NPM releases in your projects.
65

76
[![npm-image]][npm-url] [![license-image]][license-url]
87

@@ -20,15 +19,27 @@ Semantic-release shareable configuration to publish GitHub projects.
2019

2120
---
2221

22+
## Purpose
23+
24+
- This configuration also includes a semantic-release configuration, which enables automated GitHub/NPM releases based on your commit messages.
25+
2326
## Install
2427

2528
```bash
26-
npm install --dev-save @anolilab/semantic-release-preset
29+
npm install --dev-save semantic-release @anolilab/semantic-release-preset
30+
```
31+
32+
```sh
33+
yarn add -D semantic-release @anolilab/semantic-release-preset
34+
```
35+
36+
```sh
37+
pnpm add -D semantic-release @anolilab/semantic-release-preset
2738
```
2839

2940
## Plugins
3041

31-
This shareable configuration uses the following plugins:
42+
We use the following plugins within the Semantic Release ecosystem:
3243

3344
- [@semantic-release/changelog][3]
3445
- [@semantic-release/commit-analyzer][1]
@@ -52,7 +63,11 @@ This shareable configuration performs the following actions:
5263

5364
## Usage
5465

55-
When installing this package for the first time, the following shareable configuration (.releaserc.json) is automatically added to your project root folder:
66+
When installing this package for the first time, the following shareable configuration `.releaserc.json` is automatically added to your project folder:
67+
68+
> Note: If the script detects an existing `.releaserc.json` file, it will not overwrite it.
69+
70+
> Note: It can happen that the postinstall script dont run, then you have to add the `.releaserc.json` manually.
5671
5772
With npm:
5873

@@ -69,10 +84,10 @@ Without npm:
6984
"extends": "@anolilab/semantic-release-preset"
7085
}
7186
```
87+
<details>
88+
<summary>File content of the extended preset</summary>
7289

73-
File content:
74-
75-
```json
90+
```json5
7691
{
7792
"branches": [
7893
"+([0-9])?(.{+([0-9]),x}).x",
@@ -102,7 +117,7 @@ File content:
102117
}
103118
],
104119
"@semantic-release/changelog",
105-
"@semantic-release/npm",
120+
"@semantic-release/npm", // optional
106121
[
107122
"@semantic-release/git",
108123
{
@@ -119,32 +134,28 @@ File content:
119134
]
120135
}
121136
```
137+
</details>
122138

123-
### Add [Commitizen](https://github.com/commitizen/cz-cli)
124-
Add `cz` to your `package.json scripts`
125-
126-
```json
127-
{
128-
"scripts": {
129-
"commit": "cz"
130-
}
131-
}
132-
```
133139

134-
### Environment Variables Configuration
140+
## Environment Variables Configuration
135141

136142
Ensure that your CI configuration has the following environment variables set:
137143

138144
- GITHUB_TOKEN: [A GitHub personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
145+
- When a new release is published, this plugin will try to commit and push into the released branch. Ensure that the user that is running the release has push rights and can bypass branch protection rules.
139146
- NPM_TOKEN: [A npm personal access token](https://www.npmjs.com/package/settings)
147+
- A NPM token so the package can be published to NPM (a .npmrc file with extra configuration can also be used)
140148

141149
You can test your config with a dry run:
142150

143151
```sh
144152
npx semantic-release --dry-run
145153
```
146154

147-
What you’ll want to do next is configure a [GitHub workflow](https://docs.github.com/en/actions/quickstart) to run your tests and publish new versions automatically.
155+
## GitHub workflows
156+
157+
If you're [configuring a GitHub workflow](https://help.github.com/en/articles/configuring-a-workflow) you might want to do a test build matrix first and then publish only if those tests succeed across all environments.
158+
The following will do just that, immediately after something is merged into `main`.
148159

149160
Here’s an example workflow configuration that runs your tests and publishes a new version for new commits on `main` branch:
150161

@@ -246,6 +257,7 @@ jobs:
246257
run: "yarn install --immutable"
247258

248259
- name: "Build packages"
260+
if: "success()"
249261
run: "yarn build"
250262

251263
- name: "Semantic Release"
@@ -257,7 +269,7 @@ jobs:
257269
GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
258270
GIT_COMMITTER_NAME: "github-actions-shell"
259271
GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
260-
run: "yarn semantic-release"
272+
run: "npx semantic-release"
261273
```
262274
</details>
263275

‎packages/semantic-release-preset/package.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,14 @@
6363
},
6464
"dependencies": {
6565
"@anolilab/package-json-utils": "1.4.1",
66-
"@commitlint/cli": "^17.6.5",
67-
"@commitlint/config-conventional": "^17.6.5",
68-
"@commitlint/core": "^17.6.5",
6966
"@semantic-release/changelog": "^6.0.3",
7067
"@semantic-release/commit-analyzer": "^10.0.1",
7168
"@semantic-release/exec": "^6.0.3",
7269
"@semantic-release/git": "^10.0.1",
7370
"@semantic-release/github": "^9.0.3",
7471
"@semantic-release/npm": "^10.0.4",
7572
"@semantic-release/release-notes-generator": "^11.0.3",
76-
"commitizen": "^4.3.0",
77-
"conventional-changelog-conventionalcommits": "^6.0.0",
78-
"cz-conventional-changelog": "^3.3.0",
79-
"semantic-release-conventional-commits": "^3.0.0"
73+
"conventional-changelog-conventionalcommits": "^6.0.0"
8074
},
8175
"devDependencies": {
8276
"semantic-release": "^21.0.5"

‎packages/semantic-release-preset/src/postinstall.ts

+1-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
hasDep, hasDevelopmentDep, packageIsTypeModule, pkg, projectPath
2+
hasDep, hasDevelopmentDep, pkg, projectPath
33
} from "@anolilab/package-json-utils";
44
import { existsSync, writeFile } from "node:fs";
55
import { join } from "node:path";
@@ -44,54 +44,10 @@ const writeReleaseRc = () => {
4444
return writeFileAsync(releaseRcPath, content, "utf-8");
4545
};
4646

47-
/**
48-
* Writes commitlint.config.js if it doesn't exist. Warns if it exists.
49-
*/
50-
const writeCommitLintConfig = () => {
51-
const commitlintPath = join(projectPath, "commitlint.config.js");
52-
53-
if (existsSync(commitlintPath)) {
54-
console.warn("⚠️ commitlint.config.js already exists;");
55-
56-
return Promise.resolve();
57-
}
58-
59-
const content = `${packageIsTypeModule ? "export default" : "module.exports ="} {
60-
extends: ["@commitlint/config-conventional"],
61-
};
62-
63-
`;
64-
65-
return writeFileAsync(commitlintPath, content, "utf-8");
66-
};
67-
68-
/**
69-
* Writes .czrc if it doesn't exist. Warns if it exists.
70-
*/
71-
const writeCzrc = () => {
72-
const filePath = join(projectPath, ".czrc");
73-
74-
if (existsSync(filePath)) {
75-
console.warn("⚠️ .czrc already exists;");
76-
77-
return Promise.resolve();
78-
}
79-
80-
const content = `{
81-
"path": "cz-conventional-changelog"
82-
}
83-
84-
`;
85-
86-
return writeFileAsync(filePath, content, "utf-8");
87-
};
88-
8947
// eslint-disable-next-line unicorn/prefer-top-level-await
9048
(async () => {
9149
try {
9250
await writeReleaseRc();
93-
await writeCommitLintConfig();
94-
await writeCzrc();
9551

9652
console.log("😎 Everything went well, have fun!");
9753

0 commit comments

Comments
 (0)
Please sign in to comment.