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

feat - allow to retry builds when they fail to start and stop using universal builds on macOS #13

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/vscode-bisect",
"version": "0.4.7",
"version": "0.4.8",
"description": "Bisect released VS Code Insider builds to find bugs or performance issues similar to what git bisect supports.",
"repository": {
"type": "git",
Expand Down
64 changes: 44 additions & 20 deletions src/bisect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import prompts from 'prompts';
import chalk from 'chalk';
import open from 'open';
import { builds, IBuild } from './builds';
import { Runtime } from './constants';
import { logTroubleshoot, Runtime } from './constants';
import { launcher } from './launcher';

enum BisectResponse {
Expand Down Expand Up @@ -116,29 +116,53 @@ ${chalk.green(`git bisect start && git bisect bad ${badBuild.commit} && git bise
}
}

private async tryBuild(build: IBuild): Promise<BisectResponse> {
const instance = await launcher.launch(build);

const response = await prompts([
{
type: 'select',
name: 'status',
message: `Is ${build.commit} good or bad?`,
choices: [
{ title: 'Good', value: 'good' },
{ title: 'Bad', value: 'bad' },
{ title: 'Retry', value: 'retry' }
]
private async tryBuild(build: IBuild, options?: { forceReDownload: boolean }): Promise<BisectResponse> {
try {
const instance = await launcher.launch(build, options);

const response = await prompts([
{
type: 'select',
name: 'status',
message: `Is ${build.commit} good or bad?`,
choices: [
{ title: 'Good', value: 'good' },
{ title: 'Bad', value: 'bad' },
{ title: 'Retry', value: 'retry' }
]
}
]);

await instance.stop();

if (response.status === 'retry') {
return this.tryBuild(build);
}
]);

await instance.stop();
return response.status === 'good' ? BisectResponse.Good : response.status === 'bad' ? BisectResponse.Bad : BisectResponse.Quit;
} catch (error) {
console.log(`${chalk.red('\n[error]')} ${error}\n`);

if (response.status === 'retry') {
return this.tryBuild(build);
}
const response = await prompts([
{
type: 'select',
name: 'status',
message: `Would you like to retry?`,
choices: [
{ title: 'Yes', value: 'yes' },
{ title: 'No', value: 'no' }
]
}
]);

return response.status === 'good' ? BisectResponse.Good : response.status === 'bad' ? BisectResponse.Bad : BisectResponse.Quit;
if (response.status === 'yes') {
return this.tryBuild(build, { forceReDownload: true });
}

logTroubleshoot();

return BisectResponse.Quit;
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import chalk from 'chalk';
import { dirname, join } from 'path';
import { rmSync } from 'fs';
import { LOGGER, Platform, platform, Runtime } from './constants';
import { fileGet, jsonGet } from './fetch';
import { exists, getBuildPath, unzip } from './files';
Expand Down Expand Up @@ -111,19 +112,25 @@ class Builds {
}
}

async installBuild({ runtime, commit }: IBuild): Promise<void> {
async installBuild({ runtime, commit }: IBuild, options?: { forceReDownload: boolean }): Promise<void> {
const buildName = await this.getBuildArchiveName({ runtime, commit });

const path = join(getBuildPath(commit), buildName);

if (await exists(path)) {
const pathExists = await exists(path);
if (pathExists && !options?.forceReDownload) {
if (LOGGER.verbose) {
console.log(`${chalk.gray('[build]')} using ${chalk.green(path)} for the next build to try`);
}

return; // assume the build is cached
}

if (pathExists && options?.forceReDownload) {
console.log(`${chalk.gray('[build]')} deleting ${chalk.green(getBuildPath(commit))} and retrying download`);
rmSync(getBuildPath(commit), { recursive: true });
}

// Download
const url = `https://update.code.visualstudio.com/commit:${commit}/${this.getPlatformName(runtime)}/insider`;
console.log(`${chalk.gray('[build]')} downloading build from ${chalk.green(url)}...`);
Expand Down Expand Up @@ -246,8 +253,9 @@ class Builds {
case Runtime.DesktopLocal:
switch (platform) {
case Platform.MacOSX64:
return 'darwin';
case Platform.MacOSArm:
return 'darwin-universal';
return 'darwin-arm64';
case Platform.LinuxX64:
return 'linux-x64';
case Platform.LinuxArm:
Expand Down
10 changes: 10 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import chalk from 'chalk';
import { tmpdir } from 'os';
import { join } from 'path';

Expand Down Expand Up @@ -70,4 +71,13 @@ export const LOGGER = {
export const CONFIG = {
performance: false as boolean | string,
token: undefined as string | undefined,
}

export function logTroubleshoot(): void {
const packageJson = require('../package.json');

console.log(`\n${chalk.bold('Error Troubleshooting Guide:')}
- run ${chalk.green('vscode-bisect --verbose')} for more detailed output
- run ${chalk.green('vscode-bisect --reset')} to delete the cache folder
- run ${chalk.green(`npm install -g ${packageJson.name}`)} to update to the latest version (your version: ${chalk.green(packageJson.version)})`);
}
8 changes: 2 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { rmSync, truncateSync } from 'fs';
import prompts from 'prompts';
import { bisecter } from './bisect';
import { git } from './git';
import { BUILD_FOLDER, CONFIG, LOGGER, ROOT, Runtime } from './constants';
import { BUILD_FOLDER, CONFIG, LOGGER, logTroubleshoot, ROOT, Runtime } from './constants';
import { launcher } from './launcher';
import { builds } from './builds';
import { resolve } from 'path';
Expand Down Expand Up @@ -148,12 +148,8 @@ Builds are stored and cached on disk in ${BUILD_FOLDER}
await bisecter.start(runtime, goodCommit, badCommit, opts.releasedOnly);
}
} catch (error) {
const packageJson = require('../package.json');
console.log(`${chalk.red('\n[error]')} ${error}`);
console.log(`\n${chalk.bold('Error Troubleshooting Guide:')}
- run ${chalk.green('vscode-bisect --verbose')} for more detailed output
- run ${chalk.green('vscode-bisect --reset')} to delete the cache folder
- run ${chalk.green(`npm install -g ${packageJson.name}`)} to update to the latest version (your version: ${chalk.green(packageJson.version)})`);
logTroubleshoot();
process.exit(1);
}
}
4 changes: 2 additions & 2 deletions src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class Launcher {
mkdirSync(DATA_FOLDER, { recursive: true });
}

async launch(build: IBuild): Promise<IInstance> {
async launch(build: IBuild, options?: { forceReDownload: boolean }): Promise<IInstance> {

// Install (unless web remote)
if (build.runtime !== Runtime.WebRemote) {
await builds.installBuild(build);
await builds.installBuild(build, options);
}

// Launch according to runtime
Expand Down