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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.2] - 2020-03-10
### Added
- Retrieve latest version for gem from rubygems.org

## [2.0.1] - 2020-02-19
### Added
- Github issue related functions via the `hub` cli
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ files within it's directory.
</ol>
</td>
</tr>
<tr>
<td><a href="test-utils/ruby">Ruby</a></td>
<td>Helpers related to ruby infrastructure</td>
<td>
<ol>
<li><b>bl_gem_latest_version</b>: Return the latest version of a gem from rubygems.org</li>
<li><b>bl_jq_available</b>: Check jq binary is available</li>
<li><b>bl_curl_available</b>: Check curl binary is available</li>
</ol>
</td>
</tr>
<tr>
<td><a href="test-utils/lib">test-utils</a></td>
<td>Helpers for executing tests</td>
Expand Down
2 changes: 2 additions & 0 deletions github/lib
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function bl_hub_download_latest(){
local download_url
local bin_path

bl_curl_available

if [[ -z "${os_arch}" ]]; then
if [[ "${OSTYPE}" =~ "darwin" ]]; then
os_arch="darwin-amd64"
Expand Down
2 changes: 1 addition & 1 deletion init
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BASH_LIB_DIR="${BASH_LIB_DIR_RELATIVE}"

# Load the filehandling module for the abspath
# function
for lib in helpers logging filehandling git github k8s test-utils; do
for lib in helpers logging filehandling git github k8s test-utils ruby; do
. "${BASH_LIB_DIR_RELATIVE}/${lib}/lib"
done

Expand Down
1 change: 0 additions & 1 deletion logging/lib
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ function bl_error(){
function bl_fatal(){
bl_log fatal "${*}"
}

23 changes: 23 additions & 0 deletions ruby/lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
: "${BASH_LIB_DIR:?BASH_LIB_DIR must be set. Please source bash-lib/init before other scripts from bash-lib.}"

function bl_jq_available(){
type jq >/dev/null || bl_fail "jq not found :("
}

function bl_curl_available(){
type curl >/dev/null || bl_fail "curl not found :("
}

function bl_gem_latest_version(){
bl_jq_available
bl_curl_available

gem="${1:-}"

if [[ -z "${gem}" ]]; then
bl_fail "usage: bl_gem_version <gem name>"
fi

curl https://rubygems.org/api/v1/gems/${gem}.json \
|jq -r '.version'
}
14 changes: 11 additions & 3 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
# shellcheck disable=SC2086
. "$(dirname ${BASH_SOURCE[0]})/init"

# Run BATS Tests
bl_info "Checking the changelog complies with keepachangelog.com format"
docker run \
--rm \
-v "${PWD}/CHANGELOG.md:/CHANGELOG.md" \
cyberark/parse-a-changelog

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

# Run Python Lint
bl_info "Running Python Lint"
"${BASH_LIB_DIR}/tests-for-this-repo/run-python-lint"

# Run gitleaks
bl_info "Running gitleaks"
"${BASH_LIB_DIR}/tests-for-this-repo/run-gitleaks"

bl_info "Sucess! All tests passed."
42 changes: 42 additions & 0 deletions tests-for-this-repo/fixtures/ruby/ruby_gems_api_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "parse_a_changelog",
"downloads": 6660,
"version": "1.0.1",
"version_downloads": 168,
"platform": "ruby",
"authors": "John Tuttle",
"info": "Uses a grammar describing the keep-a-changelog format to attempt to parse a given file.",
"licenses": [
"Apache-2.0"
],
"metadata": {},
"yanked": false,
"sha": "c081ae854570083ba56097d84a1fc66d47dd31f1a015edcb1ba2cbf9e2a4fe4a",
"project_uri": "https://rubygems.org/gems/parse_a_changelog",
"gem_uri": "https://rubygems.org/gems/parse_a_changelog-1.0.1.gem",
"homepage_uri": "http://github.com/cyberark/parse-a-changelog",
"wiki_uri": null,
"documentation_uri": "http://www.rubydoc.info/gems/parse_a_changelog/1.0.1",
"mailing_list_uri": null,
"source_code_uri": null,
"bug_tracker_uri": null,
"changelog_uri": null,
"dependencies": {
"development": [
{
"name": "rspec",
"requirements": "~> 3.8"
},
{
"name": "rspec_junit_formatter",
"requirements": "~> 0.4.1"
}
],
"runtime": [
{
"name": "treetop",
"requirements": "~> 1.6"
}
]
}
}
56 changes: 56 additions & 0 deletions tests-for-this-repo/ruby.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
. "${BASH_LIB_DIR}/test-utils/bats-support/load.bash"
. "${BASH_LIB_DIR}/test-utils/bats-assert-1/load.bash"

. "${BASH_LIB_DIR}/init"

teardown(){
unset curl
}


@test "bl_jq_available succeeds when jq is available" {
jq(){ :; }
run bl_jq_available
assert_success
}

@test "bl_jq_available fails when jq is not available" {
real_path="${PATH}"
PATH=""
run bl_jq_available
PATH="${real_path}"
assert_failure
assert_output --partial "jq not found"
}

@test "bl_curl_available succeeds when jq is available" {
jq(){ :; }
run bl_curl_available
assert_success
}

@test "bl_curl_available fails when jq is not available" {
real_path="${PATH}"
PATH=""
run bl_curl_available
PATH="${real_path}"
assert_failure
assert_output --partial "curl not found"
}

@test "bl_gem_latest_version fails when no gem name is supplied" {
run bl_gem_latest_version
assert_failure
assert_output --partial "usage"
}

@test "bl_gem_latest_version returns only the version number" {
curl(){
fixtures_dir="${BASH_LIB_DIR}/tests-for-this-repo/fixtures/ruby"
cat ${fixtures_dir}/ruby_gems_api_response.json
}

run bl_gem_latest_version parse_a_changelog
assert_success
assert_output "1.0.1"
}