name: "Install Python"
description: "Installing an upstream python release"
inputs:
  version:
    description: "Python version"
    required: true
runs:
  using: "composite"
  steps:
    - shell: bash
      run: |
        set -xe
        url="https://www.python.org/ftp/python/${{ inputs.version }}/python-${{ inputs.version }}"
        req_10_9=$(curl -o /dev/null -Isw '%{http_code}\n' "${url}-macosx10.9.pkg")
        if [[ $req_10_9 == "200" ]]; then
          curl -sSL "${url}-macosx10.9.pkg" -o "python.pkg"
        else
          curl -sSL "${url}-macos11.pkg" -o "python.pkg"
        fi
    - shell: bash
      run: ls -hal .
    - shell: bash
      run: |
        set -xe
        sudo installer -verbose -pkg python.pkg -target /
    - shell: bash
      run: |
        set -xe
        which python3
        python3 --version
        python3 -c "import sysconfig; print(sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET'))"
    - shell: bash
      name: Set up venv with upstream Python
      run: |
        python3 -m venv /tmp/venv
        echo "/tmp/venv/bin" >> $GITHUB_PATH
