|
| 1 | +name: 'Setup Python and pip cache' |
| 2 | +description: 'Setups Python with the provided version and sets up the pip cache' |
| 3 | +inputs: |
| 4 | + version: |
| 5 | + description: 'Python version to install' |
| 6 | + required: true |
| 7 | + pip-cache-path: |
| 8 | + description: 'Path on share where the pip cache is stored' |
| 9 | + required: false |
| 10 | + should-setup-pip-paths: |
| 11 | + description: 'If the action should setup `PIP_CACHE_DIR` & `PIP_INSTALL_PATH` env variables' |
| 12 | + required: false |
| 13 | + default: 'false' |
| 14 | + self-hosted-runner: |
| 15 | + description: 'If the runner is self-hosted' |
| 16 | + required: false |
| 17 | + default: 'true' |
| 18 | +runs: |
| 19 | + using: 'composite' |
| 20 | + steps: |
| 21 | + |
| 22 | + - if: ${{ runner.os == 'Linux' && inputs.self-hosted-runner == 'true' }} |
| 23 | + name: Install 'actions/setup-python@v4' dependencies |
| 24 | + shell: bash |
| 25 | + run: apt-get update && apt-get install -y ca-certificates |
| 26 | + |
| 27 | + - if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} |
| 28 | + name: Setup sudo |
| 29 | + shell: bash |
| 30 | + run: apt-get update && apt-get install -y sudo # Needed for the deadsnakes action |
| 31 | + |
| 32 | + - if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} |
| 33 | + name: Setup Python ${{ inputs.version }} |
| 34 | + uses: deadsnakes/[email protected] |
| 35 | + with: |
| 36 | + python-version: ${{ inputs.version }} |
| 37 | + |
| 38 | + - if: ${{ runner.os == 'macOS' || runner.os == 'Windows' || (runner.os == 'Linux' && runner.arch != 'ARM64') }} |
| 39 | + name: Setup Python ${{ inputs.version }} |
| 40 | + uses: actions/setup-python@v4 |
| 41 | + with: |
| 42 | + python-version: ${{ inputs.version }} |
| 43 | + env: |
| 44 | + PIP_CACHE_DIR: ${{ inputs.self-hosted-runner == 'true' && inputs.pip-cache-path || '' }} |
| 45 | + |
| 46 | + - if: ${{ inputs.should-setup-pip-paths == 'true' }} |
| 47 | + name: Setup pip variables (cache and install path) |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + PIP_VER=$(python3 -c "import pip; print(pip.__version__)") |
| 51 | + echo "Using pip version: ${PIP_VER}" |
| 52 | + echo "PIP_CACHE_DIR=${{ inputs.pip-cache-path }}/${PIP_VER}" >> $GITHUB_ENV |
| 53 | + echo "PIP_INSTALL_PATH=$(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + - if: ${{ inputs.should-setup-pip-paths == 'true' }} |
| 56 | + name: Get pip cache info |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + echo "Cache size: " |
| 60 | + du -h -d2 ${{ env.PIP_CACHE_DIR }} |
| 61 | + echo "Cache info: " |
| 62 | + python3 -m pip cache info |
| 63 | + continue-on-error: true |
0 commit comments