opened
theckman
username_0
This change enhances the `autotag` package to support including pre-release
information on to a generated tag. This functionality is being added to
facilitate the tagging of releases that aren't considered ready for stable
release, while being able to generate a tag that's useful for humans and
automated tooling.

**Note:** this change introduces a breaking API change to the `NewRepo()`
function. Instead of taking two string parameters, the function now takes an
`autotag.GitRepoConfig` instance. This is because we added two new user-provided
parameters to the `GitRepo` struct.

In our organization, we have the need to create releases from branches before
the merge to the stable (`master`) branch happens. This need isn't part of our
normal release workflow, and is reserved for situations where a release is
needed from a branch (think hotfix, or similar).

To accomplish the creation of pre-release tags, we added two new parameters that
can be used to configure the GitRepo:

* PreReleaseName: the `NAME` to use in the tag (e.g., `v1.2.3-NAME`)
* PreReleaseTimestampLayout the `LAYOUT` to use to generate the timestamp (e.g.,
  `v1.2.3-LAYOUT`) -- this a layout string from the `time` package

If either of these values are set, or both, a hyphen is added to the tag and the
respective values are added to the end of the tag. If these two values are
combined, and name is `test` and the layout is `epoch`, the tag would look
something like `v1.2.4-test.1499323531`.

Within the `autotag` package itself, this is done by calculating the new stable
tag (e.g., `v1.2.4`) and then appending the pre-release information to the end
of it. The `autotag` code path that determines the latest tag now explicitly
skips over tags with pre-release information attached. This is to ensure our
pre-release tags are only cut from stable ones.

Within the `autotag` binary, two more command line flags have been added:

```
-p, --pre-release-name=      create a pre-release tag with this name (can be: alpha|beta|pre|rc)
-T, --pre-release-timestamp= create a pre-release tag and append a timestamp (can be: datetime|epoch)
```

The `-p` flag allows users to specify the pre-release-name. While the `autotag`
package allows us to specify any string we want, the `autotag` binary only
accepts a subset of values to use (to promote good practices). The help output
lists the possible values.

The `-T` flag supports either setting a `datetime` (`YYYYMMDDHHMMSS`) timestamp,
or a UNIX `epoch` timestamp.

Here is an example of them being used:

```
$ autotag -n -p pre
1.1.1-pre
$ autotag -n -T epoch
1.1.1-1499320004
$ autotag -n -T datetime
1.1.1-20170706054703
$ autotag -n -p pre -T epoch
1.1.1-pre.1499319951
$ autotag -n -p pre -T datetime
1.1.1-pre.20170706054528
```

In addition to the changes made, extra tests were added to assert the new
functionality of the package. None of the older tests were changed, which
indicates the behavior of the `autotag` binary should be backwards compatible
with previous versions.
Add support for creating pre-release tags from last stable tag
issue
created
spheromak
username_1
thanks @username_0
comment
created
theckman
username_0
@username_1 my pleasure, thank you for the quick review/merge as well as making this codebase easy to extend (you too @fujin).
comment