Skip to content

Instantly share code, notes, and snippets.

@bact
Last active November 11, 2024 18:56
Show Gist options
  • Save bact/159b705c4ac0e5eda38119a6361ebdf2 to your computer and use it in GitHub Desktop.
Save bact/159b705c4ac0e5eda38119a6361ebdf2 to your computer and use it in GitHub Desktop.
Convert Python version "3.9" and "pypy3.10" to "cp39" and "pp310" in GitHub Actions
jobs:
build:
steps:
- name: Make Python implementation ID (non-Windows)
id: convert-version-id
if: startsWith(matrix.os, 'windows-') == false
run: |
PYTHON_VERSION=${{ matrix.python-version }}
if [[ "$PYTHON_VERSION" == pypy* ]]; then
CP_VER="pp${PYTHON_VERSION:4}"
CP_VER="${CP_VER//./}"
else
CP_VER="cp${PYTHON_VERSION//./}"
fi
echo "Python version: $CP_VER"
echo "CP_VER=$CP_VER" >> $GITHUB_ENV
- name: Make Python implementation ID (Windows)
id: convert-version-id-win
if: startsWith(matrix.os, 'windows-')
shell: powershell
run: |
$PYTHON_VERSION = "${{ matrix.python-version }}"
if ($PYTHON_VERSION -like "pypy*") {
$CP_VER = "pp" + $PYTHON_VERSION.Substring(4).Replace(".", "")
} else {
$CP_VER = "cp" + $PYTHON_VERSION.Replace(".", "")
}
echo "Python version: $CP_VER"
echo "CP_VER=$CP_VER" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment