Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add tooling for changelog generation #1289

Merged
merged 46 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f2c106b
build: changelog generation
Planeshifter Jan 16, 2024
a2b4544
build: add new dev dependencies
Planeshifter Jan 28, 2024
0f25e8b
build: add section tags
Planeshifter Jan 30, 2024
c73ed53
build: add version suffix to ids and use kebab case consistently
Planeshifter Jan 31, 2024
674736d
build: add parameter to generate changelog for new release
Planeshifter Feb 1, 2024
3695e2d
build: generate changelog in publish script
Planeshifter Feb 1, 2024
abfc020
build: fix generated ids in changelog
Planeshifter Feb 1, 2024
7e5af81
build: rewrite changelog in standalone repo publish action
Planeshifter Feb 1, 2024
1caa4dd
build: refactor to also include breaking changes and closed issues at…
Planeshifter Feb 2, 2024
aa4c509
build: use headers for packages in namespace changelogs
Planeshifter Feb 2, 2024
4e6f72e
build: add section tag helpers and minor clean-up
Planeshifter Feb 3, 2024
26d9275
build: extract co-authors from footer
Planeshifter Feb 3, 2024
b7faceb
Apply suggestions from code review
kgryte Feb 15, 2024
97ad340
Apply suggestions from code review
kgryte Feb 15, 2024
89d4f94
Apply suggestions from code review
kgryte Feb 15, 2024
bbf1966
Apply suggestions from code review
kgryte Feb 15, 2024
943db17
build: implement suggestions from code review
Planeshifter Feb 16, 2024
d819b2c
Update lib/node_modules/@stdlib/_tools/changelog/generate/lib/npm_rel…
Planeshifter Feb 16, 2024
d281b87
Update lib/node_modules/@stdlib/_tools/changelog/generate/lib/format_…
Planeshifter Feb 16, 2024
8dc4d2e
Update lib/node_modules/@stdlib/_tools/changelog/generate/README.md
Planeshifter Feb 16, 2024
99ba538
build: expect package names with stdlib namespace prefix
Planeshifter Feb 16, 2024
e0e0716
refactor: implement code review feedback
Planeshifter Feb 17, 2024
43f14fa
build: refactor to accept directories instead of packages
Planeshifter Feb 18, 2024
32ef0d4
build: fix passed arguments
Planeshifter Feb 18, 2024
32f483a
build: add tool to suggest version change
Planeshifter Feb 18, 2024
43cf265
build: refactor to allow for automatically determined version bumps
Planeshifter Feb 18, 2024
1cf64b3
build: move git log cmd to standalone script
Planeshifter Feb 18, 2024
0480d93
build: minor doc fixes and clean-up
Planeshifter Feb 18, 2024
c7469b0
Apply suggestions from code review
kgryte Jun 2, 2024
63a4a33
Apply suggestions from code review
kgryte Jun 2, 2024
1605a4a
Apply suggestions from code review
kgryte Jun 3, 2024
2059ad3
Apply suggestions from code review
kgryte Jun 3, 2024
a17fb40
Apply suggestions from code review
kgryte Jun 3, 2024
d7e748f
Apply suggestions from code review
kgryte Jun 3, 2024
bd4c240
Apply suggestions from code review
kgryte Jun 3, 2024
4b372ae
Apply suggestions from code review
kgryte Jun 3, 2024
3e7cac5
Apply suggestions from code review
kgryte Jun 3, 2024
b853de3
Apply suggestions from code review
kgryte Jun 3, 2024
67972c6
Apply suggestions from code review
kgryte Jun 3, 2024
0b84a63
Apply suggestions from code review
kgryte Jun 3, 2024
83437ba
Apply suggestions from code review
kgryte Jun 3, 2024
a638b1a
Apply suggestions from code review
kgryte Jun 3, 2024
c1ed41b
Apply suggestions from code review
kgryte Jun 3, 2024
ab1e03d
Apply suggestions from code review
kgryte Jun 3, 2024
f60c6dc
style: remove trailing spaces
kgryte Jun 3, 2024
2bc6a29
fix: replace includes with indexOf checks
Planeshifter Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/standalone_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ on:
- patch
- minor
- major
- auto
dry-run:
type: boolean
description: 'Skip uploading packages (dry run):'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/standalone_publish_custom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ on:
- patch
- minor
- major
- auto
only-unpublished:
type: boolean
description: 'Only publish packages that have not yet been published'
Expand Down
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/_tools/changelog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--

@license Apache-2.0

Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Changelog

> Changelog tooling.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

This directory contains utilities for managing and maintaining changelogs of project packages.

</section>

<!-- /.intro -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
125 changes: 125 additions & 0 deletions lib/node_modules/@stdlib/_tools/changelog/generate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!--

@license Apache-2.0

Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Generate Changelog

> Generate a changelog for a specified stdlib package.

<section class="usage">

## Usage

```javascript
var generate = require( '@stdlib/_tools/changelog/generate' );
```

#### generate( pkg\[, releaseType] )

Generates a Markdown formatted changelog for a specified package.

```javascript
var changelog = generate( '@stdlib/assert/contains' );
// returns {...}
```

The function returns an object with the following properties:

- **content**: Markdown formatted changelog.
- **releaseType**: release type (`null` if changelog is for a non-release).

To generate a changelog for an upcoming release, provide a valid release type as the second argument.

```javascript
var changelog = generate( '@stdlib/assert/contains', 'patch' );
// returns {...}

changelog = generate( '@stdlib/assert/contains', 'minor' );
// returns {...}
```

The following release types are supported:

- `patch`: a patch release (e.g., bug fixes).
- `minor`: a minor release (e.g., new features which do not break backward compatibility).
- `major`: a major release (e.g., breaking changes).
- `prerelease`: a prerelease (e.g., a release candidate).
- `prepatch`: a prepatch release.
- `preminor`: a preminor release.
- `premajor`: a premajor release.
- `auto`: automatically determine the release type based on parsed commit messages.

</section>

<!-- /.usage -->

<section class="notes">

</section>

<!-- /.notes -->

<section class="examples">

## Examples

```javascript
var generate = require( '@stdlib/_tools/changelog/generate' );

// Generate a changelog for a non-namespace package:
var changelog = generate( '@stdlib/utils/curry' );
var content = changelog.content;
// returns '...'

var releaseType = changelog.releaseType;
// returns null

// Generate a changelog for a new release:
changelog = generate( '@stdlib/utils/curry', 'patch' );
content = changelog.content;
// returns '...'

releaseType = changelog.releaseType;
// returns 'patch'

// Generate a changelog for a namespace package:
changelog = generate( '@stdlib/string/base' );
content = changelog.content;
// returns '...'
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var generate = require( './../lib' );

// Generate a changelog for a non-namespace package:
var changelog = generate( '@stdlib/utils/curry' );
var content = changelog.content;
console.log( content );
// => '...'

var releaseType = changelog.releaseType;
console.log( releaseType );
// => null

// Generate a changelog for a new release:
changelog = generate( '@stdlib/utils/curry', 'patch' );
content = changelog.content;
console.log( content );
// => '...'

releaseType = changelog.releaseType;
console.log( releaseType );
// => 'patch'

// Generate a changelog for a namespace package:
changelog = generate( '@stdlib/string/base' );
content = changelog.content;
console.log( content );
// => '...'
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var filter = require( '@stdlib/array/base/filter' );
var trim = require( '@stdlib/string/trim' );
var map = require( '@stdlib/utils/map' );
var collectField = require( './collect_field.js' );
var sectionStart = require( './section_start.js' );
var sectionEnd = require( './section_end.js' );
var heading = require( './heading.js' );


// VARIABLES //

var STDLIB_GITHUB_URL = 'https://github.com/stdlib-js/stdlib/commit';


// FUNCTIONS //

/**
* Formats a breaking change.
*
* @private
* @param {Object} note - note object
* @returns {string} changelog entry
*
* @example
* var note = {
* 'title': 'BREAKING CHANGE',
* 'text': 'beep',
* 'hash': 'abcdef1234567890'
* };
* var out = formatBreakingChange( note );
* // returns '- [`abcdef1`](https://github.com/stdlib-js/stdlib/commit/abcdef1234567890): beep'
*/
function formatBreakingChange( note ) {
var parts = note.text.split( '\n' );
var hash = trim( note.hash );
var out = '- [`'+hash.substring( 0, 7 )+'`]('+STDLIB_GITHUB_URL+'/'+hash+'): '+parts[ 0 ];
if ( parts.length > 1 ) {
out +=' \n\n';
out += ' - ';
out += parts.slice( 1 ).join( '\n ' );
out += '\n';
}
return out;
}

/**
* Tests whether a note is a breaking change.
*
* @private
* @param {Object} note - note object
* @returns {boolean} boolean indicating whether a note is a breaking change
*/
function isBreakingChange( note ) {
return note.title === 'BREAKING CHANGE';
}


// MAIN //

/**
* Extracts breaking changes from a list of commits and formats them as a Markdown list.
*
* @private
* @param {ObjectArray} commits - commit objects
* @returns {string} list of breaking changes
*/
function breakingChanges( commits ) {
var breakingChanges;
var notes;
var out;

notes = collectField( commits, 'notes' );
breakingChanges = filter( notes, isBreakingChange );
if ( breakingChanges.length === 0 ) {
return '';
}
out = sectionStart( 'breaking-changes' );
out += heading( 'BREAKING CHANGES', 3 );
out += map( breakingChanges, formatBreakingChange ).join( '\n' );
out += sectionEnd( 'breaking-changes' );
return out;
}


// EXPORTS //

module.exports = breakingChanges;
Loading
Loading