Skip to content

Commit

Permalink
Merge pull request #34 from pantheon-systems/toggle-v-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
joemiller authored May 21, 2020
2 parents 9623602 + 01a58ab commit eeb731c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
11 changes: 10 additions & 1 deletion autotag.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
conventionalCommitRex = regexp.MustCompile(`^\s*(?P<type>\w+)(?P<scope>(?:\([^()\r\n]*\)|\()?(?P<breaking>!)?)(?P<subject>:.*)?`)

// versionRex matches semVer style versions, eg: `v1.0.0`
versionRex = regexp.MustCompile(`^v([\d]+\.?.*)`)
versionRex = regexp.MustCompile(`^v?([\d]+\.?.*)`)

// semVerBuildMetaRex validates SemVer build metadata strings according to
// https://semver.org/#spec-item-10
Expand Down Expand Up @@ -104,6 +104,9 @@ type GitRepoConfig struct {
// * "conventional" implements the Conventional Commits v1.0.0 scheme.
// * https://www.conventionalcommits.org/en/v1.0.0/#summary w
Scheme string

// Prefix prepends literal 'v' to the tag, eg: v1.0.0. Enabled by default
Prefix bool
}

// GitRepo represents a repository we want to run actions against
Expand All @@ -121,6 +124,8 @@ type GitRepo struct {
buildMetadata string

scheme string

prefix bool
}

// NewRepo is a constructor for a repo object, parsing the tags that exist
Expand Down Expand Up @@ -152,6 +157,7 @@ func NewRepo(cfg GitRepoConfig) (*GitRepo, error) {
preReleaseTimestampLayout: cfg.PreReleaseTimestampLayout,
buildMetadata: cfg.BuildMetadata,
scheme: cfg.Scheme,
prefix: cfg.Prefix,
}

err = r.parseTags()
Expand Down Expand Up @@ -412,6 +418,9 @@ func (r *GitRepo) AutoTag() error {
func (r *GitRepo) tagNewVersion() error {
// TODO:(jnelson) These should be configurable? Mon Sep 14 12:02:52 2015
tagName := fmt.Sprintf("v%s", r.newVersion.String())
if !r.prefix {
tagName = r.newVersion.String()
}

log.Println("Writing Tag", tagName)
err := r.repo.CreateTag(tagName, r.branchID)
Expand Down
2 changes: 2 additions & 0 deletions autotag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Options struct {
PreReleaseTimestamp string `short:"T" long:"pre-release-timestamp" description:"create a pre-release tag and append a timestamp (can be: datetime|epoch)"`
BuildMetadata string `short:"m" long:"build-metadata" description:"optional SemVer build metadata to append to the version with '+' character"`
Scheme string `short:"s" long:"scheme" description:"The commit message scheme to use (can be: autotag|conventional)" default:"autotag"`
NoVersionPrefix bool `short:"e" long:"empty-version-prefix" description:"Do not prepend v to version tag"`
}

var opts Options
Expand All @@ -45,6 +46,7 @@ func main() {
PreReleaseTimestampLayout: opts.PreReleaseTimestamp,
BuildMetadata: opts.BuildMetadata,
Scheme: opts.Scheme,
Prefix: !opts.NoVersionPrefix,
})
log.Println("FUCK1")

Expand Down
18 changes: 18 additions & 0 deletions autotag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type testRepoSetup struct {
// (optional) build metadata to append to the version
buildMetadata string

// (optional) prepend literal 'v' to version tags (default: true)
disablePrefix bool

// (optional) commit message to use for the next, untagged commit. Settings this allows for testing the
// commit message parsing logic. eg: "#major this is a major commit"
nextCommit string
Expand All @@ -61,6 +64,9 @@ func newTestRepo(t *testing.T, setup testRepoSetup) GitRepo {
tag := setup.initialTag
if setup.initialTag == "" {
tag = "v0.0.1"
if setup.disablePrefix {
tag = "0.0.1"
}
}
seedTestRepo(t, tag, repo)

Expand All @@ -81,6 +87,7 @@ func newTestRepo(t *testing.T, setup testRepoSetup) GitRepo {
PreReleaseTimestampLayout: setup.preReleaseTimestampLayout,
BuildMetadata: setup.buildMetadata,
Scheme: setup.scheme,
Prefix: !setup.disablePrefix,
})

if err != nil {
Expand Down Expand Up @@ -132,6 +139,7 @@ func TestValidateConfig(t *testing.T) {
PreReleaseName: "dev",
PreReleaseTimestampLayout: "epoch",
BuildMetadata: "g12345678",
Prefix: true,
},
shouldErr: false,
},
Expand Down Expand Up @@ -338,6 +346,16 @@ func TestAutoTag(t *testing.T) {
},
expectedTag: "v1.0.1+g012345678",
},
{
name: "autotag scheme, [major] bump without prefix",
setup: testRepoSetup{
scheme: "autotag",
nextCommit: "[major] this is a big release\n\nfoo bar baz\n",
initialTag: "1.0.0",
disablePrefix: true,
},
expectedTag: "2.0.0",
},
// tests for conventional commits scheme. Based on:
// https://www.conventionalcommits.org/en/v1.0.0/#summary
// and
Expand Down

0 comments on commit eeb731c

Please sign in to comment.