diff --git a/.github/actions/setup-environment-action/action.yml b/.github/actions/setup-environment-action/action.yml index f101133b5f7c..b37d30953ed9 100644 --- a/.github/actions/setup-environment-action/action.yml +++ b/.github/actions/setup-environment-action/action.yml @@ -56,6 +56,24 @@ runs: sdks/python/setup.py sdks/python/tox.ini + # Multiline python-version (e.g. 3.10\n3.11\n...) must not be embedded raw + # in cache keys: actions/cache treats each newline-separated line as a + # separate key and fails when there are more than 10 ("Keys are limited to + # a maximum of 10"). Collapse whitespace into a single key fragment. + - name: Sanitize Python version for tox cache key + if: ${{ inputs.python-version != '' && inputs.tox-cache == 'true' }} + id: py-cache-key + shell: bash + env: + PYTHON_VERSION_INPUT: ${{ inputs.python-version }} + run: | + if [[ "$PYTHON_VERSION_INPUT" == "default" ]]; then + sanitized="310" + else + sanitized=$(printf '%s' "$PYTHON_VERSION_INPUT" | tr -s '[:space:]' '-' | sed 's/^-//;s/-$//') + fi + echo "sanitized=$sanitized" >> "$GITHUB_OUTPUT" + - name: Cache tox environments if: ${{ inputs.python-version != '' && inputs.tox-cache == 'true' }} uses: actions/cache@v6 @@ -64,10 +82,10 @@ runs: sdks/python/target/.tox !sdks/python/target/.tox/**/log !sdks/python/target/.tox/.package_cache - key: tox-${{ runner.os }}-py${{ inputs.python-version == 'default' && '310' || inputs.python-version }}-${{ hashFiles('sdks/python/tox.ini') }}-${{ hashFiles('sdks/python/setup.py') }} + key: tox-${{ runner.os }}-py${{ steps.py-cache-key.outputs.sanitized }}-${{ hashFiles('sdks/python/tox.ini') }}-${{ hashFiles('sdks/python/setup.py') }} restore-keys: | - tox-${{ runner.os }}-py${{ inputs.python-version == 'default' && '310' || inputs.python-version }}-${{ hashFiles('sdks/python/tox.ini') }}- - tox-${{ runner.os }}-py${{ inputs.python-version == 'default' && '310' || inputs.python-version }}- + tox-${{ runner.os }}-py${{ steps.py-cache-key.outputs.sanitized }}-${{ hashFiles('sdks/python/tox.ini') }}- + tox-${{ runner.os }}-py${{ steps.py-cache-key.outputs.sanitized }}- - name: Install Java if: ${{ inputs.java-version != '' }} diff --git a/.github/workflows/update_python_dependencies.yml b/.github/workflows/update_python_dependencies.yml index f8630ebd0aec..b934f402067c 100644 --- a/.github/workflows/update_python_dependencies.yml +++ b/.github/workflows/update_python_dependencies.yml @@ -69,6 +69,8 @@ jobs: java-version: default go-version: default disable-cache: true + # generatePythonRequirementsAll does not use tox. + tox-cache: false - name: Update Python Dependencies uses: ./.github/actions/gradle-command-self-hosted-action with: