Skip to content

Commit c97a16d

Browse files
authored
Merge pull request #32 from cyberark/conjurinc-ops-568
Add bl_validate_changelog
2 parents 347e997 + 3a72823 commit c97a16d

File tree

7 files changed

+84
-6
lines changed

7 files changed

+84
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.0.3] - 2020-03-13
10+
### Added
11+
- bl_validate_changelog: Validate a changelog against keepachangelog.com format.
12+
13+
### Changed
14+
- bl_in_git_repo now fails (return 1) rather than exiting 1
15+
- Github issues can now be created with a label
16+
917
## [2.0.2] - 2020-03-10
1018
### Added
1119
- Retrieve latest version for gem from rubygems.org

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ files within it's directory.
195195
</td>
196196
</tr>
197197
<tr>
198-
<td><a href="test-utils/ruby">Ruby</a></td>
198+
<td><a href="ruby/lib">Ruby</a></td>
199199
<td>Helpers related to ruby infrastructure</td>
200200
<td>
201201
<ol>
@@ -213,6 +213,7 @@ files within it's directory.
213213
<li><b>bl_shellcheck_script</b>: Execute shellcheck against a script, uses docker.</li>
214214
<li><b>bl_find_scripts</b>: Find git tracked files with extension.</li>
215215
<li><b>bl_tap2junit</b>: Convert a subset of <a href="http://testanything.org/">TAP</a> to JUnit XML. Retains logs for errors.</li>
216+
<li><b>bl_validate_changelog</b>: Check CHANGELOG.md (or a specified file) complies with keepachangelog.com format. </li>
216217
</ol>
217218
</td>
218219
</tr>

git/lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function bl_git_available(){
99

1010
function bl_in_git_repo(){
1111
bl_git_available
12-
git status >/dev/null || bl_die "$(pwd) is not within a git repo."
12+
git status >/dev/null || bl_fail "$(pwd) is not within a git repo."
1313
}
1414

1515
function bl_github_owner_repo(){

run-tests

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
. "$(dirname ${BASH_SOURCE[0]})/init"
77

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

1411
bl_info "Running BATS Tests"
1512
"${BASH_LIB_DIR}/tests-for-this-repo/run-bats-tests"

test-utils/lib

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,41 @@ function bl_tap2junit(){
4848
# filters stdin to stdout
4949
docker run --rm -i tap-junit -s "${suite}"
5050
}
51+
52+
# Checks a Changelog file against keepachangelog.com format.
53+
function bl_validate_changelog(){
54+
local CHANGELOG=""
55+
56+
if [[ -z "${1:-}" ]]; then
57+
# Changelog file not specified
58+
59+
# Look in the current directory
60+
if [[ -r CHANGELOG.md ]]; then
61+
CHANGELOG="CHANGELOG.md"
62+
fi
63+
64+
# Look in the repo root
65+
if [[ -z "${CHANGELOG}" ]] && bl_in_git_repo; then
66+
guess="$(bl_repo_root)/CHANGELOG.md"
67+
[[ -r "${guess}" ]] && CHANGELOG="${guess}"
68+
fi
69+
70+
if [[ -z "${CHANGELOG}" ]]; then
71+
bl_fail "CHANGELOG.md not found in current directory or root of git "\
72+
"repo, please specify the path to the changelog. " \
73+
"Usage: bl_validate_changelog /path/to/CHANGELOG.md"
74+
fi
75+
else
76+
# Changelog specified as parameter, use that.
77+
CHANGELOG="${1}"
78+
[[ -r "${CHANGELOG}" ]] || bl_fail "Can't read changelog file: ${CHANGELOG}"
79+
fi
80+
81+
# Docker volume paths need to be absolute
82+
CHANGELOG="$(bl_abs_path "${CHANGELOG}")"
83+
84+
docker run \
85+
--rm \
86+
--volume "${CHANGELOG}:/CHANGELOG.md" \
87+
cyberark/parse-a-changelog
88+
}

tests-for-this-repo/test-utils.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,32 @@ bl_docker_safe_tmp(){
7676
assert_equal "${stdout}" "$(cat ${fdir}/tap2junit.out)"
7777
assert_equal "${rc}" "0"
7878
}
79+
80+
@test "bl_validate_changelog validates changelog specified as paremeter" {
81+
run bl_validate_changelog "${BASH_LIB_DIR}"/CHANGELOG.md
82+
assert_success
83+
}
84+
85+
@test "bl_validate_changelog finds changelog in current directory" {
86+
pushd "${BASH_LIB_DIR}"
87+
run bl_validate_changelog
88+
popd
89+
assert_success
90+
}
91+
92+
@test "bl_validate_changelog finds changelog in git root" {
93+
pushd "${BASH_LIB_DIR}/tests-for-this-repo"
94+
run bl_validate_changelog
95+
popd
96+
assert_success
97+
}
98+
99+
@test "bl_validate_changelog fails with invalid changelog path" {
100+
run bl_validate_changelog notavalidchangelog.md
101+
assert_failure
102+
}
103+
104+
@test "bl_validate_changelog fails with invalid changelog" {
105+
run bl_validate_changelog README.md
106+
assert_failure
107+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
. "$(dirname "${BASH_SOURCE[0]}")/../init"
4+
5+
bl_validate_changelog

0 commit comments

Comments
 (0)