Skip to content

Commit f6c7a06

Browse files
authored
Fix Update Python Dependencies (#39534)
* Fix Update Python Dependencies * update tox-cache comment
1 parent b5c6009 commit f6c7a06

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

.github/actions/setup-environment-action/action.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ runs:
5656
sdks/python/setup.py
5757
sdks/python/tox.ini
5858
59+
# Multiline python-version (e.g. 3.10\n3.11\n...) must not be embedded raw
60+
# in cache keys: actions/cache treats each newline-separated line as a
61+
# separate key and fails when there are more than 10 ("Keys are limited to
62+
# a maximum of 10"). Collapse whitespace into a single key fragment.
63+
- name: Sanitize Python version for tox cache key
64+
if: ${{ inputs.python-version != '' && inputs.tox-cache == 'true' }}
65+
id: py-cache-key
66+
shell: bash
67+
env:
68+
PYTHON_VERSION_INPUT: ${{ inputs.python-version }}
69+
run: |
70+
if [[ "$PYTHON_VERSION_INPUT" == "default" ]]; then
71+
sanitized="310"
72+
else
73+
sanitized=$(printf '%s' "$PYTHON_VERSION_INPUT" | tr -s '[:space:]' '-' | sed 's/^-//;s/-$//')
74+
fi
75+
echo "sanitized=$sanitized" >> "$GITHUB_OUTPUT"
76+
5977
- name: Cache tox environments
6078
if: ${{ inputs.python-version != '' && inputs.tox-cache == 'true' }}
6179
uses: actions/cache@v6
@@ -64,10 +82,10 @@ runs:
6482
sdks/python/target/.tox
6583
!sdks/python/target/.tox/**/log
6684
!sdks/python/target/.tox/.package_cache
67-
key: tox-${{ runner.os }}-py${{ inputs.python-version == 'default' && '310' || inputs.python-version }}-${{ hashFiles('sdks/python/tox.ini') }}-${{ hashFiles('sdks/python/setup.py') }}
85+
key: tox-${{ runner.os }}-py${{ steps.py-cache-key.outputs.sanitized }}-${{ hashFiles('sdks/python/tox.ini') }}-${{ hashFiles('sdks/python/setup.py') }}
6886
restore-keys: |
69-
tox-${{ runner.os }}-py${{ inputs.python-version == 'default' && '310' || inputs.python-version }}-${{ hashFiles('sdks/python/tox.ini') }}-
70-
tox-${{ runner.os }}-py${{ inputs.python-version == 'default' && '310' || inputs.python-version }}-
87+
tox-${{ runner.os }}-py${{ steps.py-cache-key.outputs.sanitized }}-${{ hashFiles('sdks/python/tox.ini') }}-
88+
tox-${{ runner.os }}-py${{ steps.py-cache-key.outputs.sanitized }}-
7189
7290
- name: Install Java
7391
if: ${{ inputs.java-version != '' }}

.github/workflows/update_python_dependencies.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ jobs:
6969
java-version: default
7070
go-version: default
7171
disable-cache: true
72+
# generatePythonRequirementsAll does not use tox.
73+
tox-cache: false
7274
- name: Update Python Dependencies
7375
uses: ./.github/actions/gradle-command-self-hosted-action
7476
with:

0 commit comments

Comments
 (0)