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 licenses
  • Loading branch information
dmitry-shibanov committed May 9, 2022
commit 381a73b90e3723733951097a61680c255006e70b
2 changes: 1 addition & 1 deletion .licenses/npm/@actions/core.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions .licenses/npm/@actions/http-client-1.0.8.dep.yml

This file was deleted.

22 changes: 10 additions & 12 deletions __tests__/finder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Finder tests', () => {

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

const pythonDir: string = path.join(toolDir, 'Python', '3.0.0', 'x64');
await io.mkdirP(pythonDir);
Expand All @@ -48,7 +48,7 @@ describe('Finder tests', () => {
findSpy.mockImplementation(() => <tc.IToolRelease[]>manifestData);

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

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

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

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

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

const cnSpy: jest.SpyInstance = jest.spyOn(process.stdout, 'write');
cnSpy.mockImplementation(line => {
Expand All @@ -102,14 +102,10 @@ describe('Finder tests', () => {
});

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

});
infoSpy.mockImplementation(() => {});

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

});
debugSpy.mockImplementation(() => {});

const pythonDir: string = path.join(toolDir, 'Python', '1.2.2', 'x64');
const expPath: string = path.join(toolDir, 'Python', '1.2.3', 'x64');
Expand All @@ -125,13 +121,15 @@ describe('Finder tests', () => {

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', true);

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

Expand Down
2 changes: 1 addition & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9752,7 +9752,7 @@ const utils_1 = __webpack_require__(163);
function installPyPy(pypyVersion, pythonVersion, architecture, releases) {
return __awaiter(this, void 0, void 0, function* () {
let downloadDir;
releases !== null && releases !== void 0 ? releases : (releases = yield getAvailablePyPyVersions());
releases = releases !== null && releases !== void 0 ? releases : (yield getAvailablePyPyVersions());
if (!releases || releases.length === 0) {
throw new Error('No release was found in PyPy version.json');
}
Expand Down
10 changes: 7 additions & 3 deletions src/find-pypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ export async function findPyPyVersion(
architecture
);

if(releaseData) {
core.info(`Resolved as PyPy ${releaseData.resolvedPyPyVersion} with Python (${releaseData.resolvedPythonVersion})`);
if (releaseData) {
core.info(
`Resolved as PyPy ${releaseData.resolvedPyPyVersion} with Python (${releaseData.resolvedPythonVersion})`
);
pypyVersionSpec.pythonVersion = releaseData.resolvedPythonVersion;
pypyVersionSpec.pypyVersion = releaseData.resolvedPyPyVersion;
} else {
core.info(`Failed to resolve PyPy ${pypyVersionSpec.pypyVersion} with Python (${pypyVersionSpec.pythonVersion}) from manifest`);
core.info(
`Failed to resolve PyPy ${pypyVersionSpec.pypyVersion} with Python (${pypyVersionSpec.pythonVersion}) from manifest`
);
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/find-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ export async function useCpythonVersion(

if (checkLatest) {
manifest = await installer.getManifest();
const resolvedVersion = (await installer.findReleaseFromManifest(semanticVersionSpec, architecture, manifest))?.version;

if(resolvedVersion) {
const resolvedVersion = (
await installer.findReleaseFromManifest(
semanticVersionSpec,
architecture,
manifest
)
)?.version;

if (resolvedVersion) {
semanticVersionSpec = resolvedVersion;
core.info(`Resolved as '${semanticVersionSpec}'`);
} else {
core.info(`Failed to resolve version ${semanticVersionSpec} from manifest`);
core.info(
`Failed to resolve version ${semanticVersionSpec} from manifest`
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/install-pypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export async function installPyPy(
) {
let downloadDir;

releases ??= await getAvailablePyPyVersions();
releases = releases ?? (await getAvailablePyPyVersions());

if (!releases || releases.length === 0) {
throw new Error('No release was found in PyPy version.json');
}
Expand Down
13 changes: 10 additions & 3 deletions src/install-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function findReleaseFromManifest(
architecture: string,
manifest: tc.IToolRelease[] | null
): Promise<tc.IToolRelease | undefined> {
if(!manifest) {
if (!manifest) {
manifest = await getManifest();
}

Expand All @@ -32,8 +32,15 @@ export async function findReleaseFromManifest(
}

export function getManifest(): Promise<tc.IToolRelease[]> {
core.debug(`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`);
return tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
core.debug(
`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`
);
return tc.getManifestFromRepo(
MANIFEST_REPO_OWNER,
MANIFEST_REPO_NAME,
AUTH,
MANIFEST_REPO_BRANCH
);
}

async function installPython(workingDirectory: string) {
Expand Down
12 changes: 10 additions & 2 deletions src/setup-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ async function run() {
let pythonVersion: string;
const arch: string = core.getInput('architecture') || os.arch();
if (isPyPyVersion(version)) {
const installed = await finderPyPy.findPyPyVersion(version, arch, checkLatest);
const installed = await finderPyPy.findPyPyVersion(
version,
arch,
checkLatest
);
pythonVersion = `${installed.resolvedPyPyVersion}-${installed.resolvedPythonVersion}`;
core.info(
`Successfully set up PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`
);
} else {
const installed = await finder.useCpythonVersion(version, arch, checkLatest);
const installed = await finder.useCpythonVersion(
version,
arch,
checkLatest
);
pythonVersion = installed.version;
core.info(`Successfully set up ${installed.impl} (${pythonVersion})`);
}
Expand Down
0