Skip to content
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

Add pylance-version option #63

Merged
merged 19 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ branding:
inputs:
# Options for pyright-action
version:
description: 'Version of pyright to run. If not specified, the latest version will be used.'
description: 'Version of pyright to run. If neither version nor pylance-version are specified, the latest version will be used.'
required: false
pylance-version:
description: 'Version of pylance whose pyright version should be run. Can be latest-release, latest-prerelease, or a specific pylance version. Ignored if version option is specified.'
required: false
working-directory:
description: 'Directory to run pyright in. If not specified, the repo root will be used.'
Expand Down
98 changes: 63 additions & 35 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,12 +1154,12 @@ var require_lib = __commonJS({
throw new Error("Client has already been disposed.");
}
const parsedUrl = new URL(requestUrl);
let info2 = this._prepareRequest(verb, parsedUrl, headers);
let info3 = this._prepareRequest(verb, parsedUrl, headers);
const maxTries = this._allowRetries && RetryableHttpVerbs.includes(verb) ? this._maxRetries + 1 : 1;
let numTries = 0;
let response;
do {
response = yield this.requestRaw(info2, data);
response = yield this.requestRaw(info3, data);
if (response && response.message && response.message.statusCode === HttpCodes2.Unauthorized) {
let authenticationHandler;
for (const handler of this.handlers) {
Expand All @@ -1169,7 +1169,7 @@ var require_lib = __commonJS({
}
}
if (authenticationHandler) {
return authenticationHandler.handleAuthentication(this, info2, data);
return authenticationHandler.handleAuthentication(this, info3, data);
} else {
return response;
}
Expand All @@ -1192,8 +1192,8 @@ var require_lib = __commonJS({
}
}
}
info2 = this._prepareRequest(verb, parsedRedirectUrl, headers);
response = yield this.requestRaw(info2, data);
info3 = this._prepareRequest(verb, parsedRedirectUrl, headers);
response = yield this.requestRaw(info3, data);
redirectsRemaining--;
}
if (!response.message.statusCode || !HttpResponseRetryCodes.includes(response.message.statusCode)) {
Expand Down Expand Up @@ -1222,7 +1222,7 @@ var require_lib = __commonJS({
* @param info
* @param data
*/
requestRaw(info2, data) {
requestRaw(info3, data) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
function callbackForResult(err, res) {
Expand All @@ -1234,7 +1234,7 @@ var require_lib = __commonJS({
resolve(res);
}
}
this.requestRawWithCallback(info2, data, callbackForResult);
this.requestRawWithCallback(info3, data, callbackForResult);
});
});
}
Expand All @@ -1244,12 +1244,12 @@ var require_lib = __commonJS({
* @param data
* @param onResult
*/
requestRawWithCallback(info2, data, onResult) {
requestRawWithCallback(info3, data, onResult) {
if (typeof data === "string") {
if (!info2.options.headers) {
info2.options.headers = {};
if (!info3.options.headers) {
info3.options.headers = {};
}
info2.options.headers["Content-Length"] = Buffer.byteLength(data, "utf8");
info3.options.headers["Content-Length"] = Buffer.byteLength(data, "utf8");
}
let callbackCalled = false;
function handleResult(err, res) {
Expand All @@ -1258,7 +1258,7 @@ var require_lib = __commonJS({
onResult(err, res);
}
}
const req = info2.httpModule.request(info2.options, (msg) => {
const req = info3.httpModule.request(info3.options, (msg) => {
const res = new HttpClientResponse(msg);
handleResult(void 0, res);
});
Expand All @@ -1270,7 +1270,7 @@ var require_lib = __commonJS({
if (socket) {
socket.end();
}
handleResult(new Error(`Request timeout: ${info2.options.path}`));
handleResult(new Error(`Request timeout: ${info3.options.path}`));
});
req.on("error", function(err) {
handleResult(err);
Expand All @@ -1297,27 +1297,27 @@ var require_lib = __commonJS({
return this._getAgent(parsedUrl);
}
_prepareRequest(method, requestUrl, headers) {
const info2 = {};
info2.parsedUrl = requestUrl;
const usingSsl = info2.parsedUrl.protocol === "https:";
info2.httpModule = usingSsl ? https : http;
const info3 = {};
info3.parsedUrl = requestUrl;
const usingSsl = info3.parsedUrl.protocol === "https:";
info3.httpModule = usingSsl ? https : http;
const defaultPort = usingSsl ? 443 : 80;
info2.options = {};
info2.options.host = info2.parsedUrl.hostname;
info2.options.port = info2.parsedUrl.port ? parseInt(info2.parsedUrl.port) : defaultPort;
info2.options.path = (info2.parsedUrl.pathname || "") + (info2.parsedUrl.search || "");
info2.options.method = method;
info2.options.headers = this._mergeHeaders(headers);
info3.options = {};
info3.options.host = info3.parsedUrl.hostname;
info3.options.port = info3.parsedUrl.port ? parseInt(info3.parsedUrl.port) : defaultPort;
info3.options.path = (info3.parsedUrl.pathname || "") + (info3.parsedUrl.search || "");
info3.options.method = method;
info3.options.headers = this._mergeHeaders(headers);
if (this.userAgent != null) {
info2.options.headers["user-agent"] = this.userAgent;
info3.options.headers["user-agent"] = this.userAgent;
}
info2.options.agent = this._getAgent(info2.parsedUrl);
info3.options.agent = this._getAgent(info3.parsedUrl);
if (this.handlers) {
for (const handler of this.handlers) {
handler.prepareRequest(info2.options);
handler.prepareRequest(info3.options);
}
}
return info2;
return info3;
}
_mergeHeaders(headers) {
if (this.requestOptions && this.requestOptions.headers) {
Expand Down Expand Up @@ -2161,10 +2161,10 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
command_1.issueCommand("notice", utils_1.toCommandProperties(properties), message instanceof Error ? message.toString() : message);
}
exports.notice = notice;
function info2(message) {
function info3(message) {
process.stdout.write(message + os.EOL);
}
exports.info = info2;
exports.info = info3;
function startGroup(name) {
command_1.issue("group", name);
}
Expand Down Expand Up @@ -6997,6 +6997,13 @@ var NpmRegistryResponse = object({
function parseNpmRegistryResponse(v) {
return NpmRegistryResponse.parse(v, { mode: "strip" });
}
var PylanceBuildMetadata = object({
pylanceVersion: string().assert(isSemVer, "must be a semver"),
pyrightVersion: string().assert(isSemVer, "must be a semver")
});
function parsePylanceBuildMetadata(v) {
return PylanceBuildMetadata.parse(v, { mode: "strip" });
}

// src/helpers.ts
function getActionVersion() {
Expand Down Expand Up @@ -7120,17 +7127,17 @@ function getBooleanInput(name, defaultValue) {
return input.toUpperCase() === "TRUE";
}
var pyrightToolName = "pyright";
async function downloadPyright(info2) {
const found = tc.find(pyrightToolName, info2.version);
async function downloadPyright(info3) {
const found = tc.find(pyrightToolName, info3.version);
if (found) {
return found;
}
const tarballPath = await tc.downloadTool(info2.dist.tarball);
const tarballPath = await tc.downloadTool(info3.dist.tarball);
const extractedPath = await tc.extractTar(tarballPath);
return await tc.cacheDir(extractedPath, pyrightToolName, info2.version);
return await tc.cacheDir(extractedPath, pyrightToolName, info3.version);
}
async function getPyrightInfo() {
const version3 = getPyrightVersion();
const version3 = await getPyrightVersion();
const client = new httpClient.HttpClient();
const resp = await client.get(`https://registry.npmjs.org/pyright/${version3}`);
const body = await resp.readBody();
Expand All @@ -7139,13 +7146,34 @@ async function getPyrightInfo() {
}
return parseNpmRegistryResponse(JSON.parse(body));
}
function getPyrightVersion() {
async function getPyrightVersion() {
const versionSpec = core.getInput("version");
if (versionSpec) {
return new import_semver2.default(versionSpec).format();
}
const pylanceVersion = core.getInput("pylance-version");
if (pylanceVersion) {
if (pylanceVersion !== "latest-release" && pylanceVersion !== "latest-prerelease") {
new import_semver2.default(pylanceVersion);
}
return await getPylancePyrightVersion(pylanceVersion);
}
return "latest";
}
async function getPylancePyrightVersion(pylanceVersion) {
const client = new httpClient.HttpClient();
const resp = await client.get(
`https://raw.githubusercontent.com/microsoft/pylance-release/main/builds/${pylanceVersion}.json`
);
const body = await resp.readBody();
if (resp.message.statusCode !== httpClient.HttpCodes.OK) {
throw new Error(`Failed to download build metadata for Pylance ${pylanceVersion} -- ${body}`);
}
const buildMetadata = parsePylanceBuildMetadata(JSON.parse(body));
const pyrightVersion = buildMetadata.pyrightVersion;
core.info(`Pylance ${pylanceVersion} uses pyright ${pyrightVersion}`);
return pyrightVersion;
}

// src/main.ts
function printInfo(pyrightVersion, node, args) {
Expand Down