ci: fix release workflows to block if version check fails (#7350)
* ci: fix release workflows to block if version check fails * fix: better readline for cli * fix: npm run lint fixes
This commit is contained in:
parent
41937a20d2
commit
d368529cb2
8 changed files with 375 additions and 61 deletions
34
.github/workflows/main.yaml
vendored
34
.github/workflows/main.yaml
vendored
|
|
@ -26,8 +26,24 @@ jobs:
|
|||
echo "should_run=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
check-version:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0 # This ensures all tags are fetched
|
||||
|
||||
- name: Checkout tag
|
||||
run: git checkout ${GITHUB_REF#refs/tags/}
|
||||
|
||||
- name: Make sure version isn't odd
|
||||
run: |
|
||||
cd extensions/vscode
|
||||
node scripts/versionCheck.js
|
||||
|
||||
build:
|
||||
needs: check_release_name
|
||||
needs: [check_release_name, check-version]
|
||||
if: needs.check_release_name.outputs.should_run == 'true' || github.event_name == 'workflow_dispatch'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
|
|
@ -88,22 +104,6 @@ jobs:
|
|||
name: ${{ matrix.platform }}-${{ matrix.arch }}-vsix
|
||||
path: "extensions/vscode/*.vsix"
|
||||
|
||||
check-version:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0 # This ensures all tags are fetched
|
||||
|
||||
- name: Checkout tag
|
||||
run: git checkout ${GITHUB_REF#refs/tags/}
|
||||
|
||||
- name: Make sure version isn't odd
|
||||
run: |
|
||||
cd extensions/vscode
|
||||
node scripts/versionCheck.js
|
||||
|
||||
release:
|
||||
permissions:
|
||||
contents: write
|
||||
|
|
|
|||
19
extensions/cli/package-lock.json
generated
19
extensions/cli/package-lock.json
generated
|
|
@ -45,7 +45,6 @@
|
|||
"@types/jszip": "^3.4.0",
|
||||
"@types/nock": "^10.0.3",
|
||||
"@types/react": "^19.1.8",
|
||||
"@types/readline-sync": "^1.4.8",
|
||||
"@types/shell-quote": "^1.7.5",
|
||||
"@types/supertest": "^6.0.3",
|
||||
"@types/turndown": "^5.0.5",
|
||||
|
|
@ -90,7 +89,6 @@
|
|||
"prettier": "^3.6.2",
|
||||
"prettier-plugin-tailwindcss": "^0.6.14",
|
||||
"react": "^19.1.0",
|
||||
"readline-sync": "^1.4.10",
|
||||
"semantic-release": "^24.2.7",
|
||||
"shell-quote": "^1.8.3",
|
||||
"supertest": "^7.1.3",
|
||||
|
|
@ -5407,13 +5405,6 @@
|
|||
"csstype": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/readline-sync": {
|
||||
"version": "1.4.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/readline-sync/-/readline-sync-1.4.8.tgz",
|
||||
"integrity": "sha512-BL7xOf0yKLA6baAX6MMOnYkoflUyj/c7y3pqMRfU0va7XlwHAOTOIo4x55P/qLfMsuaYdJJKubToLqRVmRtRZA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/send": {
|
||||
"version": "0.17.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.5.tgz",
|
||||
|
|
@ -16448,16 +16439,6 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/readline-sync": {
|
||||
"version": "1.4.10",
|
||||
"resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz",
|
||||
"integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/reflect.getprototypeof": {
|
||||
"version": "1.0.10",
|
||||
"resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.10.tgz",
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@
|
|||
"@types/jszip": "^3.4.0",
|
||||
"@types/nock": "^10.0.3",
|
||||
"@types/react": "^19.1.8",
|
||||
"@types/readline-sync": "^1.4.8",
|
||||
"@types/shell-quote": "^1.7.5",
|
||||
"@types/supertest": "^6.0.3",
|
||||
"@types/turndown": "^5.0.5",
|
||||
|
|
@ -122,7 +121,6 @@
|
|||
"prettier": "^3.6.2",
|
||||
"prettier-plugin-tailwindcss": "^0.6.14",
|
||||
"react": "^19.1.0",
|
||||
"readline-sync": "^1.4.10",
|
||||
"semantic-release": "^24.2.7",
|
||||
"shell-quote": "^1.8.3",
|
||||
"supertest": "^7.1.3",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { ModelConfig } from "@continuedev/config-yaml";
|
||||
import chalk from "chalk";
|
||||
import type { ChatHistoryItem, Session } from "core/index.js";
|
||||
import { ChatHistoryItem, Session } from "core";
|
||||
import { ChatDescriber } from "core/util/chatDescriber.js";
|
||||
import * as readlineSync from "readline-sync";
|
||||
|
||||
import { compactChatHistory, findCompactionIndex } from "../compaction.js";
|
||||
import { processCommandFlags } from "../flags/flagProcessor.js";
|
||||
|
|
@ -25,6 +24,7 @@ import { startTUIChat } from "../ui/index.js";
|
|||
import { gracefulExit } from "../util/exit.js";
|
||||
import { formatAnthropicError, formatError } from "../util/formatError.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
import { question } from "../util/prompt.js";
|
||||
import {
|
||||
calculateContextUsagePercentage,
|
||||
countChatHistoryTokens,
|
||||
|
|
@ -454,7 +454,7 @@ async function runHeadlessMode(
|
|||
const userInput =
|
||||
isFirstMessage && initialUserInput
|
||||
? initialUserInput
|
||||
: readlineSync.question(`\n${chalk.bold.green("You:")} `);
|
||||
: await question(`\n${chalk.bold.green("You:")} `);
|
||||
|
||||
isFirstMessage = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ import * as path from "path";
|
|||
|
||||
import chalk from "chalk";
|
||||
import open from "open";
|
||||
import * as readlineSync from "readline-sync";
|
||||
|
||||
import { env } from "./env.js";
|
||||
import {
|
||||
isValidAnthropicApiKey,
|
||||
getApiKeyValidationError,
|
||||
isValidAnthropicApiKey,
|
||||
} from "./util/apiKeyValidation.js";
|
||||
import { gracefulExit } from "./util/exit.js";
|
||||
import { question, questionWithChoices } from "./util/prompt.js";
|
||||
import { updateAnthropicModelInYaml } from "./util/yamlConfigUpdater.js";
|
||||
|
||||
const CONFIG_PATH = path.join(env.continueHome, "config.yaml");
|
||||
|
|
@ -52,10 +52,12 @@ export async function handleMaxedOutFreeTrial(
|
|||
console.log(chalk.white("1. 💳 Sign up for models add-on"));
|
||||
console.log(chalk.white("2. 🔑 Enter your Anthropic API key"));
|
||||
|
||||
const choice = readlineSync.question(chalk.yellow("\nEnter choice (1): "), {
|
||||
limit: ["1", "2", ""],
|
||||
limitMessage: chalk.dim("Please enter 1 or 2"),
|
||||
});
|
||||
const choice = await questionWithChoices(
|
||||
chalk.yellow("\nEnter choice (1): "),
|
||||
["1", "2", ""],
|
||||
"1",
|
||||
chalk.dim("Please enter 1 or 2"),
|
||||
);
|
||||
|
||||
if (choice === "1" || choice === "") {
|
||||
// Option 1: Open models setup page
|
||||
|
|
@ -81,15 +83,12 @@ export async function handleMaxedOutFreeTrial(
|
|||
}
|
||||
|
||||
// Wait for user to acknowledge
|
||||
readlineSync.question(chalk.dim("\nPress Enter to exit..."));
|
||||
await question(chalk.dim("\nPress Enter to exit..."));
|
||||
await gracefulExit(0);
|
||||
} else if (choice === "2") {
|
||||
// Option 2: Enter Anthropic API key
|
||||
const apiKey = readlineSync.question(
|
||||
const apiKey = await question(
|
||||
chalk.white("\nEnter your Anthropic API key: "),
|
||||
{
|
||||
hideEchoBack: true,
|
||||
},
|
||||
);
|
||||
|
||||
if (!isValidAnthropicApiKey(apiKey)) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
|
|||
import { BaseLlmApi } from "@continuedev/openai-adapters";
|
||||
import { DefaultApiInterface } from "@continuedev/sdk/dist/api/dist/index.js";
|
||||
import chalk from "chalk";
|
||||
import * as readlineSync from "readline-sync";
|
||||
|
||||
import { processPromptOrRule } from "./args.js";
|
||||
import { AuthConfig, isAuthenticated, login } from "./auth/workos.js";
|
||||
|
|
@ -16,6 +15,7 @@ import {
|
|||
getApiKeyValidationError,
|
||||
isValidAnthropicApiKey,
|
||||
} from "./util/apiKeyValidation.js";
|
||||
import { question, questionWithChoices } from "./util/prompt.js";
|
||||
import { updateAnthropicModelInYaml } from "./util/yamlConfigUpdater.js";
|
||||
|
||||
const CONFIG_PATH = path.join(env.continueHome, "config.yaml");
|
||||
|
|
@ -97,10 +97,12 @@ async function runOnboardingFlow(
|
|||
console.log(chalk.white("1. ⏩ Log in with Continue"));
|
||||
console.log(chalk.white("2. 🔑 Enter your Anthropic API key"));
|
||||
|
||||
const choice = readlineSync.question(chalk.yellow("\nEnter choice (1): "), {
|
||||
limit: ["1", "2", ""],
|
||||
limitMessage: chalk.dim("Please enter 1 or 2"),
|
||||
});
|
||||
const choice = await questionWithChoices(
|
||||
chalk.yellow("\nEnter choice (1): "),
|
||||
["1", "2", ""],
|
||||
"1",
|
||||
chalk.dim("Please enter 1 or 2"),
|
||||
);
|
||||
|
||||
if (choice === "1" || choice === "") {
|
||||
const newAuthConfig = await login();
|
||||
|
|
@ -111,11 +113,8 @@ async function runOnboardingFlow(
|
|||
const result = await initialize(finalAuthConfig, undefined);
|
||||
return { ...result, wasOnboarded: true };
|
||||
} else if (choice === "2") {
|
||||
const apiKey = readlineSync.question(
|
||||
const apiKey = await question(
|
||||
chalk.white("\nEnter your Anthropic API key: "),
|
||||
{
|
||||
hideEchoBack: true,
|
||||
},
|
||||
);
|
||||
|
||||
if (!isValidAnthropicApiKey(apiKey)) {
|
||||
|
|
|
|||
277
extensions/cli/src/util/prompt.test.ts
Normal file
277
extensions/cli/src/util/prompt.test.ts
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
import * as readline from "readline";
|
||||
|
||||
import {
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
MockInstance,
|
||||
} from "vitest";
|
||||
|
||||
// Mock readline module
|
||||
vi.mock("readline", () => ({
|
||||
createInterface: vi.fn(),
|
||||
}));
|
||||
|
||||
import { question, questionWithChoices } from "./prompt.js";
|
||||
|
||||
describe("prompt utilities", () => {
|
||||
let mockInterface: any;
|
||||
let consoleLogSpy: MockInstance<typeof console.log>;
|
||||
let processExitSpy: MockInstance<typeof process.exit>;
|
||||
|
||||
beforeEach(() => {
|
||||
// Create a mock readline interface
|
||||
mockInterface = {
|
||||
question: vi.fn(),
|
||||
close: vi.fn(),
|
||||
on: vi.fn(),
|
||||
};
|
||||
|
||||
// Mock readline.createInterface to return our mock interface
|
||||
(readline.createInterface as any).mockReturnValue(mockInterface);
|
||||
|
||||
// Mock console.log for limit messages
|
||||
consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
|
||||
// Mock process.exit
|
||||
processExitSpy = vi.spyOn(process, "exit").mockImplementation((() => {
|
||||
throw new Error("Process exit");
|
||||
}) as any);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
consoleLogSpy.mockRestore();
|
||||
processExitSpy.mockRestore();
|
||||
});
|
||||
|
||||
describe("question", () => {
|
||||
it("should return user input", async () => {
|
||||
const promptText = "What is your name? ";
|
||||
const userInput = "John Doe";
|
||||
|
||||
// Setup mock to call the callback with user input
|
||||
mockInterface.question.mockImplementation(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => callback(userInput), 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await question(promptText);
|
||||
|
||||
expect(mockInterface.question).toHaveBeenCalledWith(
|
||||
promptText,
|
||||
expect.any(Function),
|
||||
);
|
||||
expect(mockInterface.close).toHaveBeenCalled();
|
||||
expect(result).toBe(userInput);
|
||||
});
|
||||
|
||||
it("should handle empty input", async () => {
|
||||
const promptText = "Enter something: ";
|
||||
|
||||
mockInterface.question.mockImplementation(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => callback(""), 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await question(promptText);
|
||||
|
||||
expect(result).toBe("");
|
||||
});
|
||||
|
||||
it("should handle special characters in input", async () => {
|
||||
const promptText = "Enter special chars: ";
|
||||
const userInput = "!@#$%^&*()_+-=[]{}|;':\",./<>?";
|
||||
|
||||
mockInterface.question.mockImplementation(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => callback(userInput), 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await question(promptText);
|
||||
|
||||
expect(result).toBe(userInput);
|
||||
});
|
||||
|
||||
it.skip("should handle SIGINT (Ctrl+C) by exiting process", async () => {
|
||||
const promptText = "Enter something: ";
|
||||
let sigintHandler: (() => void) | null = null;
|
||||
|
||||
// Setup mock to capture SIGINT handler
|
||||
mockInterface.on.mockImplementation(
|
||||
(event: string, handler: () => void) => {
|
||||
if (event === "SIGINT") {
|
||||
sigintHandler = handler;
|
||||
}
|
||||
return mockInterface;
|
||||
},
|
||||
);
|
||||
|
||||
// Setup question mock that doesn't resolve immediately
|
||||
mockInterface.question.mockImplementation(() => {
|
||||
// Trigger SIGINT after question is called
|
||||
setTimeout(() => {
|
||||
if (sigintHandler) {
|
||||
sigintHandler();
|
||||
}
|
||||
}, 10);
|
||||
});
|
||||
|
||||
// The promise should reject when SIGINT is triggered
|
||||
await expect(question(promptText)).rejects.toThrow("Process exit");
|
||||
expect(processExitSpy).toHaveBeenCalledWith(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("questionWithChoices", () => {
|
||||
it("should accept valid choice", async () => {
|
||||
const promptText = "Choose (1): ";
|
||||
const choices = ["1", "2", "3"];
|
||||
const userChoice = "2";
|
||||
|
||||
mockInterface.question.mockImplementationOnce(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => callback(userChoice), 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await questionWithChoices(promptText, choices);
|
||||
expect(result).toBe(userChoice);
|
||||
});
|
||||
|
||||
it("should use default choice when empty input is provided", async () => {
|
||||
const promptText = "Choose (1): ";
|
||||
const choices = ["1", "2", "3"];
|
||||
const defaultChoice = "1";
|
||||
|
||||
mockInterface.question.mockImplementationOnce(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => callback(""), 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await questionWithChoices(
|
||||
promptText,
|
||||
choices,
|
||||
defaultChoice,
|
||||
);
|
||||
expect(result).toBe(defaultChoice);
|
||||
});
|
||||
|
||||
it("should reject invalid choice and ask again", async () => {
|
||||
const promptText = "Choose (1 or 2): ";
|
||||
const choices = ["1", "2"];
|
||||
const limitMessage = "Please enter 1 or 2";
|
||||
|
||||
let callCount = 0;
|
||||
mockInterface.question.mockImplementation(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => {
|
||||
if (callCount === 0) {
|
||||
callCount++;
|
||||
callback("3"); // Invalid choice
|
||||
} else {
|
||||
callback("1"); // Valid choice
|
||||
}
|
||||
}, 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await questionWithChoices(
|
||||
promptText,
|
||||
choices,
|
||||
undefined,
|
||||
limitMessage,
|
||||
);
|
||||
expect(result).toBe("1");
|
||||
expect(consoleLogSpy).toHaveBeenCalledWith(limitMessage);
|
||||
});
|
||||
|
||||
it("should handle multiple invalid attempts before valid choice", async () => {
|
||||
const promptText = "Choose: ";
|
||||
const choices = ["yes", "no"];
|
||||
const limitMessage = "Invalid choice";
|
||||
|
||||
let callCount = 0;
|
||||
const invalidAnswers = ["maybe", "perhaps"];
|
||||
mockInterface.question.mockImplementation(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => {
|
||||
if (callCount < invalidAnswers.length) {
|
||||
callback(invalidAnswers[callCount++]);
|
||||
} else {
|
||||
callback("yes");
|
||||
}
|
||||
}, 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await questionWithChoices(
|
||||
promptText,
|
||||
choices,
|
||||
undefined,
|
||||
limitMessage,
|
||||
);
|
||||
expect(result).toBe("yes");
|
||||
expect(consoleLogSpy).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("should not show limit message when none provided", async () => {
|
||||
const promptText = "Choose: ";
|
||||
const choices = ["a", "b"];
|
||||
|
||||
let callCount = 0;
|
||||
mockInterface.question.mockImplementation(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => {
|
||||
if (callCount === 0) {
|
||||
callCount++;
|
||||
callback("c"); // Invalid
|
||||
} else {
|
||||
callback("a"); // Valid
|
||||
}
|
||||
}, 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await questionWithChoices(promptText, choices);
|
||||
expect(result).toBe("a");
|
||||
expect(consoleLogSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should handle empty string as valid choice", async () => {
|
||||
const promptText = "Press Enter to continue or type 'cancel': ";
|
||||
const choices = ["", "cancel"];
|
||||
|
||||
mockInterface.question.mockImplementationOnce(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => callback(""), 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await questionWithChoices(promptText, choices);
|
||||
expect(result).toBe("");
|
||||
});
|
||||
|
||||
it("should handle choice with spaces", async () => {
|
||||
const promptText = "Choose an option: ";
|
||||
const choices = ["option one", "option two", "option three"];
|
||||
const userChoice = "option two";
|
||||
|
||||
mockInterface.question.mockImplementationOnce(
|
||||
(prompt: string, callback: (answer: string) => void) => {
|
||||
setTimeout(() => callback(userChoice), 0);
|
||||
},
|
||||
);
|
||||
|
||||
const result = await questionWithChoices(promptText, choices);
|
||||
expect(result).toBe(userChoice);
|
||||
});
|
||||
});
|
||||
});
|
||||
60
extensions/cli/src/util/prompt.ts
Normal file
60
extensions/cli/src/util/prompt.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import * as readline from "readline";
|
||||
|
||||
/**
|
||||
* Creates a promise-based question prompt using readline
|
||||
* Properly handles backspace and Ctrl+C
|
||||
*/
|
||||
export function question(prompt: string): Promise<string> {
|
||||
return new Promise((resolve) => {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: true,
|
||||
});
|
||||
|
||||
// Handle Ctrl+C properly
|
||||
rl.on("SIGINT", () => {
|
||||
console.log("\n");
|
||||
rl.close();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
rl.question(prompt, (answer) => {
|
||||
rl.close();
|
||||
resolve(answer);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a prompt with limited choices
|
||||
* @param prompt The prompt to display
|
||||
* @param choices Array of valid choices
|
||||
* @param defaultChoice Default choice if user presses enter
|
||||
* @param limitMessage Message to show when invalid choice is entered
|
||||
*/
|
||||
export async function questionWithChoices(
|
||||
prompt: string,
|
||||
choices: string[],
|
||||
defaultChoice?: string,
|
||||
limitMessage?: string,
|
||||
): Promise<string> {
|
||||
while (true) {
|
||||
const answer = await question(prompt);
|
||||
|
||||
// Handle default choice
|
||||
if (answer === "" && defaultChoice !== undefined) {
|
||||
return defaultChoice;
|
||||
}
|
||||
|
||||
// Check if answer is valid
|
||||
if (choices.includes(answer)) {
|
||||
return answer;
|
||||
}
|
||||
|
||||
// Show limit message if provided
|
||||
if (limitMessage) {
|
||||
console.log(limitMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue