#changelog #parser

bin+lib parse-changelog

Simple changelog parser, written in Rust

18 releases

Uses new Rust 2021

0.5.2 Oct 25, 2022
0.5.0 Jul 24, 2022
0.4.7 Jan 21, 2022
0.4.5 Oct 15, 2021
0.2.0 Nov 30, 2020

#159 in Parser implementations

Download history 26/week @ 2022-08-15 27/week @ 2022-08-22 27/week @ 2022-08-29 49/week @ 2022-09-05 59/week @ 2022-09-12 21/week @ 2022-09-19 30/week @ 2022-09-26 35/week @ 2022-10-03 23/week @ 2022-10-10 24/week @ 2022-10-17 82/week @ 2022-10-24 51/week @ 2022-10-31 50/week @ 2022-11-07 12/week @ 2022-11-14 46/week @ 2022-11-21 9/week @ 2022-11-28

120 downloads per month

Apache-2.0 OR MIT

305KB
708 lines

parse-changelog

crates.io docs.rs license rustc build status

Simple changelog parser, written in Rust.

Installation

CLI

From source

cargo +stable install parse-changelog

From prebuilt binaries

You can download prebuilt binaries from the Release page. Prebuilt binaries are available for macOS, Linux (gnu and musl), and Windows (static executable).

Example of script to download parse-changelog
# Get host target
host=$(rustc -Vv | grep host | sed 's/host: //')
# Download binary and install to $HOME/.cargo/bin
curl -LsSf https://github.com/taiki-e/parse-changelog/releases/latest/download/parse-changelog-$host.tar.gz | tar xzf - -C $HOME/.cargo/bin

Via Homebrew

You can install parse-changelog using Homebrew tap on macOS and Linux:

brew install taiki-e/tap/parse-changelog

Via Scoop (Windows)

You can install parse-changelog using Scoop:

scoop bucket add taiki-e https://github.com/taiki-e/scoop-bucket
scoop install parse-changelog

Via cargo-binstall

You can install parse-changelog using cargo-binstall:

cargo binstall parse-changelog

Via MPR (Debian/Ubuntu)

You can install parse-changelog from the MPR:

git clone 'https://mpr.makedeb.org/parse-changelog'
cd parse-changelog/
makedeb -si
Via Prebuilt-MPR

You can also install parse-changelog from the Prebuilt-MPR, which provides automatic upgrades directly via APT. First set up the Prebuilt-MPR on your system, and then run the following:

sudo apt install parse-changelog

Note: The MPR/Prebuilt-MPR packages are maintained by the community, not the maintainer of parse-changelog.

On GitHub Actions

You can use taiki-e/install-action to install prebuilt binaries on Linux, macOS, and Windows. This makes the installation faster and may avoid the impact of problems caused by upstream changes.

- uses: taiki-e/install-action@parse-changelog

Library

To use this crate as a library, add this to your Cargo.toml:

[dependencies]
parse-changelog = { version = "0.4", default-features = false }

Note: When using this crate as a library, we recommend disabling the default features because the default features enable CLI-related dependencies and the library part of this crate does not use them.

Compiler support: requires rustc 1.56+

Usage (CLI)

parse-changelog command parses changelog and returns a release note for the specified version.

Click to show a complete list of options
$ parse-changelog --help
parse-changelog

Simple changelog parser, written in Rust.

Parses changelog and returns a release note for the specified version.

USAGE:
    parse-changelog [OPTIONS] <PATH> [VERSION]

ARGS:
    <PATH>       Path to the changelog file (use '-' for standard input)
    [VERSION]    Specify version (by default, select the latest release)

OPTIONS:
    -t, --title                       Returns title instead of notes
        --json                        Returns JSON representation of all releases in changelog
        --version-format <PATTERN>    Specify version format
        --prefix-format <PATTERN>     Specify prefix format [aliases: prefix]
    -h, --help                        Print help information
    -V, --version                     Print version information

Example: Get Rust's release notes

Get the release note for version 1.46.0 from Rust's release notes:

curl -fsSL https://raw.githubusercontent.com/rust-lang/rust/master/RELEASES.md \
  | parse-changelog - 1.46.0

output of the above command.

Example: Get Cargo's changelog

In Cargo's changelog, the title starts with "Cargo ", and the patch version is omitted. This is a format parse-changelog don't support by default, so use --prefix and --version-format to specify a custom format. For example:

curl -fsSL https://raw.githubusercontent.com/rust-lang/cargo/master/CHANGELOG.md \
  | parse-changelog --prefix 'Cargo ' --version-format '^[0-9]+\.[0-9]+$' - 1.50

output of the above command.

--prefix is the same as Parser::prefix_format and --version-format is the same as Parser::version_format. See documentation of those methods for more information.

Example: Create a new GitHub release from changelog

With GitHub CLI:

tag=...
version=...

# Get notes for $version from CHANGELOG.md.
notes=$(parse-changelog CHANGELOG.md "$version")
# Create a new GitHub release with GitHub CLI.
gh release create "$tag" --title "$version" --notes "$notes"

See also create-gh-release-action.

Usage (Library)

let changelog = "\
## 0.1.2 - 2020-03-01

- Bug fixes.

## 0.1.1 - 2020-02-01

- Added `Foo`.
- Added `Bar`.

## 0.1.0 - 2020-01-01

Initial release
";

// Parse changelog.
let changelog = parse_changelog::parse(changelog).unwrap();

// Get the latest release.
assert_eq!(changelog[0].version, "0.1.2");
assert_eq!(changelog[0].title, "0.1.2 - 2020-03-01");
assert_eq!(changelog[0].notes, "- Bug fixes.");

// Get the specified release.
assert_eq!(changelog["0.1.0"].title, "0.1.0 - 2020-01-01");
assert_eq!(changelog["0.1.0"].notes, "Initial release");
assert_eq!(changelog["0.1.1"].title, "0.1.1 - 2020-02-01");
assert_eq!(
    changelog["0.1.1"].notes,
    "- Added `Foo`.\n\
     - Added `Bar`."
);

See documentation for more information on parse-changelog as a library.

Supported Format

By default, this crate is intended to support markdown-based changelogs that have the title of each release starts with the version format based on Semantic Versioning. (e.g., Keep a Changelog's changelog format.)

Headings

The heading for each release must be Atx-style (1-6 #) or Setext-style (= or - in a line under text), and the heading levels must match with other releases.

Atx-style headings:

# 0.1.0
## 0.1.0

Setext-style headings:

0.1.0
=====
0.1.0
-----

Titles

The title of each release must start with a text or a link text (text with [ and ]) that starts with a valid version format or prefix format. For example:

# [0.2.0]

description...

# 0.1.0

description...

Prefixes

You can include characters before the version as prefix.

## Version 0.1.0
   ^^^^^^^^

By default only "v", "Version ", "Release ", and "" (no prefix) are allowed as prefixes.

To customize the prefix format, use the Parser::prefix_format method (library) or --prefix-format option (CLI).

Versions

## v0.1.0 -- 2020-01-01
    ^^^^^

The default version format is based on Semantic Versioning.

This is parsed by using the following regular expression:

^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z\.-]+)?(\+[0-9A-Za-z\.-]+)?$|^Unreleased$

Note: To get the 'Unreleased' section in the CLI, you need to explicitly specify 'Unreleased' as the version.

To customize the version format, use the Parser::version_format method (library) or --version-format option (CLI).

Suffixes

You can freely include characters after the version.

# 0.1.0 - 2020-01-01
       ^^^^^^^^^^^^^
  • create-gh-release-action: GitHub Action for creating GitHub Releases based on changelog. (Using this crate for changelog parsing.)

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.3–3.5MB
~85K SLoC