---
inputs:
  dependencies:
    description: List of package(s) to pre-install
    required: false
  groups:
    description: List of group(s) to install
    required: false
  packages:
    description: List of package(s) to install
    required: true

runs:
  using: composite
  steps:
    - name: Install "dnf-command(config-manager)" (CentOS Stream)
      run: dnf --assumeyes --skip-broken install "dnf-command(config-manager)"
      shell: bash --noprofile --norc -euxo pipefail {0}
      if: startsWith(matrix.image, 'quay.io/centos/centos:stream')

    - name: Enable PowerTools repository (CentOS Stream 8)
      run: dnf config-manager --set-enabled powertools
      shell: bash --noprofile --norc -euxo pipefail {0}
      if: matrix.image == 'quay.io/centos/centos:stream8'

    - name: Enable CRB repository (CentOS Stream 9)
      run: dnf config-manager --set-enabled crb
      shell: bash --noprofile --norc -euxo pipefail {0}
      if: matrix.image == 'quay.io/centos/centos:stream9'

    - name: Enable EPEL repository (Amazon Linux 2)
      run: amazon-linux-extras install epel -y
      shell: bash --noprofile --norc -euxo pipefail {0}
      if: matrix.image == 'amazonlinux:2' && contains(inputs.dependencies, 'epel-release')

    - name: Install dependency package(s)
      run: |
        if [ -n "${{ inputs.dependencies }}" ]; then
          yum --assumeyes install ${{ inputs.dependencies }}
        fi
      shell: bash --noprofile --norc -euxo pipefail {0}

    - name: Install group(s)
      run: |
        if [ -n '${{ inputs.groups }}' ]; then
          yum --assumeyes groups install ${{ inputs.groups }}
        fi
      shell: bash --noprofile --norc -euxo pipefail {0}

    - name: Install package(s)
      run: |
        if command -v dnf5 &> /dev/null; then
          yum --assumeyes install ${{ inputs.packages }}
        else
          yum --assumeyes --skip-broken install ${{ inputs.packages }}
        fi
      shell: bash --noprofile --norc -euxo pipefail {0}
