Files
Kamino/scripts/run_molecule_in_ci_image.sh
T

35 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: Defame1297 and contributors
# SPDX-License-Identifier: GPL-3.0-or-later
#
# The Molecule workflow's run inside the ci image, from the checkout root: when a pin file differs
# from the image's, install the pull request's pins into $AC_ROOT/pins (/opt is not writable for the
# runner user) and put them first, then run the scenarios on stdin. CI_BASE_PYTHON is a test seam.
#
# AC_ROOT=<dir holding ansible_collections> scripts/run_molecule_in_ci_image.sh < scenario-dirs
set -euo pipefail
selected="$(cat)"
pins="$AC_ROOT/pins"
collections=""
if sha256sum --quiet -c /opt/ci-pins.sha256; then
echo "The pin files match the ci image; using the baked tools."
else
echo "::warning::a pin file differs from the ci image; installing the pinned tools and collections for this run."
"${CI_BASE_PYTHON:-/opt/venv/bin/python}" -m venv "$pins/venv"
"$pins/venv/bin/pip" install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
export PATH="$pins/venv/bin:$PATH"
# The target alone on the path, so a baked copy is not taken as already installed.
for req in requirements.yml extensions/molecule/requirements.yml; do
ANSIBLE_COLLECTIONS_PATH="$pins/collections" \
ansible-galaxy collection install --force -r "$req" -p "$pins/collections"
done
collections="$pins/collections:"
fi
ansible --version
molecule --version
# The collection under test first; molecule also installs it into each scenario's ANSIBLE_HOME,
# which the run script keeps in the job tree.
export ANSIBLE_COLLECTIONS_PATH="$AC_ROOT:$collections/opt/collections"
exec scripts/run_molecule_scenarios.sh "$AC_ROOT/molecule-runs" <<< "$selected"