Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3991

Functions to work with semantic versions

    XMLWordPrintable

    Details

      Description

      Xref: https://northern-tech.slack.com/archives/C0LCPS119/p1654288224784409

      https://semver.org/

      Strings and things sometimes will contain version numbers. It would be nice to have some function(s) for working with SemVer.

      Use cases

      I was a bit lazy while coming up with some examples and neglected to include any example versions that include pre-release versioning.

      Determine if one version is newer than another version.

      semver_newer_than( versionA, versionB )

      Returns true if version A is a more recent version than versionB, e.g. semver_newer_than( 3.0.0, 3.20.0 ) == false

      Determine if one version is newer than another version.

      semver_older_than( versionA, versionB )

      Returns true if version A is a more recent version than versionB, e.g. semver_older_than( 3.0.0, 3.20.0 ) == true

      Return the oldest version

      semver_oldest( [ "3.0.0", "3.20.0", "3.18.0" ] ) == 3.0.0

      Return the newest version

      semver_newest( [ "3.0.0", "3.20.0", "3.18.0" ] ) == 3.20.0

      Return the major version

      semver_major( "1.0.0-alpha" ) == 1

      Return the minor version

      semver_minor( "1.2.3-alpha" ) == 2

      Return the patch version

      semver_patch( "1.2.3-alpha" ) == 3

      Return the pre-release version

      semver_pre_release_version( "1.2.3-alpha.1" ) == alpha.1

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            a10042 Nick Anderson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: