Skip to content

Commit

Permalink
fix: minor bump resets patch
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtabrams committed May 29, 2020
1 parent 98b805e commit 42c4966
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
27 changes: 15 additions & 12 deletions change
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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; }

Expand All @@ -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"

0 comments on commit 42c4966

Please sign in to comment.