Skip to content

Commit

Permalink
Support explicit "latest" version
Browse files Browse the repository at this point in the history
Closes #139
  • Loading branch information
jakebailey committed Aug 22, 2024
1 parent c1dc810 commit f6f691c
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9908,6 +9908,9 @@ async function getPyrightVersion() {
if (versionSpec.toUpperCase() === "PATH") {
return "PATH";
}
if (versionSpec === "latest") {
return "latest";
}
return new import_semver2.SemVer(versionSpec);
}
const pylanceVersion = core.getInput("pylance-version");
Expand Down
135 changes: 135 additions & 0 deletions src/__snapshots__/helpers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4109,6 +4109,141 @@ exports[`getArgs > valid version > verifytypes flag > tc.find 1`] = `
exports[`getArgs > valid version > verifytypes flag > which.sync 1`] = `[]`;
exports[`getArgs > valid version > version latest > core.getInput 1`] = `
[
[
"annotate",
],
[
"create-stub",
],
[
"dependencies",
],
[
"extra-args",
],
[
"ignore-external",
],
[
"level",
],
[
"lib",
],
[
"no-comments",
],
[
"project",
],
[
"python-path",
],
[
"python-platform",
],
[
"python-version",
],
[
"skip-unannotated",
],
[
"stats",
],
[
"typeshed-path",
],
[
"venv-path",
],
[
"verbose",
],
[
"verify-types",
],
[
"version",
],
[
"warnings",
],
[
"working-directory",
],
]
`;
exports[`getArgs > valid version > version latest > cp.execFileSync 1`] = `[]`;
exports[`getArgs > valid version > version latest > result 1`] = `
{
"annotate": Set {
"error",
"warning",
},
"args": [
"<TEMP_DIR>/rootDir/cached/pyright/package/index.js",
],
"command": "<execPath>",
"pyrightVersion": SemVer {
"build": [],
"loose": false,
"major": 1,
"minor": 1,
"options": {
"includePrerelease": false,
"loose": false,
},
"patch": 240,
"prerelease": [],
"raw": "1.1.240",
"version": "1.1.240",
},
"workingDirectory": "",
}
`;
exports[`getArgs > valid version > version latest > tc.cacheDir 1`] = `
[
[
"<TEMP_DIR>/rootDir/pyright",
"pyright",
"1.1.240",
],
]
`;
exports[`getArgs > valid version > version latest > tc.downloadTool 1`] = `
[
[
"https://registry.npmjs.org/pyright/-/pyright-1.1.240.tgz",
],
]
`;
exports[`getArgs > valid version > version latest > tc.extractTar 1`] = `
[
[
"<TEMP_DIR>/rootDir/pyright.tar.gz",
],
]
`;
exports[`getArgs > valid version > version latest > tc.find 1`] = `
[
[
"pyright",
"1.1.240",
],
]
`;
exports[`getArgs > valid version > version latest > which.sync 1`] = `[]`;
exports[`getArgs > valid version > version not found > core.getInput 1`] = `
[
[
Expand Down
10 changes: 10 additions & 0 deletions src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ describe("getArgs", () => {
expect(result).toMatchSnapshot("result");
});

test("version latest", async () => {
inputs.set("version", "latest");

const result = await getArgs(execPath);
expect(result).toMatchSnapshot("result");

expect(mockedTc.downloadTool).toBeCalledWith(getNpmResponse(latestPyright).dist.tarball);
expect(mockedTc.extractTar).toBeCalledWith(tarballPath);
});

test("version not found", async () => {
inputs.set("version", "999.999.404");
await expect(getArgs(execPath)).rejects.toThrowError("version not found: 999.999.404");
Expand Down
3 changes: 3 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ async function getPyrightVersion(): Promise<SemVer | "PATH" | "latest"> {
if (versionSpec.toUpperCase() === "PATH") {
return "PATH";
}
if (versionSpec === "latest") {
return "latest";
}
return new SemVer(versionSpec);
}

Expand Down

0 comments on commit f6f691c

Please sign in to comment.