From d09bd5e6005b175076f227b13d9730d56e9dcfcb Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Wed, 8 Jun 2022 14:58:05 +0200 Subject: [PATCH] fix: 3.x-dev can install a 3.y version (#417) * fix: 3.x-dev can install a 3.y version * Update README section for `-dev` --- .github/workflows/test-python.yml | 29 ++++++++++++++++++++++++++++- README.md | 2 +- dist/setup/index.js | 11 +++-------- src/find-python.ts | 10 +++------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 02835a9..e0d9a47 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -1,5 +1,5 @@ name: Validate Python e2e -on: +on: push: branches: - main @@ -120,3 +120,30 @@ jobs: - name: Run simple code run: python -c 'import math; print(math.factorial(5))' + setup-dev-version: + name: Setup 3.9-dev ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: setup-python 3.9-dev + id: setup-python + uses: ./ + with: + python-version: '3.9-dev' + + - name: Check python-path + run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}' + shell: bash + + - name: Validate version + run: ${{ startsWith(steps.setup-python.outputs.python-version, '3.9.') }} + shell: bash + + - name: Run simple code + run: python -c 'import math; print(math.factorial(5))' diff --git a/README.md b/README.md index 56103e5..dbc7d43 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Check out our detailed guide on using [Python with GitHub Actions](https://help. - For every minor version of Python, expect only the latest patch to be preinstalled. - If `3.8.1` is installed for example, and `3.8.2` is released, expect `3.8.1` to be removed and replaced by `3.8.2` in the tools cache. - If the exact patch version doesn't matter to you, specifying just the major and minor version will get you the latest preinstalled patch version. In the previous example, the version spec `3.8` will use the `3.8.2` Python version found in the cache. - - Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest release of a minor version, *alpha and beta releases included*. + - Use `-dev` instead of a patch number (e.g., `3.11-dev`) to install the latest patch version release for a given minor version, *alpha and beta releases included*. - Downloadable Python versions from GitHub Releases ([actions/python-versions](https://github.com/actions/python-versions/releases)). - All available versions are listed in the [version-manifest.json](https://github.com/actions/python-versions/blob/main/versions-manifest.json) file. - If there is a specific version of Python that is not available, you can open an issue here diff --git a/dist/setup/index.js b/dist/setup/index.js index 7e26733..0d98b66 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -64183,15 +64183,10 @@ function useCpythonVersion(version, architecture) { }); } exports.useCpythonVersion = useCpythonVersion; -/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */ +/** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */ function desugarDevVersion(versionSpec) { - if (versionSpec.endsWith('-dev')) { - const versionRoot = versionSpec.slice(0, -'-dev'.length); - return `>= ${versionRoot}.0-a0`; - } - else { - return versionSpec; - } + const devVersion = /^(\d+)\.(\d+)-dev$/; + return versionSpec.replace(devVersion, '~$1.$2.0-0'); } /** Extracts python version from install path from hosted tool cache as described in README.md */ function versionFromPath(installDir) { diff --git a/src/find-python.ts b/src/find-python.ts index 0a3dde1..f1dad3a 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -117,14 +117,10 @@ export async function useCpythonVersion( return {impl: 'CPython', version: installed}; } -/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */ +/** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */ function desugarDevVersion(versionSpec: string) { - if (versionSpec.endsWith('-dev')) { - const versionRoot = versionSpec.slice(0, -'-dev'.length); - return `>= ${versionRoot}.0-a0`; - } else { - return versionSpec; - } + const devVersion = /^(\d+)\.(\d+)-dev$/; + return versionSpec.replace(devVersion, '~$1.$2.0-0'); } /** Extracts python version from install path from hosted tool cache as described in README.md */