Skip to content

Commit

Permalink
fix: beafed up tests for versions, made version file configurables an…
Browse files Browse the repository at this point in the history
…d added option for whether to snapshot on bump
  • Loading branch information
basejump committed Jul 21, 2021
1 parent f6e7131 commit 391835c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/semver
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function bump_version_file {
local publishingVersion="${1}"
local newVersion=$( bump_patch $publishingVersion)
local versionFile=${2:-version.properties}
updateVersionFile $newVersion $publishingVersion $versionFile $3
updateVersionFile $newVersion $publishingVersion $versionFile "${3}"
}

# Updates version.properties with given version, sets publishedVersion to the $VERSION
Expand Down
17 changes: 12 additions & 5 deletions makefiles/release.make
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ github_release := $(SHIPKIT_BIN)/github_release
semver := $(SHIPKIT_BIN)/semver
changelog := $(SHIPKIT_BIN)/changelog

VERSION_FILENAME ?= version.properties
VERSION_SET_SNAPSHOT ?= false

shipkit:
version:
filename:

update-changelog: | _verify_VERSION _verify_PUBLISHED_VERSION _verify_RELEASE_CHANGELOG _verify_PROJECT_FULLNAME
$(changelog) update_changelog $(VERSION) $(PUBLISHED_VERSION) $(RELEASE_CHANGELOG) $(PROJECT_FULLNAME)
$(changelog) update_changelog "$(VERSION)" "$(PUBLISHED_VERSION)" "$(RELEASE_CHANGELOG)" "$(PROJECT_FULLNAME)"
echo "update-changelog success"

update-readme-version: | _verify_VERSION
$(semver) replace_version "$(VERSION)" README.md
echo "update-readme-version success"

bump-version-props: | _verify_VERSION
$(semver) bump_version_file "$(VERSION)" version.properties
echo "bump-version-props success"
bump-version-file: | _verify_VERSION
$(semver) bump_version_file "$(VERSION)" "$(VERSION_FILENAME)" "$(VERSION_SET_SNAPSHOT)"
echo "bump-version-file success on $(VERSION_FILENAME) for v:$(VERSION)"

# updates change log, bumps version, updates the publishingVersion in README
push-version-bumps:
Expand All @@ -39,7 +46,7 @@ create-github-release: | _verify_VERSION _verify_RELEASABLE_BRANCH _verify_PROJE
$(github_release) create_github_release $(VERSION) $(RELEASABLE_BRANCH) $(PROJECT_FULLNAME) $(GITHUB_TOKEN)
echo "create-github-release success"

semantic-release: update-changelog update-readme-version bump-version-props create-github-release push-version-bumps
semantic-release: update-changelog update-readme-version bump-version-file create-github-release push-version-bumps
echo "Releasable ... doing version bump, changelog and tag push"

endif # end RELEASABLE_BRANCH
4 changes: 1 addition & 3 deletions tests/fixtures/versions/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include Shipkit.make
include makefiles/secrets.make
include makefiles/release.make

version-cd-dir:
cd build && $(GIT_SECRET_SH) --version
3 changes: 0 additions & 3 deletions tests/fixtures/versions/bin/gpg

This file was deleted.

28 changes: 28 additions & 0 deletions tests/semver.bats
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bats
source "$SHIPKIT_BIN/semver"
load test_helper

setup() {
export FIXTURE_DIR="$BATS_TEST_DIRNAME/fixtures/versions"
export VERSION_FILENAME=build/semver_tests/version.env
export VERSION_SET_SNAPSHOT=true
}

@test 'bump_patch' {
version=$(bump_patch "1.2.3 ")
Expand Down Expand Up @@ -27,3 +34,24 @@ source "$SHIPKIT_BIN/semver"
grep "snapshot=true" $semverFile

}

@test 'make sure git-secret-version works' {

semverFile=$VERSION_FILENAME
echo "version=1.0.1" > $semverFile
echo "publishedVersion=1.0.0" >> $semverFile
echo "snapshot=false" >> $semverFile

grep "version=1.0.1" $semverFile
grep "publishedVersion=1.0.0" $semverFile
grep "snapshot=false" $semverFile

run make -f $FIXTURE_DIR/Makefile bump-version-file VERSION=1.0.1
__debug "${status}" "${output}" "${lines[@]}"

[ "$status" -eq 0 ]
grep "version=1.0.2" $semverFile
grep "publishedVersion=1.0.1" $semverFile
grep "snapshot=true" $semverFile
# [ "${lines[0]}" == "tests/fixtures/bin/curl \"http://localhost\" | cat -" ]
}

0 comments on commit 391835c

Please sign in to comment.