Skip to content

Instantly share code, notes, and snippets.

@s-leroux
Last active May 19, 2021 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-leroux/764c6f7b610fdb2e03a2428bf099a41a to your computer and use it in GitHub Desktop.
Save s-leroux/764c6f7b610fdb2e03a2428bf099a41a to your computer and use it in GitHub Desktop.
Build a CSV matrix showing versions of Asciidoctor that produce identical output
#!/bin/bash
#
# Usage:
# sudo Build [test-file.adoc] > result.csv
#
set -e
TESTFILE="${1:-test-file.adoc}" # the test file
DIFF="${DIFF:-diff}" # the diff tool
BASEIMAGE="${BASEIMAGE:-ruby:alpine3.12}"
[ -r "${TESTFILE}" ] || ( echo Can\'t read file: ${TESTFILE} >&2; exit 1 )
RESULTS=()
#
# Collect the version tags from the remote repository
#
echo "Collecting tags" >&2
VERSIONS=( $(
git ls-remote --tags https://github.com/asciidoctor/asciidoctor |
awk -F/ '/v[0-9]+\.[0-9]+\.[0-9]+$/ { print $3 }' | sort -V
))
#
# Create a new docker image for each Asciidoctor version
# and start a conversion in a corresponding container
#
for VERSION in "${VERSIONS[@]}"; do
TAG="asciidoctor:${VERSION}"
echo "Building ${TAG}" >&2
docker build --quiet --tag "${TAG}" - > /dev/null <<- EOF
FROM ${BASEIMAGE}
RUN gem install asciidoctor -"${VERSION}"
CMD asciidoctor -b docbook -
EOF
DESTFILE="${TESTFILE%.*}-${TAG}"
RESULTS+=( "${DESTFILE}" )
docker run -i --rm "${TAG}" < "${TESTFILE}" > "${DESTFILE}" || rm -f "${DESTFILE}" &
done
echo Waiting for tests completion >&2
wait
echo Done >&2
#
# Print the results as a CSV table
#
# Header lines
echo "${TESTFILE} (${BASEIMAGE})"
for A in "${RESULTS[@]}"; do
echo -n ", ${A##*:}"
done
echo
#
# Compare all results 2 by 2
#
# Obviously the matrix is symetric so we could optimize that...
#
for A in "${RESULTS[@]}"; do
echo -n "${A##*:}"
for B in "${RESULTS[@]}"; do
if [ -r "${A}" -a -r "${B}" ]; then
if diff "${A}" "${B}" > /dev/null 2>&1 ; then
echo -n ", M"
else
echo -n ", x"
fi
else
echo -n ", -"
fi
done
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment