From 42c496639b21d88f51dd3173029457162853067d Mon Sep 17 00:00:00 2001 From: Adam Abrams Date: Fri, 29 May 2020 09:08:46 -0500 Subject: [PATCH] fix: minor bump resets patch --- CHANGELOG.md | 11 ++++++++--- README.md | 19 ++++++++++++++++++- change | 27 +++++++++++++++------------ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df780be..8ceedcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.5.1] - 2020-05-29 +## [0.5.0] - 2020-05-29 ### Added - Use GitHub personal access token for auth. +- Can now tag and push most version in changelog. + +### Fixed +- Major and minor version bump weren't resetting minor and patch. ### Changed - Changed `release` command to `post`. +- Changed `-t` command to `tag`. ## [0.4.1] - 2020-05-28 ### Fixed @@ -43,8 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Created a proof of concept for a changelog updater. -[Unreleased]: https://github.com/adamtabrams/change/compare/0.5.1...HEAD -[0.5.1]: https://github.com/adamtabrams/change/compare/0.4.1...0.5.1 +[Unreleased]: https://github.com/adamtabrams/change/compare/0.5.0...HEAD +[0.5.0]: https://github.com/adamtabrams/change/compare/0.4.1...0.5.0 [0.4.1]: https://github.com/adamtabrams/change/compare/0.4.0...0.4.1 [0.4.0]: https://github.com/adamtabrams/change/compare/0.3.0...0.4.0 [0.3.0]: https://github.com/adamtabrams/change/compare/0.2.0...0.3.0 diff --git a/README.md b/README.md index 4ad8fd6..9a27abd 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,31 @@ So it's better to let `change` generate one. You can transfer existing messages * `change` can add multiple versions to your changelog, but those version tags need to already exist. Otherwise everything since the last version tag is assumed to be for the next version. * `change` will figure out what your next version should be from based on your commits and will add that to the changelog as well. -* By default `change` won't tag the lastest commit with the version it calculated, but it will if you use the `-t` flag. #### Fill in the details * You should validate what was generated and add detail everywhere it's needed. +#### Tag the latest commit with `change tag` +* This looks at the latest version recorded in the changelog. +Then it tags the latest commit with that version and pushes the tag to origin. + #### Save a token with `change auth` * This saves a personal access token for posting releases. * Here are [instructions](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token) for making one. #### Post a release to GitHub with `change post` * This posts the section of the latest version in the changelog as a GitHub release. + + +## Workflow + +This is the general workflow I use with this tool: +* make changes to your project +* record those changes in commits + * smaller, more focused commits will help when generating the changelog +* run `change` +* improve the new section of the changelog +* ammend the revised changelog to the last commit with `git commit --amend` +* run `change tag` +* push to origin +* run `change post` diff --git a/change b/change index bf76b70..eaee752 100755 --- a/change +++ b/change @@ -13,9 +13,9 @@ usage() { echo "change" echo " updates an existing $change_file" echo "" - echo "change -t" - echo " same as change, but tags the latest commit with" - echo " the new version and pushes that tag to origin" + echo "change tag" + echo " tags the latest commit with the lastest version" + echo " in $change_file and pushes that tag to origin" echo "" echo "change init" echo " creates a $change_file with the first version" @@ -97,12 +97,14 @@ get_new_version_name() { increment_major() { cur_major=$(echo "$1" | sed "s|^[^[:digit:]]*\([[:digit:]]*\)\..*$|\1|") - echo "$1" | sed "s|\(^[^[:digit:]]*\)[[:digit:]]*\(\..*$\)|\1$(( cur_major + 1 ))\2|" + echo "$1" | sed "s|\.[[:digit:]]*|.0|g" | + sed "s|\(^[^[:digit:]]*\)[[:digit:]]*\(\..*$\)|\1$(( cur_major + 1 ))\2|" } increment_minor() { cur_minor=$(echo "$1" | sed "s|^.*\.\([[:digit:]]*\)\..*$|\1|") - echo "$1" | sed "s|\(^.*\.\)[[:digit:]]*\(\..*$\)|\1$(( cur_minor + 1 ))\2|" + echo "$1" | sed "s|\.[[:digit:]]*|.0|g" | + sed "s|\(^.*\.\)[[:digit:]]*\(\..*$\)|\1$(( cur_minor + 1 ))\2|" } increment_patch() { @@ -158,7 +160,12 @@ get_commits_between() { } make_and_push_tag() { - git tag "$1" && git push origin "$1" + latest_log_ver_name=$(sed -n "s|^\[Unreleased\]:.*/\(.*\)\.\.\.HEAD$|\1|p" $change_file) + + git tag "$latest_log_ver_name" && + git push origin "$latest_log_ver_name" && + echo "tagged latest commit as $latest_log_ver_name" && + echo "and pushed tag to origin" } auth() { @@ -223,12 +230,13 @@ $(format_commits "$first_commits") [ "$2" ] && { echo "change currently accepts only one argument" >&2; exit 1; } [ "$1" = "init" ] && { init; exit; } +[ "$1" = "tag" ] && { make_and_push_tag; exit; } [ "$1" = "auth" ] && { auth; exit; } [ "$1" = "post" ] && { post_release; exit; } [ "$1" = "-h" ] && { usage; exit; } [ "$1" = "help" ] && { usage; exit; } [ "$1" = "--help" ] && { usage; exit; } -[ "$1" != "-t" ] && { printf "couldn't recognize argument\n\n" >&2; usage >&2; exit 1; } +[ "$1" ] && { printf "couldn't recognize argument\n\n" >&2; usage >&2; exit 1; } [ ! -e "$change_file" ] && { echo "couldn't find $change_file" >&2; exit 1; } @@ -246,8 +254,3 @@ for needed_log_ver_name in $needed_log_ver_names; do latest_log_ver_name="$needed_log_ver_name" done - -[ "$1" = "-t" ] && - make_and_push_tag "$latest_log_ver_name" && - echo "tagged latest commit as $latest_log_ver_name" && - echo "and pushed tags to origin"