name: 'Setup Python and pip cache' description: 'Setups Python with the provided version and sets up the pip cache' inputs: version: description: 'Python version to install' required: true pip-cache-path: description: 'Path on share where the pip cache is stored' required: false should-setup-pip-paths: description: 'If the action should setup `PIP_CACHE_DIR` & `PIP_INSTALL_PATH` env variables' required: false default: 'false' self-hosted-runner: description: 'If the runner is self-hosted' required: false default: 'true' runs: using: 'composite' steps: - if: ${{ runner.os == 'Linux' && inputs.self-hosted-runner == 'true' }} name: Install 'actions/setup-python@v4' dependencies shell: bash run: apt-get update && apt-get install -y ca-certificates - if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} name: Setup sudo shell: bash run: apt-get update && apt-get install -y sudo # Needed for the deadsnakes action - if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} name: Setup Python ${{ inputs.version }} uses: deadsnakes/action@v3.0.1 with: python-version: ${{ inputs.version }} - if: ${{ runner.os == 'macOS' || runner.os == 'Windows' || (runner.os == 'Linux' && runner.arch != 'ARM64') }} name: Setup Python ${{ inputs.version }} uses: actions/setup-python@v4 with: python-version: ${{ inputs.version }} env: PIP_CACHE_DIR: ${{ inputs.self-hosted-runner == 'true' && inputs.pip-cache-path || '' }} - if: ${{ inputs.should-setup-pip-paths == 'true' }} name: Setup pip variables (cache and install path) shell: bash run: | PIP_VER=$(python3 -c "import pip; print(pip.__version__)") echo "Using pip version: ${PIP_VER}" echo "PIP_CACHE_DIR=${{ inputs.pip-cache-path }}/${PIP_VER}" >> $GITHUB_ENV echo "PIP_INSTALL_PATH=$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')" >> $GITHUB_ENV - if: ${{ inputs.should-setup-pip-paths == 'true' }} name: Get pip cache info shell: bash run: | echo "Cache size: " du -h -d2 ${{ env.PIP_CACHE_DIR }} echo "Cache info: " python3 -m pip cache info continue-on-error: true