Skip to content

Allow custom prerelease bumping strategy different from node semver #282

@Elenterius

Description

@Elenterius

As of #273 pre-releases are no longer incremented and instead MAJOR.MINOR.PATCH are bumped and the same identifier.0 is appended.

Working as expected:

1.0.0 + MINOR --> 1.1.0-identifier.0
1.1.1 + PATCH --> 1.1.2-identifier.0
1.1.0 + MINOR --> 1.2.0-identifier.0
1.1.0 + MAJOR --> 2.0.0-identifier.0
2.2.0-identifier.0 + MAJOR --> 3.0.0-identifier.0

Unfavorable Behavior for me where the pre-release is reset instead of incremented:

1.0.1-identifier.0 + PATCH --> 1.0.2-identifier.0
1.1.0-identifier.0 + PATCH --> 1.1.1-identifier.0
1.1.0-identifier.0 + MINOR --> 1.2.0-identifier.0
2.0.0-identifier.0 + MAJOR --> 3.0.0-identifier.0

Bumping of pre-release in semver is fairly subjective and mostly left up to the developer as long as a valid potential future version is chosen. As such I would like to have the ability to change the behavior of this gh action with my own strategy and not be constrained to node's semver behavior.

I want to implement the following behavior:

1.0.1-identifier.0 + PATCH --> 1.0.1-identifier.1
1.1.0-identifier.0 + PATCH --> 1.1.0-identifier.1
1.1.0-identifier.0 + MINOR --> 1.1.0-identifier.1
2.0.0-identifier.0 + MAJOR --> 2.0.0-identifier.1
2.2.0-identifier.1 + MAJOR --> 3.0.0-identifier.0
function bumpVersionHook(oldVersion, releaseType, isPreRelease, identifier) {
    if (isPreRelease) {
        return bumpPreReleaseVersion(oldVersion, releaseType, identifier);
    }
    
    return semver.inc(oldVersion, releaseType, identifier);
}

function bumpPreReleaseVersion(oldVersion, releaseType, identifier) {
    const oldSemVersion = semver.parse(oldVersion);
    const isStable = oldSemVersion.prerelease.length === 0;

    if (!isStable) {
        const stableBase = semver.inc(oldSemVersion, releaseType);
        const oldBase = `${oldSemVersion.major}.${oldSemVersion.minor}.${oldSemVersion.patch}`;
        if (oldBase === stableBase) {
            console.log(`incrementing ${oldSemVersion.format()} with prerelease`);
            return semver.inc(oldSemVersion, "prerelease", identifier);
        }
    }
    
    console.log(`incrementing ${oldSemVersion.format()} with pre${releaseType}`);
    return semver.inc(oldSemVersion, `pre${releaseType}`, identifier);
}

Sadly I can't use the pre-changelog-generation.preVersionGeneration hook because it is lacking the oldVersion, releaseType, prerelease and identifier information which i need to for custom bump behavior.

Therefore i would like to request a new hook to replace the version bump behavior or provide all the missing information to the callback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions