8000 CI: check formatting and lint, then typecheck, build and test on Linux and macOS by anvk · Pull Request #9 · anvk/lanes · GitHub
[go: up one dir, main page]

Skip to content
Merged
8000
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
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
style:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
cache: npm
- run: npm ci
- name: Formatting
run: npm run format:check
- name: Lint
run: npm run lint

test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
env:
# Some tests make commits in scratch repositories.
GIT_AUTHOR_NAME: CI
GIT_AUTHOR_EMAIL: ci@example.com
GIT_COMMITTER_NAME: CI
GIT_COMMITTER_EMAIL: ci@example.com
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
- name: Plugin API
working-directory: plugins/api
run: npm ci
- name: Warp plugin
working-directory: plugins/warp
run: |
npm ci
npm run typecheck
npm run build
npm test
- name: CLI
working-directory: cli
run: |
npm ci
npm run typecheck
npm run build
npm test
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
package-lock.json
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"printWidth": 120,
"trailingComma": "none"
}
149 changes: 83 additions & 66 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"scripts": {
"build": "tsc -p tsconfig.json && node tools/build-clonedir.mjs && node tools/build-bin-mode.mjs",
"typecheck": "tsc -p tsconfig.test.json",
"start": "node ./dist/bin/lanes.js",
"dev": "tsx ./src/bin/lanes.ts",
"test": "node --import tsx --test \"src/**/*.test.ts\"",
Expand Down
4 changes: 3 additions & 1 deletion cli/src/bin/lanes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ withOpenOptions(
.argument(...LANE_ID)
.option("--no-open", "Do not run the open commands after creation"),
"Base to create the lane from (required when several bases are configured)"
).action((laneId: string, options: OpenCommandOptions & { open: boolean }) => runCreateCommand(laneId, options, repo()));
).action((laneId: string, options: OpenCommandOptions & { open: boolean }) =>
runCreateCommand(laneId, options, repo())
);

withOpenOptions(
program
Expand Down
7 changes: 4 additions & 3 deletions cli/src/branches/branchsearch.ts
10BC8
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ export function rankBranches(branches: RemoteBranch[], needle: string): RemoteBr
// `owner/name` of a github.com remote, in any of its URL spellings; `null` for anything else.
function githubRepo(repoRoot: string): { owner: string; name: string } | null {
const url = run("git", ["remote", "get-url", "origin"], { cwd: repoRoot }).stdout;
const match = /^(?:git@github\.com:|ssh:\/\/git@github\.com\/|https:\/\/(?:[^@/]+@)?github\.com\/)([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(
url
);
const match =
/^(?:git@github\.com:|ssh:\/\/git@github\.com\/|https:\/\/(?:[^@/]+@)?github\.com\/)([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(
url
);
return match ? { owner: match[1], name: match[2] } : null;
}

Expand Down
32 changes: 26 additions & 6 deletions cli/src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export async function runCreateCommand(

createLaneFolder(configDir, config, location, options);
if (options.open) {
openLane(configDir, config, location, { ...options, created: true, runSetup: await askToRunSetup(config, location.base) });
openLane(configDir, config, location, {
...options,
created: true,
runSetup: await askToRunSetup(config, location.base)
});
}
}

Expand Down Expand Up @@ -190,7 +194,12 @@ export async function runLanesCommand(
case "cancel":
return;
case "open":
openLane(configDir, config, locateInBase(configDir, findBase(config, result.item.baseName), result.item.laneName), options);
openLane(
configDir,
config,
locateInBase(configDir, findBase(config, result.item.baseName), result.item.laneName),
options
);
return;
case "create":
await runOpenCommand(result.laneId, { ...options, base: result.baseName }, repoOption);
Expand All @@ -204,7 +213,11 @@ export async function runLanesCommand(
const { branches, total } = searchRemoteBranches(baseRepoRoot, query);
const items = branches.map((remote) => {
const holder = holders.get(remote.name);
const note = holder ? (holder.laneName ? `lane ${holder.laneName}` : `checked out in ${holder.folder}`) : null;
const note = holder
? holder.laneName
? `lane ${holder.laneName}`
: `checked out in ${holder.folder}`
: null;
return { ...remote, note };
});
return { items, total };
Expand Down Expand Up @@ -286,7 +299,9 @@ export async function runPurgeCommand(options: { days?: string; force?: boolean
for (const candidate of purgeCandidates) {
const baseTag = showBase ? ` [${candidate.baseName}]` : "";
const loses = candidate.uncommitted ? pc.red(`, ${candidate.uncommitted} uncommitted file(s) will be lost`) : "";
console.log(`- ${candidate.laneName}${baseTag} (last update: ${new Date(candidate.lastUpdatedMs).toISOString()}${loses})`);
console.log(
`- ${candidate.laneName}${baseTag} (last update: ${new Date(candidate.lastUpdatedMs).toISOString()}${loses})`
);
}

const confirmationToken = `PURGE ${purgeCandidates.length}`;
Expand Down Expand Up @@ -355,7 +370,10 @@ export function runPruneCommand(repoOption?: string): void {
// re-running init. Lists the document does not mention are left as they are.
// Lines that run on every open come from the template's owner, so a change to them is
// shown line by line and applied only once you say so (or pass --yes).
export async function runCommandsUpdateCommand(options: BaseOption & { yes?: boolean }, repoOption?: string): Promise<void> {
export async function runCommandsUpdateCommand(
options: BaseOption & { yes?: boolean },
repoOption?: string
): Promise<void> {
const { configDir, config } = loadWorkspace(repoOption);
const targets = options.base ? [findBase(config, options.base)] : config.bases;

Expand Down Expand Up @@ -384,7 +402,9 @@ export async function runCommandsUpdateCommand(options: BaseOption & { yes?: boo
` ${list}:`,
...before[list].filter((line) => !next.includes(line)).map((line) => pc.red(` - ${line}`)),
...next.filter((line) => !before[list].includes(line)).map((line) => pc.green(` + ${line}`)),
...(next.every((line) => before[list].includes(line)) && before[list].every((line) => next.includes(line)) ? [pc.dim(" (same lines, new order)")] : [])
...(next.every((line) => before[list].includes(line)) && before[list].every((line) => next.includes(line))
? [pc.dim(" (same lines, new order)")]
: [])
];
});
const pluginChanges = Object.entries(lists.plugins ?? {})
Expand Down
33 changes: 29 additions & 4 deletions cli/src/cli/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ import { selfUpdateDiagnostics } from "../update/diagnostics.js";
import { resolveLanesRoot } from "../core/lanes.js";
import type { BaseConfig } from "../core/types.js";
import { errorMessage } from "../core/util.js";
import { exportLanesRepoCommand, knownLaneKeys, resolveBaseRepoRoot, resolveConfiguredRepoRoot } from "../core/workspace.js";
import {
exportLanesRepoCommand,
knownLaneKeys,
resolveBaseRepoRoot,
resolveConfiguredRepoRoot
} from "../core/workspace.js";

// Words the shell handles itself, which a PATH lookup would wrongly report as missing.
const SHELL_WORDS = new Set(["cd", "export", "set", "true", "false", "echo", "exit", "test", "[", "source", ".", "eval", "exec"]);
const SHELL_WORDS = new Set([
"cd",
"export",
"set",
"true",
"false",
"echo",
"exit",
"test",
"[",
"source",
".",
"eval",
"exec"
]);

// The program a command line starts with, when it is something to look up on PATH.
function executableOf(line: string): string | undefined {
Expand Down Expand Up @@ -114,7 +133,9 @@ export function runDiagnosticsCommand(repoOption?: string): void {
if (prunable.length === 0) {
ok(`${label}: no stale git worktrees`);
} else {
warn(`${label}: ${prunable.length} git worktree(s) point at deleted folders. Run 'lanes prune' to clean them up.`);
warn(
`${label}: ${prunable.length} git worktree(s) point at deleted folders. Run 'lanes prune' to clean them up.`
);
}
}

Expand All @@ -136,7 +157,11 @@ export function runDiagnosticsCommand(repoOption?: string): void {
}

const installed = readInstalled();
ok(installed.length === 0 ? "No plugins installed" : `Plugins: ${installed.map((plugin) => `${plugin.name} (${pluginVersion(plugin)}, ${describeKind(plugin)})`).join(", ")}`);
ok(
installed.length === 0
? "No plugins installed"
: `Plugins: ${installed.map((plugin) => `${plugin.name} (${pluginVersion(plugin)}, ${describeKind(plugin)})`).join(", ")}`
);
for (const broken of brokenPluginList()) {
warn(`Plugin '${broken.name}' does not load: ${broken.reason}`);
}
Expand Down
25 changes: 22 additions & 3 deletions cli/src/cli/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { stdin as input } from "node:process";
import pc from "picocolors";
import { resolveBaseCommands } from "../core/config.js";
import { uncommittedPaths } from "../core/git.js";
import { checkoutBranchLane, deleteLane, MAX_LISTED_DIRTY_ITEMS, openLane, type ForceOption, type OpenOptions } from "../core/lifecycle.js";
import {
checkoutBranchLane,
deleteLane,
MAX_LISTED_DIRTY_ITEMS,
openLane,
type ForceOption,
type OpenOptions
} from "../core/lifecycle.js";
import type { BaseConfig, LanesConfig } from "../core/types.js";
import { ask } from "../core/util.js";
import { laneIdentity, resolveBaseRepoRoot, type LaneLocation } from "../core/workspace.js";
Expand Down Expand Up @@ -42,7 +49,11 @@ export async function promptForExactConfirmation(prompt: string, expected: strin
}
}

export async function confirmAndRemoveLane(configDir: string, config: LanesConfig, location: LaneLocation): Promise<void> {
export async function confirmAndRemoveLane(
configDir: string,
config: LanesConfig,
location: LaneLocation
): Promise<void> {
const baseRepoRoot = resolveBaseRepoRoot(configDir, location.base);
if (!fs.existsSync(location.lanePath)) {
throw new Error(`Lane folder does not exist: ${location.lanePath}`);
Expand All @@ -54,7 +65,15 @@ export async function confirmAndRemoveLane(configDir: string, config: LanesConfi
if (changed && changed.length > 0) {
const shown = changed.slice(0, MAX_LISTED_DIRTY_ITEMS).map((p) => ` ${p}`);
const more = changed.length > shown.length ? [` ...and ${changed.length - shown.length} more`] : [];
console.log(pc.red([` ${label} has ${changed.length} file(s) with uncommitted changes, which removal discards:`, ...shown, ...more].join("\n")));
console.log(
pc.red(
[
` ${label} has ${changed.length} file(s) with uncommitted changes, which removal discards:`,
...shown,
...more
].join("\n")
)
);
}
await promptForExactConfirmation(`Type 'delete' to permanently remove the lane worktree ${label}:`, "delete");
deleteLane(configDir, config, location, baseRepoRoot);
Expand Down
30 changes: 24 additions & 6 deletions cli/src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export async function interactiveInit(repoRoot: string, options: InitOptions = {
const firstFolder = folderCandidates[0] ?? DEFAULT_BASE.folder;
return writeConfig(
repoRoot,
existing ?? { ...DEFAULT_CONFIG, bases: [{ ...DEFAULT_BASE, name: suggestBaseName(firstFolder), folder: firstFolder }] }
existing ?? {
...DEFAULT_CONFIG,
bases: [{ ...DEFAULT_BASE, name: suggestBaseName(firstFolder), folder: firstFolder }]
}
);
}

Expand Down Expand Up @@ -107,7 +110,7 @@ async function askAll(
existing?.branchPrefix ?? DEFAULT_CONFIG.branchPrefix
);
// The prefix is glued to the lane name as-is, so `alex` (no slash) yields `alex1437`.
if (branchPrefix && !/[\/_-]$/.test(branchPrefix)) {
if (branchPrefix && !/[/_-]$/.test(branchPrefix)) {
console.log(
pc.yellow(
`Branch prefix '${branchPrefix}' has no trailing separator, so branches will be named like '${branchPrefix}${lanePrefix}1437'.`
Expand Down Expand Up @@ -301,7 +304,11 @@ async function promptBaseCommands(
// The document may need a plugin that is not installed yet; offer it now rather
// than at the first lane.
if (lists.plugins) {
await ensurePlugins({ ...DEFAULT_CONFIG, bases: [{ ...base, open: lists.open ?? [] }], plugins: lists.plugins });
await ensurePlugins({
...DEFAULT_CONFIG,
bases: [{ ...base, open: lists.open ?? [] }],
plugins: lists.plugins
});
}
return { lists, source };
}
Expand Down Expand Up @@ -347,7 +354,10 @@ async function promptCopyFrom(
return answer === NONE ? null : (withLists.find((base) => base.name === answer) ?? null);
}

async function promptCommandLists(wizard: Wizard, existingBase: BaseConfig | undefined): Promise<Partial<LaneCommands>> {
async function promptCommandLists(
wizard: Wizard,
existingBase: BaseConfig | undefined
): Promise<Partial<LaneCommands>> {
const lists: Partial<LaneCommands> = { open: await promptOpenList(wizard, existingBase?.open ?? []) };
for (const list of ["create", "remove"] as const) {
const lines = await promptLineList(wizard, list, existingBase?.[list] ?? []);
Expand All @@ -363,7 +373,11 @@ async function promptCommandLists(wizard: Wizard, existingBase: BaseConfig | und
async function promptOpenList(wizard: Wizard, current: string[]): Promise<string[]> {
const askers = installedPlugins().filter((plugin) => plugin.prompt);
console.log("");
console.log(pc.cyan(`Commands run ${listLabel("open")} (e.g. cursor .${askers.length ? `, or a ${askers.map((plugin) => plugin.name).join("/")} entry` : ""})`));
console.log(
pc.cyan(
`Commands run ${listLabel("open")} (e.g. cursor .${askers.length ? `, or a ${askers.map((plugin) => plugin.name).join("/")} entry` : ""})`
)
);
const lines: string[] = [];
for (let index = 0; ; index += 1) {
const existingLine: string | undefined = current[index];
Expand All @@ -382,7 +396,11 @@ async function promptOpenList(wizard: Wizard, current: string[]): Promise<string
plugin = askers.find((candidate) => candidate.name === kind);
}
const line = plugin
? shellJoin(["lanes", plugin.name, ...(await plugin.prompt!(wizard, existingPlugin === plugin ? existingWords!.slice(1) : undefined))])
? shellJoin([
"lanes",
plugin.name,
...(await plugin.prompt!(wizard, existingPlugin === plugin ? existingWords!.slice(1) : undefined))
])
: await wizard.validated("Command to run in the lane folder (e.g. cursor .)", existingLine, (value) =>
validateWith(() => validateCommandLine(value, "command"))
);
Expand Down
4 changes: 3 additions & 1 deletion cli/src/cli/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export class Wizard {
async positiveInt(label: string, current: number): Promise<number> {
const answer = await this.validated(label, String(current), (value) => {
const parsed = Number.parseInt(value, 10);
return Number.isInteger(parsed) && parsed > 0 && String(parsed) === value ? null : "Enter a positive whole number.";
return Number.isInteger(parsed) && parsed > 0 && String(parsed) === value
? null
: "Enter a positive whole number.";
});
return Number.parseInt(answer, 10);
}
Expand Down
13 changes: 11 additions & 2 deletions cli/src/core/activity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ function laneFromOldCommit(): { lane: string } {
const base = path.join(root, "base");
fs.mkdirSync(base);
const old = new Date(Date.now() - 30 * DAY).toISOString();
const env = { ...process.env, GIT_AUTHOR_NAME: "t", GIT_AUTHOR_EMAIL: "t@t", GIT_COMMITTER_NAME: "t", GIT_COMMITTER_EMAIL: "t@t", GIT_AUTHOR_DATE: old, GIT_COMMITTER_DATE: old };
const git = (args: string[], cwd = base) => assert.equal(spawnSync("git", args, { cwd, env }).status, 0, args.join(" "));
const env = {
...process.env,
GIT_AUTHOR_NAME: "t",
GIT_AUTHOR_EMAIL: "t@t",
GIT_COMMITTER_NAME: "t",
GIT_COMMITTER_EMAIL: "t@t",
GIT_AUTHOR_DATE: old,
GIT_COMMITTER_DATE: old
};
const git = (args: string[], cwd = base) =>
assert.equal(spawnSync("git", args, { cwd, env }).status, 0, args.join(" "));
git(["init", "-q", "-b", "main"]);
fs.writeFileSync(path.join(base, "a.txt"), "a\n");
fs.writeFileSync(path.join(base, "b.txt"), "b\n");
Expand Down
Loading
Loading
0