8000 Add check-latest functionality by dmitry-shibanov · Pull Request #406 · actions/setup-python · GitHub
[go: up one dir, main page]

Skip to content

Add check-latest functionality #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
58a8109
add check-latest for python versions
dmitry-shibanov May 4, 2022
8723b8a
add check-latest for pypy
dmitry-shibanov May 6, 2022
7339590
add check-latest to the documentation
dmitry-shibanov May 9, 2022
381a73b
add licenses
dmitry-shibanov May 9, 2022
62079db
fix tests
dmitry-shibanov May 9, 2022
4841389
add check-latest for python versions
dmitry-shibanov May 4, 2022
73adf61
add check-latest for pypy
dmitry-shibanov May 6, 2022
71940d6
add check-latest to the documentation
dmitry-shibanov May 9, 2022
5dd8329
add licenses
dmitry-shibanov May 9, 2022
ee3a254
fix tests
dmitry-shibanov May 9, 2022
f50cbbf
Merge branch 'v-dmshib/add-check-latest' of https://github.com/dmitry…
dmitry-shibanov May 9, 2022
ca41e9d
fix tests
dmitry-shibanov May 9, 2022
bd01c0d
fix tests
dmitry-shibanov May 9, 2022
d43033c
add mock
dmitry-shibanov May 9, 2022
0c0e574
run format
dmitry-shibanov May 9, 2022
0753db1
fix tests
dmitry-shibanov May 9, 2022
ea1d6e9
Merge branch 'main' into v-dmshib/add-check-latest
dmitry-shibanov May 24, 2022
86e88a6
Merge branch 'main' into v-dmshib/add-check-latest
dmitry-shibanov May 31, 2022
6d01ca9
Merge branch 'main' into v-dmshib/add-check-latest
dmitry-shibanov Jun 15, 2022
614f5d9
rebuild dist
dmitry-shibanov Jun 15, 2022
0e03ef2
fix test-python.yml
dmitry-shibanov Jun 15, 2022
de4dd60
Merge branch 'main' into v-dmshib/add-check-latest
dmitry-shibanov Jul 7, 2022
2718326
resolve conflicts
dmitry-shibanov Jul 7, 2022
72e092b
format code
dmitry-shibanov Jul 7, 2022
1c2a569
Merge branch 'main' into v-dmshib/add-check-latest
dmitry-shibanov Jul 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add check-latest for python versions
  • Loading branch information
dmitry-shibanov committed May 9, 2022
commit 4841389b470d15d781fd39a2bf1711c2cde4c3b4
23 changes: 23 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,26 @@ jobs:
- name: Run simple code
run: python -c 'import math; print(math.factorial(5))'

check-latest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Setup Python and check latest
uses: ./
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Validate version
run: |
$pythonVersion = (python --version)
if ("$pythonVersion" -NotMatch "${{ matrix.python }}"){
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
exit 1
}
$pythonVersion
shell: pwsh
64 changes: 61 additions & 3 deletions __tests__/finder.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import io = require('@actions/io');
import fs = require('fs');
import path = require('path');
import * as io from '@actions/io';
const fs = require('fs');
const path = require('path');
const os = require('os');

const toolDir = path.join(
__dirname,
Expand All @@ -19,6 +20,7 @@ process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;

import * as tc from '@actions/tool-cache';
import * as core from '@actions/core';
import * as finder from '../src/find-python';
import * as installer from '../src/install-python';

Expand All @@ -31,6 +33,9 @@ describe('Finder tests', () => {
});

it('Finds Python if it is installed', async () => {
const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation((input) => false);

const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64');
await io.mkdirP(pythonDir);
fs.writeFileSync(`${pythonDir}.complete`, 'hello');
Expand All @@ -42,6 +47,9 @@ describe('Finder tests', () => {
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);

const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation((input) => false);

const installSpy: jest.SpyInstance = jest.spyOn(
installer,
'installCpythonFromRelease'
Expand All @@ -59,6 +67,9 @@ describe('Finder tests', () => {
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);

const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation((input) => false);

const installSpy: jest.SpyInstance = jest.spyOn(
installer,
'installCpythonFromRelease'
Expand All @@ -77,6 +88,53 @@ describe('Finder tests', () => {
await finder.useCpythonVersion('1.2.3-beta.2', 'x64');
});

it('Check-latest true, finds the latest version in the manifest', async () => {
const findSpy: jest.SpyInstance = jest.spyOn(tc, 'getManifestFromRepo');
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);

const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
getBooleanInputSpy.mockImplementation((input) => true);

const cnSpy: jest.SpyInstance = jest.spyOn(process.stdout, 'write');
cnSpy.mockImplementation(line => {
// uncomment to debug
// process.stderr.write('write:' + line + '\n');
});

const infoSpy: jest.SpyInstance = jest.spyOn(core, 'info');
infoSpy.mockImplementation(() => {

});

const debugSpy: jest.SpyInstance = jest.spyOn(core, 'debug');
debugSpy.mockImplementation(() => {

});

const pythonDir: string = path.join(toolDir, 'Python', '1.2.2', 'x64');
const expPath: string = path.join(toolDir, 'Python', '1.2.3', 'x64');

const installSpy: jest.SpyInstance = jest.spyOn(
installer,
'installCpythonFromRelease'
);
installSpy.mockImplementation(async () => {
await io.mkdirP(expPath);
fs.writeFileSync(`${expPath}.complete`, 'hello');
});

await io.mkdirP(pythonDir);
await io.rmRF(expPath);

fs.writeFileSync(`${pythonDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
await finder.useCpythonVersion('1.2', 'x64');

expect(infoSpy).toHaveBeenCalledWith("Resolved as '1.2.3'");
expect(infoSpy).toHaveBeenCalledWith('Version 1.2.3 was not found in the local cache');
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${os.EOL}`);
});

it('Errors if Python is not installed', async () => {
// This will throw if it doesn't find it in the cache and in the manifest (because no such version exists)
let thrown = false;
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
required: false
architecture:
description: 'The target architecture (x86, x64) of the Python interpreter.'
check-latest:
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.'
default: false
token:
description: Used to pull python distributions from actions/python-versions. Since there's a default, this is typically not supplied by the user.
default: ${{ github.token }}
Expand Down
Loading
0