Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack: Validating generated build artifacts option on tests #994

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 28 additions & 7 deletions stack/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o pipefail

readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly STACK_DIR="$(cd "${PROG_DIR}/.." && pwd)"
readonly STACK_IMAGES_JSON_PATH="${STACK_DIR}/images.json"
readonly STACK_IMAGES_JSON_PATH="${STACK_DIR}/stacks/images.json"
readonly INTEGRATION_JSON="${STACK_DIR}/integration.json"
declare STACK_IMAGES

Expand All @@ -16,13 +16,16 @@ source "${PROG_DIR}/.util/tools.sh"
source "${PROG_DIR}/.util/print.sh"

function main() {
local clean token test_only_stacks registryPort registryPid localRegistry setupLocalRegistry
local clean token test_only_stacks validate_stack_builds
local registryPort registryPid localRegistry setupLocalRegistry

help=""
clean="false"
token=""
test_only_stacks=""
registryPid=""
setupLocalRegistry=""
validate_stack_builds="false"

while [[ "${#}" != 0 ]]; do
case "${1}" in
Expand All @@ -46,6 +49,11 @@ function main() {
shift 2
;;

--validate-stack-builds)
validate_stack_builds="true"
shift 1
;;

"")
# skip if the argument is empty
shift 1
Expand Down Expand Up @@ -100,6 +108,11 @@ function main() {

stack_output_builds_exist=$(stack_builds_exist)

if [[ "${stack_output_builds_exist}" == "false" && "${validate_stack_builds}" == "true" ]]; then
util::print::error "Stack builds are not valid."
exit 1
fi

if [[ "${stack_output_builds_exist}" == "false" ]]; then
util::print::title "Creating stack..."
while read -r image; do
Expand All @@ -109,6 +122,8 @@ function main() {
--stack-dir "${config_dir}" \
--build-dir "${output_dir}"
done <<<"$STACK_IMAGES"
else
util::print::title "Stack builds already exist..."
fi

if [[ -f $INTEGRATION_JSON ]]; then
Expand Down Expand Up @@ -163,10 +178,11 @@ ${joined_oci_images}
if they exist. Otherwise, first runs create.sh to create them.

OPTIONS
--clean -c clears contents of stack output directory before running tests
--token <token> -t Token used to download assets from GitHub (e.g. jam, pack, etc) (optional)
--test-only-stacks Runs the tests of the stacks passed to this argument (e.g. java-8 nodejs-16) (optional)
--help -h prints the command usage
--clean -c Clears contents of stack output directory before running tests
--token <token> -t Token used to download assets from GitHub (e.g. jam, pack, etc) (optional)
--test-only-stacks Runs the tests of the stacks passed to this argument (e.g. java-8 nodejs-16) (optional)
--validate-stack-builds Validates that the stack builds are present before running tests (optional)
--help -h Prints the command usage
USAGE
}

Expand Down Expand Up @@ -210,7 +226,12 @@ function stack_builds_exist() {

while IFS= read -r image; do
stack_output_dir=$(echo "${image}" | jq -r '.output_dir')
if ! [[ -f "${STACK_DIR}/${stack_output_dir}/build.oci" ]] || ! [[ -f "${STACK_DIR}/${stack_output_dir}/run.oci" ]]; then
is_build_image_necessary=$(echo "${image}" | jq -r '.create_build_image // false')

if ! [[ -f "${STACK_DIR}/${stack_output_dir}/run.oci" ]]; then
stack_output_builds_exist="false"
fi
if [[ ! -f "${STACK_DIR}/${stack_output_dir}/build.oci" && "${is_build_image_necessary}" == true ]]; then
stack_output_builds_exist="false"
fi
done <<<"$STACK_IMAGES"
Expand Down
Loading