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

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

florenzen
Copy link
Contributor

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
Contributor 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 xperiandri force-pushed the changelog-parse-references branch from 887e7c1 to ce42a01 Compare July 26, 2024 08:53
@xperiandri
Copy link
Collaborator

@TheAngryByrd any remarks?

@xperiandri xperiandri force-pushed the changelog-parse-references branch from ce42a01 to 90d75b7 Compare July 27, 2024 15:35
@TheAngryByrd
Copy link
Contributor

Overall love it :)

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

@xperiandri xperiandri force-pushed the changelog-parse-references branch from 90d75b7 to 137a6f1 Compare July 29, 2024 23:55
@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
Contributor Author

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

@florenzen florenzen force-pushed the changelog-parse-references branch from f802046 to 4226bd8 Compare September 14, 2024 08:46
@florenzen
Copy link
Contributor Author

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

@florenzen
Copy link
Contributor Author

florenzen commented Dec 19, 2024

Any chance of getting this one merged and closed or should I make some more changes to it?

@xperiandri
Copy link
Collaborator

@TheAngryByrd could you have a look?

@xperiandri xperiandri force-pushed the changelog-parse-references branch from b94624d to a9ef205 Compare January 8, 2025 01:11
@xperiandri xperiandri force-pushed the changelog-parse-references branch from a9ef205 to eeab39b Compare January 8, 2025 17:14
src/app/Fake.Core.ReleaseNotes/Changelog.fs Outdated Show resolved Hide resolved
src/app/Fake.Core.ReleaseNotes/Changelog.fs Outdated Show resolved Hide resolved
@xperiandri xperiandri merged commit 3ee60b4 into fsprojects:master Jan 8, 2025
@xperiandri
Copy link
Collaborator

xperiandri commented Jan 8, 2025

@florenzen could you submit release notes file update describing this fix?

@florenzen
Copy link
Contributor Author

@xperiandri, where should I submit the release notes line?

I think, it would read like this:

* ENHANCEMENT: Parse references at end of changelog as separate component, thanks @florenzen - https://github.com/fsprojects/FAKE/pull/2779

Thanks for accepting the contribution.

@xperiandri
Copy link
Collaborator

I’ll push manually, thanks

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