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

Parse references at end of changelog as separate part of a changelog. #2779

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

florenzen
Copy link

Description

The references to tags or compare links at the end of a changelog file are parsed into a separate member of the Changelog record. Before, lines like

[Unreleased]: https://github.com/user/MyCoolNewLib.git/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/user/MyCoolNewLib.git/releases/tag/v0.1.0

ended up in the Changes list of the last ChangelogEntry. In certain situations, this lead to undesired modifications by PromoteUnreleased since these reference lines were reproduced in a release entry.

When saving and converting a Changelog to a string, these references are also included as the last lines of the changeling file.

@xperiandri
Copy link
Collaborator

xperiandri commented Jul 11, 2024

Could you explain when this is used? I'm not familiar with this piece of functionality

@florenzen
Copy link
Author

florenzen commented Jul 26, 2024

Could you explain when this is used? I'm not familiar with this piece of functionality

Hello @xperiandri,

the Changelog module is, e.g., used in the the MiniScaffold template to manipulate the CHANGELOG.md file during a release build.

When you have a change log like this:

# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed
- Foo 2

## [0.1.0-pre.2] - 2023-10-19

### Added
- Foo 1

## [0.1.0-pre.1] - 2023-10-11

### Added
- Foo 0

[Unreleased]: https://github.com/florenzen/Foo/compare/v0.1.0-pre.2...HEAD
[0.1.0-pre.2]: https://github.com/florenzen/Foo/releases/tag/v0.1.0-pre.2
[0.1.0-pre.1]: https://github.com/florenzen/Foo/releases/tag/v0.1.0-pre.1

and then run the following code, that is a stripped down excerpt from the build code of MiniScaffold to move the unreleased and the pre-release entries to a new release section

#r "nuget: Fake.Core.ReleaseNotes"

open System
open System.IO
open Fake.Core

let chglog = Changelog.parse (File.ReadAllLines("CHANGELOG.md"))

let newVersion = SemVer.parse ("0.1.0")

let versionTuple version =
    (version.Major, version.Minor, version.Patch)

let prereleaseEntries =
    chglog.Entries
    |> List.filter (fun entry ->
        entry.SemVer.PreRelease.IsSome
        && versionTuple entry.SemVer = versionTuple newVersion)

let prereleaseChanges =
    prereleaseEntries |> List.collect (fun entry -> entry.Changes) |> List.distinct

let assemblyVersion, nugetVersion = Changelog.parseVersions newVersion.AsString

let description, unreleasedChanges =
    match chglog.Unreleased with
    | None -> None, []
    | Some u -> u.Description, u.Changes

let newEntry =
    Changelog.ChangelogEntry.New(
        assemblyVersion.Value,
        nugetVersion.Value,
        Some DateTime.Today,
        description,
        unreleasedChanges @ prereleaseChanges,
        false
    )

let newChangelog =
    Changelog.Changelog.New(chglog.Header, chglog.Description, None, newEntry :: chglog.Entries)

File.WriteAllText("CHANGELOG1.md", newChangelog.ToString())

you get:

# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2024-07-26

### Changed
- Foo 2

### Added
- Foo 1

- Foo 0
[Unreleased]: https://github.com/florenzen/Foo/compare/v0.1.0-pre.2...HEAD
[0.1.0-pre.2]: https://github.com/florenzen/Foo/releases/tag/v0.1.0-pre.2
[0.1.0-pre.1]: https://github.com/florenzen/Foo/releases/tag/v0.1.0-pre.1

## [0.1.0-pre.2] - 2023-10-19

### Added
- Foo 1

## [0.1.0-pre.1] - 2023-10-11

### Added
- Foo 0

[Unreleased]: https://github.com/florenzen/Foo/compare/v0.1.0-pre.2...HEAD
[0.1.0-pre.2]: https://github.com/florenzen/Foo/releases/tag/v0.1.0-pre.2
[0.1.0-pre.1]: https://github.com/florenzen/Foo/releases/tag/v0.1.0-pre.1

All the links from the bottom are part of the Foo 0 added entry since by the parsing mechanics of the Changelog modules, they are considered to be part of that entry.

By moving them to a separate component of the changeling record type, this does not happen anymore.

@xperiandri
Copy link
Collaborator

@TheAngryByrd any remarks?

@TheAngryByrd
Copy link
Contributor

Overall love it :)

Probably needs some extra tests to make sure we don't mess up files or regress.

@xperiandri
Copy link
Collaborator

Can you give any particular advice?

@TheAngryByrd
Copy link
Contributor

Can you give any particular advice?

@florenzen has an example here that would be useful as a test case.

@xperiandri
Copy link
Collaborator

Should it be added as a test?

@florenzen
Copy link
Author

I'll add it as a test as soon as I find a minute for it.
Thanks for your feedback so far.

@florenzen
Copy link
Author

I added several test cases. Glad to receive your feedback on these, @TheAngryByrd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants