This plugin provides helpers for updating a version file and committing the changes to git.
Note: You can still make manual changes to the version file in-between execution of the targets provided by the module. Each target operates on the version file as is at the time of execution.
Add a VersionFileModule
to the build.sc
file:
import $ivy.`com.lihaoyi::mill-contrib-versionfile:`
import mill.contrib.versionfile.VersionFileModule
object versionFile extends VersionFileModule
The module will read and write to the file version
located at the module’s millSourcePath
.
In the example above, that would be /versionFile/version
relative to the build.sc
file.
Create the version file with the initial version number:
$ 0.1.0-SNAPSHOT > versionFile/version
Then to write a release version or snapshot version to file:
$ mill versionFile.setReleaseVersion # Sets release
$ mill versionFile.setNextVersion --bump minor # Sets snapshot
You can also make manual changes in-between:
$ mill versionFile.setReleaseVersion
$ echo 0.1.0 > versionFile/version
$ mill versionFile.setNextVersion --bump minor # Will now set the version to 0.2.0-SNAPSHOT
If you want to use the version file for publishing, you can do it like this:
import $ivy.`com.lihaoyi::mill-contrib-versionfile:`
import mill.contrib.versionfile.VersionFileModule
object versionFile extends VersionFileModule
object mymodule extends PublishModule {
def publishVersion = versionFile.currentVersion().toString
...
}
If you want the version file to have another name, you will need to override the versionFile
task.
If you have a project wide version file like in the example above, and you want the version file to reside
at the root of the project, you can override millSourcePath
:
import $ivy.`com.lihaoyi::mill-contrib-versionfile:`
import mill.contrib.versionfile.VersionFileModule
object versionFile extends VersionFileModule {
def millSourcePath = millOuterCtx.millSourcePath
}
In this example, it would look for the file version
in the same directory as the build.sc
.
The setReleaseVersion
target removes the -SNAPSHOT
identifier from the version,
then overwrites the previous content in the version file with this new version.
The setNextVersion
target bumps the version and changes it to a snapshot version,
then overwrites the previous content in the version file with this new version.
The setVersion
overwrites the previous content of the version file with an arbitrary version.
If you need to output the version numbers (for example for other CI tools you might use), you can use the following commands:
# Show the current version from the version file.
$ mill show versionFile.currentVersion
# Show the version that would be used as release version.
$ mill show versionFile.releaseVersion
# Show the version that would be used as next version with the given --bump argument.
$ mill show versionFile.nextVersion --bump minor
The module has an exec
task that allows you to execute tasks of type T[Seq[os.proc]]
:
$ mill mill.contrib.versionfile.VersionFile/exec --procs versionFile.tag
$ mill mill.contrib.versionfile.VersionFile/exec --procs versionFile.push
The VersionFileModule
comes with two tasks of this type: