|
| 1 | +#!/bin/bash |
| 2 | +#================================================================ |
| 3 | +# HEADER |
| 4 | +#================================================================ |
| 5 | +#% |
| 6 | +#%OVERVIEW 📑 |
| 7 | +#+ ./scripts/prow-smoke-test.sh [--validate --preview] |
| 8 | +#% |
| 9 | +#%DESCRIPTION 💡 |
| 10 | +#% Validates openshift-docs AsciiDoc source files using the same tools that run in the Prow CI |
| 11 | +#% |
| 12 | +#%OPTIONS ⚙️ |
| 13 | +#% -v, --validate Validate the AsciiDoc source |
| 14 | +#% -p, --preview $DISTRO "$PRODUCT_NAME" $VERSION Use --preview to run with default options |
| 15 | +#% -h, --help Print this help |
| 16 | +#% |
| 17 | +#%EXAMPLES 🤔 |
| 18 | +#% ./scripts/prow-smoke-test.sh --validate |
| 19 | +#% ./scripts/prow-smoke-test.sh --preview |
| 20 | +#% ./scripts/prow-smoke-test.sh --preview openshift-rosa |
| 21 | +#% ./scripts/prow-smoke-test.sh --preview openshift-pipelines "Red Hat OpenShift Pipelines" 1.14 |
| 22 | +#================================================================ |
| 23 | +# END_OF_HEADER |
| 24 | +#================================================================ |
| 25 | + |
| 26 | +set -e |
| 27 | + |
| 28 | +TEST=$1 |
| 29 | +DISTRO=$2 |
| 30 | +PRODUCT_NAME=$3 |
| 31 | +VERSION=$4 |
| 32 | +CONTAINER_IMAGE=quay.io/redhat-docs/openshift-docs-asciidoc |
| 33 | +SCRIPT_HEADSIZE=$(head -30 ${0} |grep -n "^# END_OF_HEADER" | cut -f1 -d:) |
| 34 | + |
| 35 | +if [[ "$1" == "--help" || "$1" == "-h" ]]; then |
| 36 | + usage |
| 37 | +fi |
| 38 | + |
| 39 | +# Assign default variables |
| 40 | +: ${PRODUCT_NAME:="OpenShift Container Platform"} |
| 41 | +: ${VERSION:="4.16"} |
| 42 | +: ${DISTRO:="openshift-enterprise"} |
| 43 | + |
| 44 | +# Allow podman or docker |
| 45 | +if hash podman 2>/dev/null; then |
| 46 | + CONTAINER_ENGINE=podman |
| 47 | +elif hash docker 2>/dev/null; then |
| 48 | + CONTAINER_ENGINE=docker |
| 49 | +else |
| 50 | + echo >&2 "Container engine not installed. Install Podman or Docker and run the script again." |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +echo "CONTAINER_ENGINE=$CONTAINER_ENGINE 🐳" |
| 55 | + |
| 56 | +# Get the default container $WORKDIR |
| 57 | +CONTAINER_WORKDIR=$($CONTAINER_ENGINE run --rm $CONTAINER_IMAGE /bin/bash -c 'echo $PWD') |
| 58 | + |
| 59 | +# Grep the commented script preamble and return it as help |
| 60 | +display_help() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#[%+-]" | sed -e "s/^#[%+-]//g" ; } |
| 61 | + |
| 62 | +# Exit and show the help if no parameters are passed |
| 63 | +if [ $# -eq 0 ]; then |
| 64 | + display_help |
| 65 | +fi |
| 66 | + |
| 67 | +if [[ "$TEST" == "--preview" || "$TEST" == "-p" ]] && [[ -z "$DISTRO" ]]; then |
| 68 | + echo "" |
| 69 | + echo "🚧 Building with openshift-enterprise distro..." |
| 70 | + $CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}:Z $CONTAINER_IMAGE asciibinder build -d "$DISTRO" |
| 71 | + |
| 72 | +elif [[ "$TEST" == "--preview" || "$TEST" == "-p" ]] && [[ -n "$DISTRO" ]]; then |
| 73 | + echo "" |
| 74 | + echo "🚧 Building $DISTRO distro..." |
| 75 | + $CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}:Z $CONTAINER_IMAGE asciibinder build -d "$DISTRO" |
| 76 | + |
| 77 | +elif [[ "$TEST" == "--validate" || "$TEST" == "-v" ]]; then |
| 78 | + echo "" |
| 79 | + echo "🚧 Validating the docs..." |
| 80 | + $CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}:Z $CONTAINER_IMAGE sh -c 'scripts/check-asciidoctor-build.sh && python3 build_for_portal.py --distro '${DISTRO}' --product "'"${PRODUCT_NAME}"'" --version '${VERSION}' --no-upstream-fetch && python3 makeBuild.py' |
| 81 | +fi |
0 commit comments