Package: auto-tag
Auto-TagAutomatically tag a branch with the next semantic version tag.This is useful if you want to generate tags every time something is merged.
Microservice and GitOps repository are good candidates for this type of action.TOCInstallHow it WorksExampelsDetectorsGit AuthorHow to install~$pipinstallauto-tagTo see if it works, you can try~$auto-tag-h
usage:auto-tag[-h][-bBRANCH][-rREPO][-u[UPSTREAM_REMOTE[UPSTREAM_REMOTE...]]][-l{CRITICAL,FATAL,ERROR,WARN,WARNING,INFO,DEBUG,NOTSET}][--nameNAME][--emailEMAIL][-cCONFIG][--skip-tag-if-one-already-present][--append-v-to-tag][--tag-search-strategy{biggest-tag-in-repo,biggest-tag-in-branch,latest-tag-in-repo,latest-tag-in-branch}].....How it WorksThe flow is as follows:figure our repository based on the argumentload detectors from file if specified (-coption), if none specified load default ones (seeDetectors)check for the last tag (depending on the search strategy seeSearch Strategylook at all commits done after that tag on a specific branch (or from the start of the repository if no tag is found)apply the detector (seeDetectors) on each commit and save the highest change detected (PATH, MINOR, MAJOR)bump the last tag with the approbate change  and apply it using the default git author in the system or a specific one (seeGit Author)if an upstream was specified push the tag to that upstreamExamplesHere we can see in commit2245d5dthat it stats withfeature(so the latest know tag (0.2.1) was bumped to0.3.0~ $ git log --oneline
2245d5d (HEAD -> master) feature(component) commit #4
939322f commit #3
9ef3be6 (tag: 0.2.1) commit #2
0ee81b0 commit #1
~ $ auto-tag
2019-08-31 14:10:24,626: Start tagging <git.Repo "/Users/matei/git/test-auto-tag-branch/.git">
2019-08-31 14:10:24,649: Bumping tag 0.2.1 -> 0.3.0
2019-08-31 14:10:24,658: No push remote was specified
~ $ git log --oneline
2245d5d (HEAD -> master, tag: 0.3.0) feature(component) commit #4
939322f commit #3
9ef3be6 (tag: 0.2.1) commit #2
0ee81b0 commit #1In this example we can see2245d5deb5d97d288b7926be62d051b7eed35c98introducing a feature that will trigger a MINOR change but we can also see0de444695e3208b74d0b3ed7fd20fd0be4b2992ehaving aBREAKING_CHANGEthat will introduce a MAJOR bump, this is the reason the tag moved from0.2.1to1.0.0~ $ git log
commit 0de444695e3208b74d0b3ed7fd20fd0be4b2992e (HEAD -> master)
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 21:58:01 2019 +0300

    fix(something) ....

    BREAKING_CHANGE: this must trigger major version bump

commit 65bf4b17669ea52f84fd1dfa4e4feadbc299a80e
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 21:57:47 2019 +0300

    fix(something) ....

commit 2245d5deb5d97d288b7926be62d051b7eed35c98
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:52:10 2019 +0300

    feature(component) commit #4

commit 939322f1efaa1c07b7ed33f2923526f327975cfc
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:51:24 2019 +0300

    commit #3

commit 9ef3be64c803d7d8d3b80596485eac18e80cb89d (tag: 0.2.1)
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:51:18 2019 +0300

    commit #2

commit 0ee81b0bed209941720ee602f76341bcb115b87d
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:50:25 2019 +0300

    commit #1
~ $ auto-tag
2019-08-31 14:10:24,626: Start tagging <git.Repo "/Users/matei/git/test-auto-tag-branch/.git">
2019-08-31 14:10:24,649: Bumping tag 0.2.1 -> 1.0.0
2019-08-31 14:10:24,658: No push remote was specified
~ $ git log
commit 0de444695e3208b74d0b3ed7fd20fd0be4b2992e (HEAD -> master, tag: 1.0.0)
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 21:58:01 2019 +0300

    fix(something) ....

    BREAKING_CHANGE: this must trigger major version bump

commit 65bf4b17669ea52f84fd1dfa4e4feadbc299a80e
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 21:57:47 2019 +0300

    fix(something) ....

commit 2245d5deb5d97d288b7926be62d051b7eed35c98
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:52:10 2019 +0300

    feature(component) commit #4

commit 939322f1efaa1c07b7ed33f2923526f327975cfc
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:51:24 2019 +0300

    commit #3

commit 9ef3be64c803d7d8d3b80596485eac18e80cb89d (tag: 0.2.1)
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:51:18 2019 +0300

    commit #2

commit 0ee81b0bed209941720ee602f76341bcb115b87d
Author: Matei-Marius Micu <micumatei@gmail.com>
Date:   Fri Aug 30 19:50:25 2019 +0300

    commit #1DetectorsIf you want to detect what commit enforces a specific tag bump(PATH, MINOR, MAJOR) you can configure detectors.
They are configured in a yaml file that looks like this:detectors:check_for_feature_heading:type:CommitMessageHeadStartsWithDetectorproduce_type_change:MINORparams:pattern:'feature'check_for_breaking_change:type:CommitMessageContainsDetectorproduce_type_change:MAJORparams:pattern:'BREAKING_CHANGE'case_sensitive:falseHere is the default configuration for detectors if none is specified.
We can see we have two detectorscheck_for_feature_headingandcheck_for_breaking_change, with a type, what change they will trigger and specific parameters for each one.
This configuration will do the following:if the commit message  starts withfeature(a MINOR change will BE triggeredif the commit hasBREAKIN_CHANGEin the message a MAJOR change will be triggered
The bump on the tag will be based on the higher priority found.Thetypeandproduce_type_changeparameters are requiredparamsis specific to every detector.To pass the file to the process just use the-cCLI parameter.Currently we support the following triggers:CommitMessageHeadStartsWithDetectorParameters:case_sensitiveof typebool, if the comparison is case sensitivestripof typebool, if we strip the spaces from the commit messagepatternof typestring, what pattern is searched at the start of the commit messageCommitMessageContainsDetectorcase_sensitiveof typebool, if the comparison is case sensitivestripof typebool, if we strip the spaces from the commit messagepatternof typestring, what pattern is searched in the body of the commit messageCommitMessageMatchesRegexDetectorstripof typebool, if we strip the spaces from the commit messagepatternof typestring, what regex pattern to match against the commit messageThe regex detector is the most powerful one.Git AuthorWhen creating and tag we need to specify a git author, if a global one is not set (or if we want to make this one with a specific user), we have the option to specify one.
The following options will add a temporary config to this repository(local config). After the tag was created it will restore the existing config (if any was present)--name NAME           User name used for creating git objects.If not
                        specified the system one will be used.
  --email EMAIL         Email name used for creating git objects.If not
                        specified the system one will be used.If another user interacts with git while this process is taking place it will use the temporary config, but we assume we are run in a CI pipeline and this is the only process interacting with git.Search StrategyIf you want to bump a tag first you need to find the last one, we have a few  implementations to search for the last tag that can be configured with--tag-search-strategyCLI option.biggest-tag-in-repoconsider all tagsin the repositoryas semantic versions and pick the biggest onebiggest-tag-in-branchconsider all tagson the specified branchas semantic versions and pick the biggest onelatest-tag-in-repocomparecommit datefor each commit that has a tagin the repositoryand take the latestlatest-tag-in-branchcomparecommit datefor each commit that has a tagone the specifid branchand take the latestThis project is licensed under the terms of the MIT license.