Skip to content

Commit

Permalink
Merge pull request #1 from PAYONE-GmbH/feature/changelog
Browse files Browse the repository at this point in the history
chore: add conventional commit enforcement and conventional changelog generation
  • Loading branch information
ehrdi authored Aug 9, 2024
2 parents df6461a + 102df2c commit 59acfce
Show file tree
Hide file tree
Showing 7 changed files with 1,966 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 0.0.1 (2024-08-09)

### Documentation

* docs: update readme ([f3adc58a9b39a4170f4c686dde07bfc1c5dcb6b0](https://github.com/PAYONE-GmbH/PCP-server-nodeJS-SDK/commit/f3adc58a9b39a4170f4c686dde07bfc1c5dcb6b0))
* docs: update readme ([4d596a66f3007e3d96e0ef39cacd3f278f507fdc](https://github.com/PAYONE-GmbH/PCP-server-nodeJS-SDK/commit/4d596a66f3007e3d96e0ef39cacd3f278f507fdc))

44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Welcome to the Node SDK for the PAYONE Commerce Platform! This repository contai

### TODOS

- [ ] Setup changelog
- [ ] Setup sonarcloud
- [ ] Setup Github actions
- [ ] Write more tests

## Table of Contents
Expand All @@ -23,6 +20,12 @@ Welcome to the Node SDK for the PAYONE Commerce Platform! This repository contai
- [Usage](#usage)
- [Configuration](#configuration)
- [Contributing](#contributing)
- [Build the library](#build-the-library)
- [Run tests](#run-tests)
- [Releasing the library](#releasing-the-library)
- [Preparing the Release](#preparing-the-release)
- [Changelog Generation with Conventional Changelog](#changelog-generation-with-conventional-changelog)
- [Merging the Release Branch](#merging-the-release-branch)
- [License](#license)

## Features
Expand Down Expand Up @@ -60,10 +63,22 @@ Please make sure to follow the coding standards and write appropriate tests for

### Build the library

```sh
npm run build
```

### Run tests

```sh
npm run test
# or for coverage
npm run coverage
```

### Releasing the library

#### Preparing the Release

- Checkout develop branch
- Create release branch (release/0.1.0)

Expand All @@ -77,6 +92,29 @@ git checkout -b release/0.1.0
./prepare-release.sh
```

#### Changelog Generation with Conventional Changelog

After calling the `prepare_release.sh` script, it is recommended to manually trigger the changelog generation script (which uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)).

1. **Conventional Commit Messages**:

- Ensure all commit messages follow the conventional commit format, which helps in automatic changelog generation.
- Commit messages should be in the format: `type(scope): subject`.

2. **Enforcing Commit Messages**:

- We enforce conventional commit messages using [Lefthook](https://github.com/evilmartians/lefthook) with [commitlint](https://github.com/conventional-changelog/commitlint).
- This setup ensures that all commit messages are validated before they are committed.

3. **Generate Changelog**:
- Run the changelog generation script to update the `CHANGELOG.md` file:
```sh
npm run changelog
```
- Review and commit the updated changelog before proceeding with the release.

#### Merging the Release Branch

- Create PR on develop branch
- Merge develop in main branch

Expand Down
81 changes: 81 additions & 0 deletions changelog.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* eslint-disable */
const fs = require('fs');

const customTransform = (commit, context) => {
const transformedCommit = { ...commit };

switch (transformedCommit.type) {
case 'feat':
transformedCommit.customGroup = 'Features';
break;
case 'feature':
transformedCommit.customGroup = 'Features';
break;
case 'fix':
transformedCommit.customGroup = 'Bug Fixes';
break;
case 'docs':
transformedCommit.customGroup = 'Documentation';
break;
default:
transformedCommit.customGroup = null;
}

return transformedCommit;
};

module.exports = {
writerOpts: {
transform: customTransform,
groupBy: 'customGroup',
commitGroupsSort: 'title',
commitsSort: ['scope', 'subject'],
mainTemplate: `{{> header}}
{{#each commitGroups}}
{{#if title}}
### {{title}}
{{#each commits}}
{{> commit root=@root}}
{{/each}}
{{/if}}
{{/each}}
{{> footer}}
`,
headerPartial: `{{#if isPatch~}}
##
{{~else~}}
#
{{~/if}} {{#if @root.linkCompare~}}
[{{version}}](
{{~#if @root.repository~}}
{{~#if @root.host}}
{{[email protected]}}/
{{~/if}}
{{~#if @root.owner}}
{{[email protected]}}/
{{~/if}}
{{[email protected]}}
{{~else}}
{{[email protected]}}
{{~/if~}}
/compare/{{previousTag}}...{{currentTag}})
{{~else}}
{{~version}}
{{~/if}}
{{~#if title}} "{{title}}"
{{~/if}}
{{~#if date}} ({{date}})
{{/if}}
`,
},
hooks: {
postbump: () => {
const path = 'CHANGELOG.md';
if (!fs.existsSync(path)) {
fs.writeFileSync(path, '', 'utf8');
}
},
},
};
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
48 changes: 48 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# EXAMPLE USAGE:
#
# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
#
# pre-push:
# commands:
# packages-audit:
# tags: frontend security
# run: yarn audit
# gems-audit:
# tags: backend security
# run: bundle audit
#
# pre-commit:
# parallel: true
# commands:
# eslint:
# glob: "*.{js,ts,jsx,tsx}"
# run: yarn eslint {staged_files}
# rubocop:
# tags: backend style
# glob: "*.rb"
# exclude: '(^|/)(application|routes)\.rb$'
# run: bundle exec rubocop --force-exclusion {all_files}
# govet:
# tags: backend style
# files: git ls-files -m
# glob: "*.go"
# run: go vet {files}
# scripts:
# "hello.js":
# runner: node
# "any.go":
# runner: go run

pre-commit:
parallel: true
commands:
lint:
run: npm run lint
glob: "*.{js,ts}"

commit-msg:
parallel: true
commands:
commitlint:
run: npx commitlint --edit $1
Loading

0 comments on commit 59acfce

Please sign in to comment.