Skip to content

Commit

Permalink
fix: 3.x-dev can install a 3.y version (#417)
Browse files Browse the repository at this point in the history
* fix: 3.x-dev can install a 3.y version

* Update README section for `-dev`
  • Loading branch information
mayeut authored Jun 8, 2022
1 parent f72db17 commit d09bd5e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Validate Python e2e
on:
on:
push:
branches:
- main
Expand Down Expand Up @@ -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))'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 3 additions & 7 deletions src/find-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit d09bd5e

Please sign in to comment.