##
## =====================================================================================
##  C O P Y R I G H T
## -------------------------------------------------------------------------------------
##  Copyright (c) 2023 by Robert Bosch GmbH. All rights reserved.
##
##  Author(s):
##  - Markus Braun, :em engineering methods AG (contracted by Robert Bosch GmbH)
## =====================================================================================
##

name: "Ensure Everything is initialized for build/test etc."
description: "Installs python and poetry if necessary"
inputs:
  python-version:
    description: "The version of python to use (default: 3.9)"
    required: true
    default: 3.9
  doc-tools:
    description: "Whether to install the documentation tools (doxygen)"
    required: true
    default: true
runs:
  using: "composite"
  steps:
  - name: "Ensure doxygen"
    if: inputs.doc-tools
    run: sudo apt-get install graphviz doxygen -y
    # latest doxygen (untested)
    # run: |
    #  if ! command -v doxygen &> /dev/null
    #  then
    #    echo "doxygen wasn't found... installing now..."
    #    mkdir -p ~/.local/bin
    #    curl -sSL https://www.doxygen.nl/files/doxygen-1.9.4.linux.bin.tar.gz | \
    #    tar -xzvf - --strip-components=1 -C ~/.local/bin bin/doxygen;
    #  fi

    shell: bash

  - name: "Ensure poetry"
    run: pipx install poetry
    shell: bash

  - name: "Ensure python (with poetry caching)"
    uses: actions/setup-python@v5
    with:
      python-version: ${{ inputs.python-version }}
      cache: 'poetry'

  - name: "Install dependencies"
    run: poetry install --with=ci
    shell: bash
