Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating pre-release tags from last stable tag #14

Merged
merged 1 commit into from
Jul 6, 2017

Conversation

theckman
Copy link
Contributor

@theckman theckman commented Jul 6, 2017

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.

Signed-off-by: Tim Heckman t@heckman.io


This change is Reviewable

@theckman theckman force-pushed the prerelease-tags branch 12 times, most recently from e81e0e7 to ab8f83d Compare July 6, 2017 09:57
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.

Signed-off-by: Tim Heckman <t@heckman.io>
@spheromak spheromak merged commit 1c4d976 into autotag-dev:master Jul 6, 2017
@spheromak
Copy link
Member

thanks @theckman

@theckman theckman deleted the prerelease-tags branch July 6, 2017 21:04
@theckman
Copy link
Contributor Author

theckman commented Jul 6, 2017

@spheromak my pleasure, thank you for the quick review/merge as well as making this codebase easy to extend (you too @fujin).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants