# ********** Please don't edit this file!
# ********** It has been generated automatically by dae_devops version 0.5.4.dev0+g1fb30ef.d20230527.
# ********** For repository_name dls-bxflow

name: Install requirements
description: Run pip install with requirements and upload resulting requirements
inputs:
  requirements_file:
    description: Name of requirements file to use and upload
    required: true
  install_options:
    description: Parameters to pass to pip install
    required: true
  python_version:
    description: Python version to install
    default: "3.x"

runs:
  using: composite

  steps:
    - name: Setup python
      uses: actions/setup-python@v4
      with:
        python-version: ${{ inputs.python_version }}

    - name: Pip install
      run: |
        touch ${{ inputs.requirements_file }}
        # -c uses requirements.txt as constraints, see 'Validate requirements file'
        pip install -c ${{ inputs.requirements_file }} ${{ inputs.install_options }}
      shell: bash

    - name: Create lockfile
      run: |
        mkdir -p lockfiles
        pip freeze --exclude-editable > lockfiles/${{ inputs.requirements_file }}
        # delete the self referencing line and make sure it isn't blank
        sed -i '/file:/d' lockfiles/${{ inputs.requirements_file }}
      shell: bash

    - name: Upload lockfiles
      uses: actions/upload-artifact@v3
      with:
        name: lockfiles
        path: lockfiles

    # This eliminates the class of problems where the requirements being given no
    # longer match what the packages themselves dictate. E.g. In the rare instance
    # where I install some-package which used to depend on vulnerable-dependency
    # but now uses good-dependency (despite being nominally the same version)
    # pip will install both if given a requirements file with -r
    - name: If requirements file exists, check it matches pip installed packages
      run: |
        if [ -s ${{ inputs.requirements_file }} ]; then
          if ! diff -u ${{ inputs.requirements_file }} lockfiles/${{ inputs.requirements_file }}; then
            echo "Error: ${{ inputs.requirements_file }} need the above changes to be exhaustive"
            exit 1
          fi
        fi
      shell: bash


# dae_devops_fingerprint a5800c88a9ba24077377747d0c06fb25
