Skip to content

Commit

Permalink
feat(semver): bump conventional-changelog to v5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
edbzn committed Oct 21, 2023
1 parent 986209c commit f6aa922
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 157 deletions.
2 changes: 2 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ runs:
- name: Test
shell: bash
run: yarn nx test semver --code-coverage
env:
NODE_OPTIONS: --experimental-vm-modules
- name: E2E
shell: bash
run: yarn nx affected:e2e --headless --base=last-release
Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ nx run workspace:version [...options]
6. Pushes the version to the remote repository.
7. Runs post-targets hook to publish the version on NPM, GitHub or GitLab.

Important: merge commits messages are ignored by the tool when calculating next version to bump.

#### Available options

| name | type | default | description |
Expand Down Expand Up @@ -116,10 +114,21 @@ The preset is highly configurable, following the [conventional-changelog configu
"executor": "@jscutlery/semver:version",
"options": {
"preset": {
"name": "conventionalcommits",
"commitUrlFormat": "{{host}}/{{owner}}/{{repository}}/commit/{{hash}}",
"compareUrlFormat": "{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}",
"issueUrlFormat": "{{host}}/{{owner}}/{{repository}}/issues/{{id}}",
"issueUrlFormat": "{{host}}/{{owner}}/{{repository}}/issues/{{id}}"
}
}
}
```

You can also add your own custom types, for example:

```json
{
"executor": "@jscutlery/semver:version",
"options": {
"preset": {
"types": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
Expand All @@ -137,7 +146,7 @@ The preset is highly configurable, following the [conventional-changelog configu
}
```

See [conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec) for available
See the [conventional-changelog-config-spec](https://github.com/conventional-changelog/conventional-changelog-config-spec) for available
configuration options.

#### Customizing the commit parser
Expand Down Expand Up @@ -165,7 +174,11 @@ This package is **tag-based**, which means it never reads the `package.json` to

To detect a new version this package looks into the commit history and checks if any source files changed since the last version.

> **Note**: Major zero version `0.x.y` is for initial development. Anything may change at any time so the consumer won't get any new minor version using the caret or tilde compatibility range, for instance version `0.3.1` won't be resolved if the consumer wants `^0.2.0`.
> [!IMPORTANT]
> Major zero version `0.x.y` is for initial development. Anything may change at any time so the consumer won't get any new minor version using the caret or tilde compatibility range, for instance version `0.3.1` won't be resolved if the consumer wants `^0.2.0`.
> [!NOTE]
> Merge commits are ignored by the tool when calculating next version to bump.
#### Specify the level of change

Expand Down
9 changes: 1 addition & 8 deletions packages/semver/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
export default {
displayName: 'semver',
setupFilesAfterEnv: ['jest-extended/all'],
transform: {
'^.+\\.[tj]sx?$': [
'ts-jest/legacy',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
transform: {},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
coverageDirectory: '../../coverage/packages/semver',
coverageReporters: ['html', 'lcov'],
Expand Down
5 changes: 3 additions & 2 deletions packages/semver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
},
"dependencies": {
"chalk": "4.1.2",
"conventional-changelog": "^5.0.0",
"conventional-changelog": "^5.1.0",
"conventional-changelog-conventionalcommits": "^7.0.2",
"conventional-recommended-bump": "^7.0.0",
"detect-indent": "6.1.0",
"inquirer": "8.2.6",
"rxjs": "7.8.1"
},
"devDependencies": {
"@types/conventional-changelog": "^3.1.1",
"@types/conventional-changelog": "^3.1.4 ",
"@types/conventional-recommended-bump": "6.1.1",
"@types/inquirer": "8.2.9",
"@types/rimraf": "3.0.2",
Expand Down
9 changes: 5 additions & 4 deletions packages/semver/src/executors/version/index.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
import { readFile } from './utils/filesystem';
import { getProjectDependencies } from './utils/get-project-dependencies';
import { readPackageJson } from './utils/project';
import { jest } from '@jest/globals';

jest.mock('@nx/devkit');

describe('@jscutlery/semver:version', () => {
xdescribe('@jscutlery/semver:version', () => {
const defaultBuilderOptions: VersionBuilderSchema = {
dryRun: false,
noVerify: false,
Expand Down Expand Up @@ -76,8 +77,8 @@ describe('@jscutlery/semver:version', () => {
let testingWorkspace: TestingWorkspace;

beforeAll(() => {
jest.spyOn(console, 'warn').mockImplementation();
jest.spyOn(console, 'info').mockImplementation();
jest.spyOn(console, 'warn').mockImplementation(() => {});
jest.spyOn(console, 'info').mockImplementation(() => {});
});

afterAll(() => (console.info as jest.Mock).mockRestore());
Expand Down Expand Up @@ -562,7 +563,7 @@ $`),
beforeEach(() => {
const originalModule = jest.requireActual(
'@nx/workspace/src/core/project-graph',
);
) as any;
mockCreateProjectGraphAsync.mockImplementation(
originalModule.createProjectGraphAsync,
);
Expand Down
21 changes: 9 additions & 12 deletions packages/semver/src/executors/version/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ describe('@jscutlery/semver:version', () => {
describe('--preset', () => {
it('should use --preset=angular by default', async () => {
const { success } = await version(
/// @ts-expect-error - preset is not in the schema
{ ...options, preset: undefined },
context,
);
Expand All @@ -720,9 +721,9 @@ describe('@jscutlery/semver:version', () => {
);
});

it('should use --preset=conventional', async () => {
it('should use --preset=conventionalcommits', async () => {
const { success } = await version(
{ ...options, preset: 'conventional' },
{ ...options, preset: 'conventionalcommits' },
context,
);

Expand All @@ -735,26 +736,22 @@ describe('@jscutlery/semver:version', () => {
});

it('should use --preset=conventional-changelog-config-spec', async () => {
const preset = {
compareUrlFormat:
'{{host}}/{{owner}}/{{repository}}/compareee/{{previousTag}}...{{currentTag}}',
};
const { success } = await version(
{
...options,
preset: {
name: 'conventionalcommits',
compareUrlFormat:
'{{host}}/{{owner}}/{{repository}}/compareee/{{previousTag}}...{{currentTag}}',
},
preset,
},
context,
);

expect(success).toBe(true);
expect(mockUpdateChangelog).toBeCalledWith(
expect.objectContaining({
preset: {
compareUrlFormat:
'{{host}}/{{owner}}/{{repository}}/compareee/{{previousTag}}...{{currentTag}}',
name: 'conventionalcommits',
},
preset,
}),
);
});
Expand Down
9 changes: 4 additions & 5 deletions packages/semver/src/executors/version/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ExecutorContext } from '@nx/devkit';
import { concat, defer, lastValueFrom, of } from 'rxjs';
import { catchError, concatMap, reduce, switchMap } from 'rxjs/operators';
import type { VersionBuilderSchema } from './schema';
import type { Preset, VersionBuilderSchema } from './schema';
import {
calculateChangelogChanges,
defaultHeader,
Expand Down Expand Up @@ -241,9 +241,8 @@ function _normalizeOptions(options: VersionBuilderSchema) {
commitMessageFormat: options.commitMessageFormat as string,
commitParserOptions: options.commitParserOptions,
skipCommit: options.skipCommit as boolean,
preset:
options.preset === 'conventional'
? 'conventionalcommits'
: options.preset || 'angular',
preset: (options.preset === 'conventional'
? 'conventionalcommits'
: options.preset || 'angular') as Preset,
};
}
13 changes: 9 additions & 4 deletions packages/semver/src/executors/version/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ConventionalChangelogConfigSpec from '@types/conventional-changelog-config-spec';
import type { Options as CommitParserOptions } from 'conventional-commits-parser';

export { CommitParserOptions };
Expand All @@ -14,9 +13,15 @@ export type ReleaseIdentifier =

export type Preset =
| 'angular'
| 'conventional'
| 'conventionalcommits'
| ({ name: string } & ConventionalChangelogConfigSpec.Config);
| 'atom'
| 'codemirror'
| 'ember'
| 'eslint'
| 'express'
| 'jquery'
| 'jshint'
| Record<string, any>; // Custom preset, see: https://github.com/conventional-changelog/conventional-changelog-config-spec/blob/master/versions/2.2.0/README.md

export interface VersionBuilderSchema {
dryRun?: boolean;
Expand All @@ -37,7 +42,7 @@ export interface VersionBuilderSchema {
allowEmptyRelease?: boolean;
skipCommitTypes?: string[];
commitMessageFormat?: string;
preset: Preset;
preset: Preset | 'conventional'; // @TODO: Remove 'conventional' in the next major release.
commitParserOptions?: CommitParserOptions;
}

Expand Down
60 changes: 8 additions & 52 deletions packages/semver/src/executors/version/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"oneOf": [
{
"type": "string",
"enum": ["angular", "conventional"],
"enum": ["angular", "conventional", "conventionalcommits"],
"default": "angular"
},
{
Expand Down Expand Up @@ -170,63 +170,22 @@
"title": "Conventional Changelog Configuration",
"description": "Describes the configuration options supported by conventional-config for upstream tooling.",
"type": "object",
"required": ["name"],
"required": [],
"properties": {
"name": {
"type": "string",
"description": "A base preset name to be customized.",
"default": "angular"
},
"header": {
"type": "string",
"description": "A string to be used as the main header section of the CHANGELOG.",
"default": "# Changelog\n\n"
"description": "A string to be used as the main header section of the CHANGELOG."
},
"types": {
"description": "An array of `type` objects representing the explicitly supported commit message types, and whether they should show up in generated `CHANGELOG`s.",
"type": "array",
"items": {
"$ref": "#/definitions/type"
},
"default": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"hidden": true
},
{
"type": "docs",
"hidden": true
},
{
"type": "style",
"hidden": true
},
{
"type": "refactor",
"hidden": true
},
{
"type": "perf",
"hidden": true
},
{
"type": "test",
"hidden": true
}
]
}
},
"preMajor": {
"type": "boolean",
"description": "Boolean indicating whether or not the action being run (generating CHANGELOG, recommendedBump, etc.) is being performed for a pre-major release (<1.0.0).\n This config setting will generally be set by tooling and not a user.",
"default": false
"description": "Boolean indicating whether or not the action being run (generating CHANGELOG, recommendedBump, etc.) is being performed for a pre-major release (<1.0.0).\n This config setting will generally be set by tooling and not a user."
},
"commitUrlFormat": {
"type": "string",
Expand All @@ -245,21 +204,18 @@
},
"userUrlFormat": {
"type": "string",
"description": "A URL representing the a user's profile URL on GitHub, Gitlab, etc. This URL is used for substituting @bcoe with https://github.com/bcoe in commit messages.",
"default": "{{host}}/{{user}}"
"description": "A URL representing the a user's profile URL on GitHub, Gitlab, etc. This URL is used for substituting @bcoe with https://github.com/bcoe in commit messages."
},
"releaseCommitMessageFormat": {
"type": "string",
"description": "A string to be used to format the auto-generated release commit message.",
"default": "chore(release): {{currentTag}}"
"description": "A string to be used to format the auto-generated release commit message."
},
"issuePrefixes": {
"type": "array",
"items": {
"type": "string"
},
"description": "An array of prefixes used to detect references to issues",
"default": ["#"]
"description": "An array of prefixes used to detect references to issues"
}
}
},
Expand Down

0 comments on commit f6aa922

Please sign in to comment.