Activate ansible-lint workflow #439
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Molecule Playbooks | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- ready_for_review | |
jobs: | |
define_scenarios: | |
if: github.event.pull_request.draft == false | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get changed scenarios | |
id: changed-scenarios | |
uses: tj-actions/changed-files@v41 | |
with: | |
dir_names: true | |
dir_names_max_depth: 2 | |
files: | | |
molecule/playbook-*/*.yml | |
- name: Get changed playbooks | |
id: changed-playbooks | |
uses: tj-actions/changed-files@v41 | |
with: | |
files: | | |
playbooks/*.yml | |
- name: List all changed files | |
run: echo '${{ steps.changed-playbooks.outputs.all_changed_files }}' '${{ steps.changed-scenarios.outputs.all_changed_files }}' | |
- name: Set matrix based on changed files | |
id: set-scenario-matrix | |
run: | | |
PLAYBOOKS=(${{steps.changed-playbooks.outputs.all_changed_files}}) | |
PLAYBOOKS=("${PLAYBOOKS[@]/#playbooks\//playbook-}") # playbooks/foo.yml -> playbook-foo.yml | |
PLAYBOOKS=("${PLAYBOOKS[@]/%.yml/}") # playbook-foo.yml -> playbook-foo | |
echo "DEBUG PLAYBOOKS: ${PLAYBOOKS[*]}" | |
SCENARIOS=(${{ steps.changed-scenarios.outputs.all_changed_files }}) | |
SCENARIOS=("${SCENARIOS[@]/#molecule\//}") # molecule/playbook-foo -> playbook-foo | |
echo "DEBUG SCENARIOS: ${SCENARIOS[*]}" | |
ALL_CHANGES="${PLAYBOOKS[*]} ${SCENARIOS[*]}" | |
echo "DEBUG ALL_CHANGES: $ALL_CHANGES" | |
# Construct a unique bash array out of ALL_CHANGES | |
MATRIX=($(echo "$ALL_CHANGES" | xargs -n 1 | sort -u)) | |
# Create a valid json array out of the bash array using jq | |
MATRIX=$(printf '%s\n' "${MATRIX[@]}" | jq -R . | jq -c -s .) | |
# Store the results | |
echo matrix={\"scenarios\": $MATRIX} >> $GITHUB_OUTPUT | |
echo scenarios=$MATRIX >> $GITHUB_OUTPUT | |
echo "DEBUG SCENARIOS: $MATRIX" | |
outputs: | |
matrix: ${{ steps.set-scenario-matrix.outputs.matrix }} | |
scenarios: ${{ steps.set-scenario-matrix.outputs.scenarios }} | |
molecule: | |
needs: define_scenarios | |
runs-on: ubuntu-latest | |
if: ${{ needs.define_scenarios.outputs.scenarios != '[""]' && needs.define_scenarios.outputs.scenarios != '' }} | |
env: | |
DOCKER_USER: ${{ github.actor }} | |
DOCKER_PW: ${{ secrets.GITHUB_TOKEN }} | |
DOCKER_REGISTRY: ghcr.io | |
ANSIBLE_FORCE_COLOR: '1' | |
ANSIBLE_STDOUT_CALLBACK: yaml | |
MOLECULE_CONFIG: molecule/ext/molecule-src/molecule.yml | |
REQUIREMENTS_FILE: molecule/ext/molecule-src/requirements.txt | |
ANSIBLE_REQUIREMENTS_FILE: molecule/ext/molecule-src/requirements.yml | |
CRUN_VER: 1.11.2 | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJSON(needs.define_scenarios.outputs.matrix) }} | |
steps: | |
- name: Workaround crun issue on ubuntu # https://github.com/UtrechtUniversity/SRC-catalog-items/issues/3 | |
run: | | |
mkdir -p "${HOME}/.local/bin" | |
curl -L "https://github.com/containers/crun/releases/download/${CRUN_VER}/crun-${CRUN_VER}-linux-amd64" -o "${HOME}/.local/bin/crun" | |
chmod +x "${HOME}/.local/bin/crun" | |
crun --version | |
mkdir -p "${HOME}/.config/containers" | |
cat << EOF > "${HOME}/.config/containers/containers.conf" | |
[engine.runtimes] | |
crun = [ | |
"${HOME}/.local/bin/crun", | |
"/usr/bin/crun" | |
] | |
EOF | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- run: pip install -r ${{ env.REQUIREMENTS_FILE }} | |
- run: ansible-galaxy install -r ${{ env.ANSIBLE_REQUIREMENTS_FILE }} | |
- run: ansible-galaxy install -r requirements.yml | |
- name: Check if scenario exists | |
id: check_scenario_exists | |
run: | | |
if [[ -d molecule/${{ matrix.scenarios }} ]]; then | |
echo "exitcode=true" >> $GITHUB_OUTPUT | |
else | |
echo "exitcode=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Molecule tests for playbook | |
if: ${{ steps.check_scenario_exists.outputs.exitcode == 'true' }} | |
run: | | |
molecule -c ${{ env.MOLECULE_CONFIG }} test --scenario-name ${{ matrix.scenarios }} |