name: "Install"
description: "Install python, then cache"
inputs:
  python-version:
    description: "Python version"
    required: true
  python-architecture:
    description: "Python architecture, if not default for platform"
  task:
    description: "Task name"
    required: true
runs:
  using: "composite"
  steps:
  - name: Set up Python ${{ inputs.python-version }} ${{ inputs.python-architecture }}
    uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
    with:
      python-version: ${{ inputs.python-version }}
      architecture: ${{ inputs.python-architecture }}
  - name: Set up rust target for 32-bit windows
    # we test 32bit windows by cross-compiling to 32bit from a 64bit host, because we don't
    # have access to a 32bit host on github actions. Set that cross-compilation up now; otherwise,
    # we'll compile as 64bit and try to run against a 32bit python interpreter, and crash.
    if: ${{ inputs.python-architecture == 'x86' }}
    shell: bash
    run: |
      rustup target add i686-pc-windows-msvc
      echo "CARGO_BUILD_TARGET=i686-pc-windows-msvc" >> "$GITHUB_ENV"
  - name: Install dotnet6 for Pyjion
    if: ${{ endsWith(inputs.task, '-pyjion') }}
    shell: bash
    run: |
      wget https://packages.microsoft.com/config/ubuntu/21.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
      sudo dpkg -i packages-microsoft-prod.deb
      rm packages-microsoft-prod.deb
      sudo apt-get update
      sudo apt-get install -y apt-transport-https && \
        sudo apt-get update && \
        sudo apt-get install -y dotnet-sdk-6.0
  - name: Restore cache
    uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
    with:
      path: |
        .tox/
        vendor/bundle
        ~/.cache
        ~/.local
        ~/appdata/local/pip/cache
        ~/Library/Caches/pip
        ~/wheelhouse
        hypothesis/rust/target
      key: deps-${{ runner.os }}-${{ hashFiles('requirements/*.txt') }}-${{ inputs.python-version }}-${{ inputs.python-architecture }}-${{ inputs.task }}
      restore-keys: |
        deps-${{ runner.os }}-${{ hashFiles('requirements/*.txt') }}-${{ inputs.python-version }}-${{ inputs.python-architecture }}
        deps-${{ runner.os }}-${{ hashFiles('requirements/*.txt') }}
        deps-${{ runner.os }}
