8000 Add support of pre-release Python versions (#112) · MarcusSaviour/setup-python@306c473 · GitHub
[go: up one dir, main page]

Skip to content

Commit 306c473

Browse files
MaksimZhukovMaksimZhukov
and
MaksimZhukov
authored
Add support of pre-release Python versions (actions#112)
* Add support of unstable Python versions * Update README * Get rid of stable boolean input * Fix typo in the test.yml * Update README Co-authored-by: MaksimZhukov <v-mazhuk@microsoft.com>
1 parent 7a69c2b commit 306c473

File tree

7 files changed

+5911
-5803
lines changed

7 files changed

+5911
-5803
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,32 @@ jobs:
6161

6262
- name: Run simple code
6363
run: python -c 'import math; print(math.factorial(5))'
64+
65+
setup-pre-release-version-from-manifest:
66+
name: Setup 3.9.0-beta.4 ${{ matrix.os }}
67+
runs-on: ${{ matrix.os }}
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
os: [macos-latest, windows-latest, ubuntu-16.04, ubuntu-18.04]
72+
steps:
73+
- name: Checkout
74+
uses: actions/checkout@v2
75+
76+
- name: setup-python 3.9.0-beta.4
77+
uses: ./
78+
with:
79+
python-version: '3.9.0-beta.4'
80+
81+
- name: Validate version
82+
run: |
83+
$pythonVersion = (python --version)
84+
if ("Python 3.9.0b4" -ne "$pythonVersion"){
85+
Write-Host "The current version is $pythonVersion; expected version is 3.9.0b4"
86+
exit 1
87+
}
88+
$pythonVersion
89+
shell: pwsh
90+
91+
- name: Run simple code
92+
run: python -c 'import math; print(math.factorial(5))'

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This action sets up a Python environment for use in actions by:
1616
- Ability to download, install and set up Python packages from `actions/python-versions` that do not come preinstalled on runners
1717
- Allows for pinning to a specific patch version of Python without the worry of it ever being removed or changed
1818
- Automatic setup and download of Python packages if using a self-hosted runner
19+
- Support for pre-release versions of Python
1920

2021
# Usage
2122

@@ -92,6 +93,26 @@ jobs:
9293

9394
```
9495

96+
Download and set up a accurate pre-release version of Python:
97+
```yaml
98+
steps:
99+
- uses: actions/checkout@v2
100+
- uses: actions/setup-python@v2
101+
with:
102+
python-version: '3.9.0-beta.4'
103+
- run: python my_script.py
104+
```
105+
106+
Download and set up the latest available version of Python (includes both pre-release and stable versions):
107+
```yaml
108+
steps:
109+
- uses: actions/checkout@v2
110+
- uses: actions/setup-python@v2
111+
with:
112+
python-version: '3.9.0-alpha - 3.9.0' # SemVer's version range syntax
113+
- run: python my_script.py
114+
```
115+
95116
# Getting started with Python + Actions
96117
97118
Check out our detailed guide on using [Python with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-github-actions).

__tests__/data/python-release.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

__tests__/data/versions-manifest.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[
2+
{
3+
"version": "1.2.3",
4+
"stable": true,
5+
"release_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6",
6+
"files": [
7+
{
8+
"filename": "sometool-1.2.3-linux-x64.tar.gz",
9+
"arch": "x64",
10+
"platform": "linux",
11+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-linux-x64.tar.gz"
12+
},
13+
{
14+
"filename": "sometool-1.2.3-darwin-x64.tar.gz",
15+
"arch": "x64",
16+
"platform": "darwin",
17+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-darwin-x64.tar.gz"
18+
},
19+
{
20+
"filename": "sometool-1.2.3-win32-x64.tar.gz",
21+
"arch": "x64",
22+
"platform": "win32",
23+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.6/sometool-1.2.3-win32-x64.tar.gz"
24+
}
25+
]
26+
},
27+
{
28+
"version": "1.2.3-beta.2",
29+
"stable": false,
30+
"release_url": "https://github.com/actions/sometool/releases/tag/1.2.3-beta.2-20200402.5",
31+
"files": [
32+
{
33+
"filename": "sometool-1.2.3-linux-x64.tar.gz",
34+
"arch": "x64",
35+
"platform": "linux",
36+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-beta.2-20200402.5/sometool-1.2.3-linux-x64.tar.gz"
37+
},
38+
{
39+
"filename": "sometool-1.2.3-darwin-x64.tar.gz",
40+
"arch": "x64",
41+
"platform": "darwin",
42+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.5/sometool-1.2.3-darwin-x64.tar.gz"
43+
},
F438 44+
{
45+
"filename": "sometool-1.2.3-win32-x64.tar.gz",
46+
"arch": "x64",
47+
"platform": "win32",
48+
"download_url": "https://github.com/actions/sometool/releases/tag/1.2.3-20200402.5/sometool-1.2.3-win32-x64.tar.gz"
49+
}
50+
]
51+
}
52+
]

__tests__/finder.test.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import * as tc from '@actions/tool-cache';
2222
import * as finder from '../src/find-python';
2323
import * as installer from '../src/install-python';
2424

25-
const pythonRelease = require('./data/python-release.json');
25+
const manifestData = require('./data/versions-manifest.json');
2626

2727
describe('Finder tests', () => {
2828
afterEach(() => {
@@ -38,12 +38,9 @@ describe('Finder tests', () => {
3838
await finder.findPythonVersion('3.x', 'x64');
3939
});
4040

41-
it('Finds Python if it is not installed, but exists in the manifest', async () => {
42-
const findSpy: jest.SpyInstance = jest.spyOn(
43-
installer,
44-
'findReleaseFromManifest'
45-
);
46-
findSpy.mockImplementation(() => <tc.IToolRelease>pythonRelease);
41+
it('Finds stable Python version if it is not installed, but exists in the manifest', async () => {
42+
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
43+
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);
4744

4845
const installSpy: jest.SpyInstance = jest.spyOn(
4946
installer,
@@ -58,6 +55,28 @@ describe('Finder tests', () => {
5855
await finder.findPythonVersion('1.2.3', 'x64');
5956
});
6057

58+
it('Finds pre-release Python version in the manifest', async () => {
59+
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
60+
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);
61+
62+
const installSpy: jest.SpyInstance = jest.spyOn(
63+
installer,
64+
'installCpythonFromRelease'
65+
);
66+
installSpy.mockImplementation(async () => {
67+
const pythonDir: string = path.join(
68+
toolDir,
69+
'Python',
70+
'1.2.3-beta.2',
71+
'x64'
72+
);
73+
await io.mkdirP(pythonDir);
74+
fs.writeFileSync(`${pythonDir}.complete`, 'hello');
75+
});
76+
// This will throw if it doesn't find it in the manifest (because no such version exists)
77+
await finder.findPythonVersion('1.2.3-beta.2', 'x64');
78+
});
79+
6180
it('Errors if Python is not installed', async () => {
6281
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
6382
let thrown = false;

0 commit comments

Comments
 (0)
0