diff --git a/.gitignore b/.gitignore index f12e324..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,52 +0,0 @@ -*.pyc -*.pyo -*.class -*~ -*# -/doc/generated/* -/runpy -/build -*.py[cod] - -# C extensions -*.so - -# Packages -*.egg -*.egg-info -dist -build -eggs -parts -var -sdist -develop-eggs -.installed.cfg -lib -lib64 - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox -nosetests.xml -htmlcov - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Complexity -output/*.html -output/*/index.html - -# Sphinx -docs/_build - -/venv diff --git a/.travis.yml b/.travis.yml index 9d0b5fe..cda50e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,21 @@ -language: python - -python: - - "2.6" - - "2.7" - - "3.3" - - "3.4" - - "pypy" +language: bash before_install: - - git config --global user.email "you@example.com" - - git config --global user.name "Your Name" +- sudo add-apt-repository ppa:duggan/bats --yes +- sudo apt-get update -qq +- sudo apt-get install -qq bats +- git config --global user.email "you@example.com" +- git config --global user.name "Your Name" + +script: +- make test -script: make test +deploy: + provider: releases + api_key: + secure: IFO/IqsxE2ZF1oLIWQkr7VE6yTQtbG6vea/4+zgMrknWxjkfVproj25rSgsxL3Wxln03ubOqaG50d01hDmgWoaRz3sG3wV9mMn7EjXz9+M6MBCzv940VDYzBhZUaW225Sw7SDdZIA7bsgMrvkmlhK8tZg7Ow7pcYoeRmyDrehCE= + file: chag + on: + repo: mtdowling/chag + tags: true + all_branches: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f76e80..c793f2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,10 @@ ## 1.0.0 - 2014-10-26 * Using the format from http://keepachangelog.com -* Trimming down the feature set and switching back to bash. This makes chag - much simpler to install and does not require any dependencies. +* Trimming down the feature set and switching back to bash instead of Python. + This makes chag much simpler to install and does not require any + dependencies. +* Simplified by removing `chag new`, `chag append`, and `chag get`. ## 0.5.0 - 2014-08-16 diff --git a/Makefile b/Makefile index c92a1ac..3bb7fa2 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ -tag: - ./chag tag --sign --debug CHANGELOG.rst latest - test: bats test/ deploy: tag + git push origin master git push origin --tags .PHONY: test diff --git a/chag b/chag index 8a29dd5..0da156b 100755 --- a/chag +++ b/chag @@ -13,7 +13,7 @@ unset COMMAND FILENAME TAG SIGN FORCE ADDV NOTRIM HEADING_START='## .+' version() { - echo "chag 0.6.0" + echo "chag 1.0.0" } usage() { @@ -196,9 +196,9 @@ parse_options() { # Gets the contents of a changelog entry contents() { if [ -z "$NOTRIM" ]; then - get_trimmed_entry "$TAG" + get_trimmed_entry "$TAG" || exit $? else - get_changelog_entry "$TAG" + get_changelog_entry "$TAG" || exit $? fi } @@ -206,7 +206,7 @@ tag() { `git diff --quiet HEAD` || die 'Working directory not clean' TAG=$(latest) contents_cmd="get_trimmed_entry" - (entries | grep -q $TAG) || die "[FAILURE] $TAG not found in $FILENAME" + (entries | grep -q $TAG) || die "[FAILURE] $TAG not found" if [ "$TAG" == "Unreleased" ]; then die 'Not tagging an Unreleased tag. Please check your changelog file.' @@ -229,7 +229,7 @@ tag() { debug "Running git command: $cmd" fi - (contents_cmd | $cmd) || die "[FAILURE] Failed tagging $real_tag" + ($contents_cmd | $cmd) || die "[FAILURE] Failed tagging $real_tag" echo "[SUCCESS] Tagged $real_tag" } @@ -238,7 +238,7 @@ update() { start=$(find_first_entry) local replacement="## $TAG - $(date +%Y-%m-%d)" perl -i -pe "s/.*/$replacement/ if \$.==${start}" $FILENAME - echo "[SUCCESS] Updated ${FILENAME} with $replacement" + echo "[SUCCESS] Updated ${FILENAME} with ${TAG}" } # Get a list of entry versions separated by newlines @@ -246,6 +246,16 @@ entries() { entries_and_lines | cut -d ':' -f 2 } +# Prints each heading "line_number:line" from the changelog separated w/ "\n" +entries_and_lines() { + local pattern="^($HEADING_START)" + # Find each entry line number and version, separated by colons. + grep -n -E -e "$pattern" $FILENAME \ + | sed -E 's/## //' \ + | cut -d '-' -f 1 \ + | sed -e 's/^ *//' -e 's/ *$//' +} + # Gets the latest version number from the changelog latest() { entries | head -n1 | cut -d ':' -f 1 @@ -270,7 +280,7 @@ get_changelog_entry() { fi # Ensure that the heading was found - [ "$found_line" == "" ] && die "Tag not found in $FILENAME" + [ "$found_line" == "" ] && die "[FAILURE] Tag not found" # First line in the file of the changelog header. local start_line=$(($found_line + 1)) # Find the length of the section @@ -294,16 +304,8 @@ get_changelog_entry() { # Gets a trimmed changelog entry get_trimmed_entry() { get_changelog_entry "$1" | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' -} - -# Prints each heading "line_number:line" from the changelog separated w/ "\n" -entries_and_lines() { - local pattern="^($HEADING_START)" - # Find each entry line number and version, separated by colons. - grep -n -E -e "$pattern" $FILENAME \ - | sed -E 's/## //' \ - | cut -d '-' -f 1 \ - | sed -e 's/^ *//' -e 's/ *$//' + # PIPESTATUS tells us the exit status of each command in the previous pipe. + [ ${PIPESTATUS[0]} -eq 0 ] || exit 1 } main "$@" diff --git a/test/contents.bats b/test/contents.bats index cee2ca5..50dd4da 100644 --- a/test/contents.bats +++ b/test/contents.bats @@ -25,7 +25,7 @@ load test_helper run ./chag contents --file $CHNGFILE --tag 9.9.9 delete_changelog [ $status -eq 1 ] - [ $(expr "${lines[0]}" : "Tag 9.9.9 not found") -ne 0 ] + [ "${lines[0]}" == "[FAILURE] Tag not found" ] } @test "contents can contents a tag" { diff --git a/test/latest.bats b/test/latest.bats index 4cdbbb8..b3be597 100644 --- a/test/latest.bats +++ b/test/latest.bats @@ -14,12 +14,6 @@ load test_helper [ $(expr "${lines[0]}" : "Unknown option") -ne 0 ] } -@test "latest requires a FILENAME" { - run ./chag latest - [ $status -eq 1 ] - [ $(expr "${lines[0]}" : ".* latest requires a FILENAME") -ne 0 ] -} - @test "latest shows latest tag" { setup_changelog run ./chag latest --file $CHNGFILE diff --git a/test/tag.bats b/test/tag.bats index 0723f0a..8a56ef9 100644 --- a/test/tag.bats +++ b/test/tag.bats @@ -22,27 +22,15 @@ chagcmd="$BATS_TEST_DIRNAME/../chag" [ $(expr "${lines[0]}" : "File not found: /path/to/does/not/exist") -ne 0 ] } -@test "Tags with annotation and specific tag" { - setup_repo - run $chagcmd tag --addv --file CHANGELOG.rst - [ $status -eq 0 ] - [ "${lines[0]}" == '[SUCCESS] Tagged v0.0.1' ] - run git tag -l -n1 v0.0.1 - cd - - [ $status -eq 0 ] - [ "${lines[0]}" == 'v0.0.1 * Initial release.' ] - delete_repo -} - @test "Tags debug output" { setup_repo - run $chagcmd tag --debug --file CHANGELOG.rst + run $chagcmd tag --debug --file CHANGELOG.md [ $status -eq 0 ] [ "${lines[0]}" == 'Tagging 0.0.2 with the following annotation:' ] [ "${lines[1]}" == '===[ BEGIN ]===' ] [ "${lines[2]}" == '* Correcting ``--debug`` description.' ] [ "${lines[3]}" == '===[ END ]===' ] - [ "${lines[4]}" == 'Running git command: git tag -a -F - 0.0.2' ] + [ "${lines[4]}" == 'Running git command: git tag -a -F - 0.0.2' ] [ "${lines[5]}" == '[SUCCESS] Tagged 0.0.2' ] run git tag -l -n1 0.0.2 cd - @@ -53,9 +41,9 @@ chagcmd="$BATS_TEST_DIRNAME/../chag" @test "Can force a tag" { setup_repo - run $chagcmd tag CHANGELOG.rst 0.0.2 + run $chagcmd tag CHANGELOG.md 0.0.2 [ $status -eq 0 ] - run $chagcmd tag --force --file CHANGELOG.rst --tag 0.0.2 + run $chagcmd tag --force --file CHANGELOG.md --tag 0.0.2 [ $status -eq 0 ] [ "${lines[0]}" == '[SUCCESS] Tagged 0.0.2' ] cd - diff --git a/test/test_helper.bash b/test/test_helper.bash index 7ccb8d8..3015b61 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -5,7 +5,7 @@ CHAGREPO="$BATS_TMPDIR/chag-test" # Creates a test fixure changelog setup_changelog() { - tail -9 CHANGELOG.rst > $CHNGFILE + tail -9 CHANGELOG.md > $CHNGFILE } # Creates a test fixure changelog that has a TBD entry @@ -14,7 +14,7 @@ setup_changelog_tbd() { printf "Next Release (TBD)\n" >> $CHNGFILE echo "------------------" >> $CHNGFILE printf "\nHello!\n\n" >> $CHNGFILE - tail -9 CHANGELOG.rst >> $CHNGFILE + tail -9 CHANGELOG.md >> $CHNGFILE } # Deletes the test fixture changelog @@ -32,7 +32,7 @@ setup_repo() { delete_repo # Create new git repo mkdir -p $CHAGREPO - tail -9 CHANGELOG.rst > $CHAGREPO/CHANGELOG.rst + tail -9 CHANGELOG.md > $CHAGREPO/CHANGELOG.md cd $CHAGREPO git init && git add -A && git commit -m 'Initial commit' } diff --git a/test/update.bats b/test/update.bats index 9876120..92bae7e 100644 --- a/test/update.bats +++ b/test/update.bats @@ -28,9 +28,9 @@ load test_helper @test "updates inline" { setup_changelog_tbd - run ./chag update --file $CHNGFILE --tag 9.9.9 + run ./chag update --file $CHNGFILE 9.9.9 delete_changelog [ $status -eq 0 ] date=$(date +%Y-%m-%d) - [ "${lines[0]}" == "[SUCCESS] Updated ${CHNGFILE} with ## 9.9.9 - $date" ] + [ "${lines[0]}" == "[SUCCESS] Updated ${CHNGFILE} with 9.9.9" ] }