Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.3] - 2020-03-13
### Added
- bl_validate_changelog: Validate a changelog against keepachangelog.com format.

### Changed
- bl_in_git_repo now fails (return 1) rather than exiting 1
- Github issues can now be created with a label

## [2.0.2] - 2020-03-10
### Added
- Retrieve latest version for gem from rubygems.org
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ files within it's directory.
</td>
</tr>
<tr>
<td><a href="test-utils/ruby">Ruby</a></td>
<td><a href="ruby/lib">Ruby</a></td>
<td>Helpers related to ruby infrastructure</td>
<td>
<ol>
Expand All @@ -213,6 +213,7 @@ files within it's directory.
<li><b>bl_shellcheck_script</b>: Execute shellcheck against a script, uses docker.</li>
<li><b>bl_find_scripts</b>: Find git tracked files with extension.</li>
<li><b>bl_tap2junit</b>: Convert a subset of <a href="http://testanything.org/">TAP</a> to JUnit XML. Retains logs for errors.</li>
<li><b>bl_validate_changelog</b>: Check CHANGELOG.md (or a specified file) complies with keepachangelog.com format. </li>
</ol>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion git/lib
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function bl_git_available(){

function bl_in_git_repo(){
bl_git_available
git status >/dev/null || bl_die "$(pwd) is not within a git repo."
git status >/dev/null || bl_fail "$(pwd) is not within a git repo."
}

function bl_github_owner_repo(){
Expand Down
5 changes: 1 addition & 4 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
. "$(dirname ${BASH_SOURCE[0]})/init"

bl_info "Checking the changelog complies with keepachangelog.com format"
docker run \
--rm \
-v "${PWD}/CHANGELOG.md:/CHANGELOG.md" \
cyberark/parse-a-changelog
"${BASH_LIB_DIR}/tests-for-this-repo/validate-changelog"

bl_info "Running BATS Tests"
"${BASH_LIB_DIR}/tests-for-this-repo/run-bats-tests"
Expand Down
38 changes: 38 additions & 0 deletions test-utils/lib
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,41 @@ function bl_tap2junit(){
# filters stdin to stdout
docker run --rm -i tap-junit -s "${suite}"
}

# Checks a Changelog file against keepachangelog.com format.
function bl_validate_changelog(){
local CHANGELOG=""

if [[ -z "${1:-}" ]]; then
# Changelog file not specified

# Look in the current directory
if [[ -r CHANGELOG.md ]]; then
CHANGELOG="CHANGELOG.md"
fi

# Look in the repo root
if [[ -z "${CHANGELOG}" ]] && bl_in_git_repo; then
guess="$(bl_repo_root)/CHANGELOG.md"
[[ -r "${guess}" ]] && CHANGELOG="${guess}"
fi

if [[ -z "${CHANGELOG}" ]]; then
bl_fail "CHANGELOG.md not found in current directory or root of git "\
"repo, please specify the path to the changelog. " \
"Usage: bl_validate_changelog /path/to/CHANGELOG.md"
fi
else
# Changelog specified as parameter, use that.
CHANGELOG="${1}"
[[ -r "${CHANGELOG}" ]] || bl_fail "Can't read changelog file: ${CHANGELOG}"
fi

# Docker volume paths need to be absolute
CHANGELOG="$(bl_abs_path "${CHANGELOG}")"

docker run \
--rm \
--volume "${CHANGELOG}:/CHANGELOG.md" \
cyberark/parse-a-changelog
}
29 changes: 29 additions & 0 deletions tests-for-this-repo/test-utils.bats
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,32 @@ bl_docker_safe_tmp(){
assert_equal "${stdout}" "$(cat ${fdir}/tap2junit.out)"
assert_equal "${rc}" "0"
}

@test "bl_validate_changelog validates changelog specified as paremeter" {
run bl_validate_changelog "${BASH_LIB_DIR}"/CHANGELOG.md
assert_success
}

@test "bl_validate_changelog finds changelog in current directory" {
pushd "${BASH_LIB_DIR}"
run bl_validate_changelog
popd
assert_success
}

@test "bl_validate_changelog finds changelog in git root" {
pushd "${BASH_LIB_DIR}/tests-for-this-repo"
run bl_validate_changelog
popd
assert_success
}

@test "bl_validate_changelog fails with invalid changelog path" {
run bl_validate_changelog notavalidchangelog.md
assert_failure
}

@test "bl_validate_changelog fails with invalid changelog" {
run bl_validate_changelog README.md
assert_failure
}
5 changes: 5 additions & 0 deletions tests-for-this-repo/validate-changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

. "$(dirname "${BASH_SOURCE[0]}")/../init"

bl_validate_changelog