-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathprow-smoke-test.sh
executable file
·112 lines (98 loc) · 4.49 KB
/
prow-smoke-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
#================================================================
# HEADER
#================================================================
#%
#%OVERVIEW 📑
#+ ./scripts/prow-smoke-test.sh [--validate --preview]
#%
#%DESCRIPTION 💡
#% Validates openshift-docs AsciiDoc source files using the same tools that run in the Prow CI
#%
#%OPTIONS ⚙️
#% -v, --validate $DISTRO Validate the AsciiDoc source. Use --validate to run with default options
#% -a, --validate-incl-api-book Validate the AsciiDoc source and include the REST API books
#% -l, --lint-topicmaps Lint topic-map YAML
#% -p, --preview $DISTRO "$PRODUCT_NAME" $VERSION Use --preview to run with default options
#% -h, --help Print this help
#%
#%EXAMPLES 🤔
#% ./scripts/prow-smoke-test.sh --validate
#% ./scripts/prow-smoke-test.sh --validate openshift-rosa
#% ./scripts/prow-smoke-test.sh --validate-incl-api-book
#% ./scripts/prow-smoke-test.sh --lint-topicmaps
#% ./scripts/prow-smoke-test.sh --preview
#% ./scripts/prow-smoke-test.sh --preview openshift-rosa
#% ./scripts/prow-smoke-test.sh --preview openshift-pipelines "Red Hat OpenShift Pipelines" 1.14
#================================================================
# END_OF_HEADER
#================================================================
set -e
TEST=$1
DISTRO=$2
PRODUCT_NAME=$3
VERSION=$4
ARCH=$(uname -m)
TAG=latest # Default tag
SELINUX_LABEL=":Z"
if [[ $ARCH == "aarch64" || $ARCH == "arm64" ]]; then
TAG=multiarch
SELINUX_LABEL=""
fi
CONTAINER_IMAGE="quay.io/redhat-docs/openshift-docs-asciidoc:$TAG"
SCRIPT_HEADSIZE=$(head -30 ${0} |grep -n "^# END_OF_HEADER" | cut -f1 -d:)
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
usage
fi
# Assign default variables
: ${PRODUCT_NAME:="OpenShift Container Platform"}
: ${VERSION:="4.16"}
: ${DISTRO:="openshift-enterprise"}
# Allow podman or docker
if hash podman 2>/dev/null; then
CONTAINER_ENGINE=podman
elif hash docker 2>/dev/null; then
CONTAINER_ENGINE=docker
else
echo >&2 "Container engine not installed. Install Podman or Docker and run the script again."
exit 1
fi
echo "CONTAINER_ENGINE=$CONTAINER_ENGINE 🐳"
echo "CONTAINER_IMAGE=$CONTAINER_IMAGE"
# Get the default container $WORKDIR
CONTAINER_WORKDIR=$($CONTAINER_ENGINE run --rm $CONTAINER_IMAGE /bin/bash -c 'echo $PWD')
# Grep the commented script preamble and return it as help
display_help() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#[%+-]" | sed -e "s/^#[%+-]//g" ; }
# Exit and show the help if no parameters are passed
if [ $# -eq 0 ]; then
display_help
fi
if [[ "$TEST" == "--preview" || "$TEST" == "-p" ]] && [[ -z "$DISTRO" ]]; then
# Clean output folder
rm -rf ./_preview
echo ""
echo "🚧 Building with openshift-enterprise distro..."
$CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}${SELINUX_LABEL} $CONTAINER_IMAGE asciibinder build -d "$DISTRO"
elif [[ "$TEST" == "--preview" || "$TEST" == "-p" ]] && [[ -n "$DISTRO" ]]; then
# Clean output folder
rm -rf ./_preview
echo ""
echo "🚧 Building $DISTRO distro..."
$CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}${SELINUX_LABEL} $CONTAINER_IMAGE asciibinder build -d "$DISTRO"
elif [[ "$TEST" == "--validate" || "$TEST" == "-v" ]]; then
# Clean output folder
rm -rf ./drupal-build
echo ""
echo "🚧 Validating the docs..."
$CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}${SELINUX_LABEL} $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'
elif [[ "$TEST" == "--validate-incl-api-book" || "$TEST" == "-a" ]]; then
# Clean output folder
rm -rf ./drupal-build
echo ""
echo "🚧 Validating the docs..."
$CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}${SELINUX_LABEL} $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 --include-api-book'
elif [[ "$TEST" == "--lint-topicmaps" || "$TEST" == "-l" ]]; then
echo ""
echo "🚧 Linting the topicmap YAML..."
$CONTAINER_ENGINE run --rm -it -v "$(pwd)":${CONTAINER_WORKDIR}${SELINUX_LABEL} $CONTAINER_IMAGE sh -c 'yamllint _topic_maps'
fi