Search Unity

Recommended approach to handle multiple release versions of custom package on git

Discussion in 'Package Manager' started by Xarbrough, Jul 24, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I’ve set up our company’s first package on git and wonder what the typical development and release strategy would be to handle different versions. For example, I started developing with Unity 2018.3 as the minimum supported version and then updated the package to handle API changes in 2019.1. Using packages, it sounds logical to not try to fit all version compatibility via #if UNITY_X_Y into the same source, but instead simply make the changes and then change the supported Unity version in the manifest. Does this make sense? If so, how do I best commit this change to the repository? As a regular changeset on the master branch, tags or a separate release branch for each Unity version? The package manager docs state that I could use all of these methods to specify which version to dowload in projects that use the package, but what are the pros and cons?
     
    Last edited: Jul 25, 2019
    Peter77 likes this.
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    #if UNITY_X_Y works best for both dev and user. I didn't see much package use the branch strategy, to ask user download this version for Unity x and that version for Unity y.
     
  3. manu73

    manu73

    Unity Technologies

    Joined:
    Aug 22, 2014
    Posts:
    68
    Hi @Xarbrough !

    Let me recap:
    You already have a package xyz@1.0.0 that is compatible with Unity 2018.3
    You want to make it compatible in 2019.1 because their's some API changes in Unity

    So, you need to create a new version your package and mark it compatible with 2019.1 (minimum version)

    The best approach for you will be to have to separate branches in your repo (one for 2018.3 and one for 2019.1) in case you need to publish a patch version (bug fixes for 2018.3, in case you need to publish xyz@1.0.1)

    Regards,

    Manu
     
  4. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    @manu73 Thanks, that sounds like a sensible approach. :)

    How does Unity do semantic versioning in this case? Do I start with xyz@1.0.0 for Unity 2018.3 and then jump to xyz@2.0.0 for Unity 2019.1 and so on, allowing me to insert minor or patch versions for different branches later?
     
  5. manu73

    manu73

    Unity Technologies

    Joined:
    Aug 22, 2014
    Posts:
    68
    @Xarbrough

    I recommend you to only increase minor version. It will let you space for possible patches.
    For 2018.3: x.y.z@1.0.0 (so you will have space for possible patch versions 1.0.1... 1.0.nnn)
    For 2019.1: x.y.z@1.1.0 (so you will have space for possible patch versions 1.1.1... 1.1.nnn)

    Of course, if your public APIs need to be updated because of changes required, you need to use x.y.z@2.0.0 to clearly identify API break (See https://semver.org/)

    Regards,

    Manu
     
    Xarbrough likes this.
  6. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    @Xarbrough,

    I'd like to offer different guidance on the topic. While the suggestion made by my colleague @manu73 would certainly work, it's not really aligned with semantic versioning, and it could lead you into a corner where you would need to make a decision among bad choices. For instance, if you were to use different versions for 2018.X and 2019.X, but you wanted to implement a new feature for both Editor versions, you'd have to lie in the 2018.X versioning by slipping a feature inside a patch version. (Note that your suggestion of using different major versions alleviates this somewhat, but you're still stuck if you need to make a breaking change in your 2018.X-compatible API...)

    As mentioned by @Favo-Yang a superior approach is actually to leverage Unity's #if UNITY_X_Y_OR_NEWER, so that a single package works across multiple versions. Why? Well, it's simpler for you (no forking or versioning hell induced by Unity versions, no backporting or unnecessary branching), and it's simpler for consumers (more consistent feature-set, less likely to need explicitly changing dependencies when switching Unity versions, and it makes your package easier to use as a dependency in other packages).

    Going back to your initial question, which addressed using Git as a delivery method. In that case, you can certainly ignore the above advice if your users only use Git URLs with branches, but as soon as you want to follow a more Semver-esque strategy (including if you want to ship versions of your package through a registry), I would strongly recommend keeping a single codebase, with as few #if as needed to keep your code maintainable.
     
    Xarbrough and Peter77 like this.
  7. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    556
    Note that the above was meant in a general manner. In your case, where you use Git as the delivery mechanism, your package cannot be referenced as a dependency in another package because that's not (yet) supported. If you used a scoped registry, however, there would be no such limitation.