Skip to content

Commit

Permalink
Re-bootstrap with github-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran committed May 20, 2021
1 parent c1c1632 commit 4f855d6
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 27 deletions.
7 changes: 7 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"stack": "cflinuxfs3",
"oses": [
"linux",
"windows"
]
}
52 changes: 52 additions & 0 deletions scripts/.util/print.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

function util::print::title() {
local blue reset message
blue="\033[0;34m"
reset="\033[0;39m"
message="${1}"

echo -e "\n${blue}${message}${reset}" >&2
}

function util::print::info() {
local message
message="${1}"

echo -e "${message}" >&2
}

function util::print::error() {
local message red reset
message="${1}"
red="\033[0;31m"
reset="\033[0;39m"

echo -e "${red}${message}${reset}" >&2
exit 1
}

function util::print::success() {
local message green reset
message="${1}"
green="\033[0;32m"
reset="\033[0;39m"

echo -e "${green}${message}${reset}" >&2
exitcode="${2:-0}"
exit "${exitcode}"
}

function util::print::warn() {
local message yellow reset
message="${1}"
yellow="\033[0;33m"
reset="\033[0;39m"

echo -e "${yellow}${message}${reset}" >&2
exit 0
}

114 changes: 114 additions & 0 deletions scripts/.util/tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

# shellcheck source=SCRIPTDIR/print.sh
source "$(dirname "${BASH_SOURCE[0]}")/print.sh"

function util::tools::path::export() {
local dir
dir="${1}"

if ! echo "${PATH}" | grep -q "${dir}"; then
PATH="${dir}:$PATH"
export PATH
fi
}

function util::tools::ginkgo::install() {
local dir
while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

mkdir -p "${dir}"
util::tools::path::export "${dir}"

if [[ ! -f "${dir}/ginkgo" ]]; then
util::print::title "Installing ginkgo"

GOBIN="${dir}" \
go get \
-u \
github.com/onsi/ginkgo/ginkgo
fi
}

function util::tools::buildpack-packager::install() {
local dir
while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

mkdir -p "${dir}"
util::tools::path::export "${dir}"

if [[ ! -f "${dir}/buildpack-packager" ]]; then
util::print::title "Installing buildpack-packager"

GOBIN="${dir}" \
go install \
github.com/cloudfoundry/libbuildpack/packager/buildpack-packager
fi
}

function util::tools::jq::install() {
local dir
while [[ "${#}" != 0 ]]; do
case "${1}" in
--directory)
dir="${2}"
shift 2
;;

*)
util::print::error "unknown argument \"${1}\""
esac
done

mkdir -p "${dir}"
util::tools::path::export "${dir}"

local os
case "$(uname)" in
"Darwin")
os="osx-amd64"
;;

"Linux")
os="linux64"
;;

*)
echo "Unknown OS \"$(uname)\""
exit 1
esac

if [[ ! -f "${dir}/jq" ]]; then
util::print::title "Installing jq"

curl "https://github.com/stedolan/jq/releases/download/jq-1.6/jq-${os}" \
--silent \
--location \
--output "${dir}/jq"
chmod +x "${dir}/jq"
fi
}
17 changes: 13 additions & 4 deletions scripts/brats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@ set -o pipefail
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR

source "${ROOTDIR}/.envrc"
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOTDIR}/scripts/.util/tools.sh"

function main() {
local src
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"

"${ROOTDIR}/scripts/install_tools.sh"
if [[ ! -d "${src}/brats" ]]; then
echo "There are no brats tests to run"
exit 0
fi

util::tools::ginkgo::install --directory "${ROOTDIR}/.bin"
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"
util::tools::jq::install --directory "${ROOTDIR}/.bin"

echo "Run Buildpack Runtime Acceptance Tests"
local stack
stack="$(jq -r -S .stack "${ROOTDIR}/config.json")"

CF_STACK="${CF_STACK:-cflinuxfs3}" \
echo "Run Buildpack Runtime Acceptance Tests"
CF_STACK="${CF_STACK:-"${stack}"}" \
ginkgo \
-r \
-mod vendor \
Expand Down
33 changes: 16 additions & 17 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,36 @@ set -o pipefail
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR

# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOTDIR}/scripts/.util/tools.sh"

function main() {
local src
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"

IFS=" " read -r -a binaries <<< "$(find "${src}" -name cli -type d -print0 | xargs -0)"

for path in "${binaries[@]}"; do
local name
name="$(basename "$(dirname "${path}")")"
util::tools::jq::install --directory "${ROOTDIR}/.bin"

GOOS=linux \
go build \
-mod vendor \
-ldflags="-s -w" \
-o "${ROOTDIR}/bin/${name}" \
"${path}"
done
IFS=" " read -r -a oses <<< "$(jq -r -S '.oses[]' "${ROOTDIR}/config.json" | xargs)"
IFS=" " read -r -a binaries <<< "$(find "${src}" -name cli -type d -print0 | xargs -0)"

if [[ -f "${ROOTDIR}/.windows" ]]; then
for os in "${oses[@]}"; do
for path in "${binaries[@]}"; do
local name
local name output
name="$(basename "$(dirname "${path}")")"
output="${ROOTDIR}/bin/${name}"

if [[ "${os}" == "windows" ]]; then
output="${output}.exe"
fi

GOOS=windows \
GOOS="${os}" \
go build \
-mod vendor \
-ldflags="-s -w" \
-o "${ROOTDIR}/bin/${name}.exe" \
-o "${output}" \
"${path}"
done
fi
done
}

main "${@:-}"
13 changes: 9 additions & 4 deletions scripts/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ set -o pipefail
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR

source "${ROOTDIR}/.envrc"
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOTDIR}/scripts/.util/tools.sh"

function main() {
local src
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"

"${ROOTDIR}/scripts/install_tools.sh"
util::tools::ginkgo::install --directory "${ROOTDIR}/.bin"
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"

local stack
stack="$(jq -r -S .stack "${ROOTDIR}/config.json")"

echo "Run Uncached Buildpack"
CF_STACK="${CF_STACK:-cflinuxfs3}" \
CF_STACK="${CF_STACK:-"${stack}"}" \
BUILDPACK_FILE="${UNCACHED_BUILDPACK_FILE:-}" \
ginkgo \
-r \
Expand All @@ -28,7 +33,7 @@ function main() {
-- --cached=false

echo "Run Cached Buildpack"
CF_STACK="${CF_STACK:-cflinuxfs3}" \
CF_STACK="${CF_STACK:-"${stack}"}" \
BUILDPACK_FILE="${CACHED_BUILDPACK_FILE:-}" \
ginkgo \
-mod vendor \
Expand Down
9 changes: 7 additions & 2 deletions scripts/unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ set -o pipefail
ROOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
readonly ROOTDIR

source "${ROOTDIR}/.envrc"
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOTDIR}/scripts/.util/tools.sh"

# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${ROOTDIR}/scripts/.util/tools.sh"

function main() {
local src
src="$(find "${ROOTDIR}/src" -mindepth 1 -maxdepth 1 -type d )"

"${ROOTDIR}/scripts/install_tools.sh"
util::tools::ginkgo::install --directory "${ROOTDIR}/.bin"
util::tools::buildpack-packager::install --directory "${ROOTDIR}/.bin"

ginkgo \
-r \
Expand Down

0 comments on commit 4f855d6

Please sign in to comment.